]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blame - test/grsecurity-3.0-3.12.1-201311261204.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-3.0-3.12.1-201311261204.patch
CommitLineData
2e3d84fe
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 eb29ec7..876409e 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..4e7fae5 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
844diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
845index da1c77d..2ee6056 100644
846--- a/arch/arm/include/asm/atomic.h
847+++ b/arch/arm/include/asm/atomic.h
848@@ -17,17 +17,35 @@
849 #include <asm/barrier.h>
850 #include <asm/cmpxchg.h>
851
852+#ifdef CONFIG_GENERIC_ATOMIC64
853+#include <asm-generic/atomic64.h>
854+#endif
855+
856 #define ATOMIC_INIT(i) { (i) }
857
858 #ifdef __KERNEL__
859
860+#define _ASM_EXTABLE(from, to) \
861+" .pushsection __ex_table,\"a\"\n"\
862+" .align 3\n" \
863+" .long " #from ", " #to"\n" \
864+" .popsection"
865+
866 /*
867 * On ARM, ordinary assignment (str instruction) doesn't clear the local
868 * strex/ldrex monitor on some implementations. The reason we can use it for
869 * atomic_set() is the clrex or dummy strex done on every exception return.
870 */
871 #define atomic_read(v) (*(volatile int *)&(v)->counter)
872+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
873+{
874+ return v->counter;
875+}
876 #define atomic_set(v,i) (((v)->counter) = (i))
877+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
878+{
879+ v->counter = i;
880+}
881
882 #if __LINUX_ARM_ARCH__ >= 6
883
884@@ -42,6 +60,35 @@ static inline void atomic_add(int i, atomic_t *v)
885 int result;
886
887 __asm__ __volatile__("@ atomic_add\n"
888+"1: ldrex %1, [%3]\n"
889+" adds %0, %1, %4\n"
890+
891+#ifdef CONFIG_PAX_REFCOUNT
892+" bvc 3f\n"
893+"2: bkpt 0xf103\n"
894+"3:\n"
895+#endif
896+
897+" strex %1, %0, [%3]\n"
898+" teq %1, #0\n"
899+" bne 1b"
900+
901+#ifdef CONFIG_PAX_REFCOUNT
902+"\n4:\n"
903+ _ASM_EXTABLE(2b, 4b)
904+#endif
905+
906+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
907+ : "r" (&v->counter), "Ir" (i)
908+ : "cc");
909+}
910+
911+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
912+{
913+ unsigned long tmp;
914+ int result;
915+
916+ __asm__ __volatile__("@ atomic_add_unchecked\n"
917 "1: ldrex %0, [%3]\n"
918 " add %0, %0, %4\n"
919 " strex %1, %0, [%3]\n"
920@@ -60,6 +107,42 @@ static inline int atomic_add_return(int i, atomic_t *v)
921 smp_mb();
922
923 __asm__ __volatile__("@ atomic_add_return\n"
924+"1: ldrex %1, [%3]\n"
925+" adds %0, %1, %4\n"
926+
927+#ifdef CONFIG_PAX_REFCOUNT
928+" bvc 3f\n"
929+" mov %0, %1\n"
930+"2: bkpt 0xf103\n"
931+"3:\n"
932+#endif
933+
934+" strex %1, %0, [%3]\n"
935+" teq %1, #0\n"
936+" bne 1b"
937+
938+#ifdef CONFIG_PAX_REFCOUNT
939+"\n4:\n"
940+ _ASM_EXTABLE(2b, 4b)
941+#endif
942+
943+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
944+ : "r" (&v->counter), "Ir" (i)
945+ : "cc");
946+
947+ smp_mb();
948+
949+ return result;
950+}
951+
952+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
953+{
954+ unsigned long tmp;
955+ int result;
956+
957+ smp_mb();
958+
959+ __asm__ __volatile__("@ atomic_add_return_unchecked\n"
960 "1: ldrex %0, [%3]\n"
961 " add %0, %0, %4\n"
962 " strex %1, %0, [%3]\n"
963@@ -80,6 +163,35 @@ static inline void atomic_sub(int i, atomic_t *v)
964 int result;
965
966 __asm__ __volatile__("@ atomic_sub\n"
967+"1: ldrex %1, [%3]\n"
968+" subs %0, %1, %4\n"
969+
970+#ifdef CONFIG_PAX_REFCOUNT
971+" bvc 3f\n"
972+"2: bkpt 0xf103\n"
973+"3:\n"
974+#endif
975+
976+" strex %1, %0, [%3]\n"
977+" teq %1, #0\n"
978+" bne 1b"
979+
980+#ifdef CONFIG_PAX_REFCOUNT
981+"\n4:\n"
982+ _ASM_EXTABLE(2b, 4b)
983+#endif
984+
985+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
986+ : "r" (&v->counter), "Ir" (i)
987+ : "cc");
988+}
989+
990+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
991+{
992+ unsigned long tmp;
993+ int result;
994+
995+ __asm__ __volatile__("@ atomic_sub_unchecked\n"
996 "1: ldrex %0, [%3]\n"
997 " sub %0, %0, %4\n"
998 " strex %1, %0, [%3]\n"
999@@ -98,11 +210,25 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1000 smp_mb();
1001
1002 __asm__ __volatile__("@ atomic_sub_return\n"
1003-"1: ldrex %0, [%3]\n"
1004-" sub %0, %0, %4\n"
1005+"1: ldrex %1, [%3]\n"
1006+" subs %0, %1, %4\n"
1007+
1008+#ifdef CONFIG_PAX_REFCOUNT
1009+" bvc 3f\n"
1010+" mov %0, %1\n"
1011+"2: bkpt 0xf103\n"
1012+"3:\n"
1013+#endif
1014+
1015 " strex %1, %0, [%3]\n"
1016 " teq %1, #0\n"
1017 " bne 1b"
1018+
1019+#ifdef CONFIG_PAX_REFCOUNT
1020+"\n4:\n"
1021+ _ASM_EXTABLE(2b, 4b)
1022+#endif
1023+
1024 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1025 : "r" (&v->counter), "Ir" (i)
1026 : "cc");
1027@@ -134,6 +260,28 @@ static inline int atomic_cmpxchg(atomic_t *ptr, int old, int new)
1028 return oldval;
1029 }
1030
1031+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
1032+{
1033+ unsigned long oldval, res;
1034+
1035+ smp_mb();
1036+
1037+ do {
1038+ __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
1039+ "ldrex %1, [%3]\n"
1040+ "mov %0, #0\n"
1041+ "teq %1, %4\n"
1042+ "strexeq %0, %5, [%3]\n"
1043+ : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1044+ : "r" (&ptr->counter), "Ir" (old), "r" (new)
1045+ : "cc");
1046+ } while (res);
1047+
1048+ smp_mb();
1049+
1050+ return oldval;
1051+}
1052+
1053 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1054 {
1055 unsigned long tmp, tmp2;
1056@@ -167,7 +315,17 @@ static inline int atomic_add_return(int i, atomic_t *v)
1057
1058 return val;
1059 }
1060+
1061+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
1062+{
1063+ return atomic_add_return(i, v);
1064+}
1065+
1066 #define atomic_add(i, v) (void) atomic_add_return(i, v)
1067+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
1068+{
1069+ (void) atomic_add_return(i, v);
1070+}
1071
1072 static inline int atomic_sub_return(int i, atomic_t *v)
1073 {
1074@@ -182,6 +340,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1075 return val;
1076 }
1077 #define atomic_sub(i, v) (void) atomic_sub_return(i, v)
1078+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1079+{
1080+ (void) atomic_sub_return(i, v);
1081+}
1082
1083 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1084 {
1085@@ -197,6 +359,11 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1086 return ret;
1087 }
1088
1089+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
1090+{
1091+ return atomic_cmpxchg(v, old, new);
1092+}
1093+
1094 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1095 {
1096 unsigned long flags;
1097@@ -209,6 +376,10 @@ static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1098 #endif /* __LINUX_ARM_ARCH__ */
1099
1100 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
1101+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
1102+{
1103+ return xchg(&v->counter, new);
1104+}
1105
1106 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1107 {
1108@@ -221,11 +392,27 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1109 }
1110
1111 #define atomic_inc(v) atomic_add(1, v)
1112+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
1113+{
1114+ atomic_add_unchecked(1, v);
1115+}
1116 #define atomic_dec(v) atomic_sub(1, v)
1117+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
1118+{
1119+ atomic_sub_unchecked(1, v);
1120+}
1121
1122 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
1123+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
1124+{
1125+ return atomic_add_return_unchecked(1, v) == 0;
1126+}
1127 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
1128 #define atomic_inc_return(v) (atomic_add_return(1, v))
1129+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
1130+{
1131+ return atomic_add_return_unchecked(1, v);
1132+}
1133 #define atomic_dec_return(v) (atomic_sub_return(1, v))
1134 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
1135
1136@@ -241,6 +428,14 @@ typedef struct {
1137 u64 __aligned(8) counter;
1138 } atomic64_t;
1139
1140+#ifdef CONFIG_PAX_REFCOUNT
1141+typedef struct {
1142+ u64 __aligned(8) counter;
1143+} atomic64_unchecked_t;
1144+#else
1145+typedef atomic64_t atomic64_unchecked_t;
1146+#endif
1147+
1148 #define ATOMIC64_INIT(i) { (i) }
1149
1150 #ifdef CONFIG_ARM_LPAE
1151@@ -257,6 +452,19 @@ static inline u64 atomic64_read(const atomic64_t *v)
1152 return result;
1153 }
1154
1155+static inline u64 atomic64_read_unchecked(const atomic64_unchecked_t *v)
1156+{
1157+ u64 result;
1158+
1159+ __asm__ __volatile__("@ atomic64_read_unchecked\n"
1160+" ldrd %0, %H0, [%1]"
1161+ : "=&r" (result)
1162+ : "r" (&v->counter), "Qo" (v->counter)
1163+ );
1164+
1165+ return result;
1166+}
1167+
1168 static inline void atomic64_set(atomic64_t *v, u64 i)
1169 {
1170 __asm__ __volatile__("@ atomic64_set\n"
1171@@ -265,6 +473,15 @@ static inline void atomic64_set(atomic64_t *v, u64 i)
1172 : "r" (&v->counter), "r" (i)
1173 );
1174 }
1175+
1176+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, u64 i)
1177+{
1178+ __asm__ __volatile__("@ atomic64_set_unchecked\n"
1179+" strd %2, %H2, [%1]"
1180+ : "=Qo" (v->counter)
1181+ : "r" (&v->counter), "r" (i)
1182+ );
1183+}
1184 #else
1185 static inline u64 atomic64_read(const atomic64_t *v)
1186 {
1187@@ -279,6 +496,19 @@ static inline u64 atomic64_read(const atomic64_t *v)
1188 return result;
1189 }
1190
1191+static inline u64 atomic64_read_unchecked(atomic64_unchecked_t *v)
1192+{
1193+ u64 result;
1194+
1195+ __asm__ __volatile__("@ atomic64_read_unchecked\n"
1196+" ldrexd %0, %H0, [%1]"
1197+ : "=&r" (result)
1198+ : "r" (&v->counter), "Qo" (v->counter)
1199+ );
1200+
1201+ return result;
1202+}
1203+
1204 static inline void atomic64_set(atomic64_t *v, u64 i)
1205 {
1206 u64 tmp;
1207@@ -292,6 +522,21 @@ static inline void atomic64_set(atomic64_t *v, u64 i)
1208 : "r" (&v->counter), "r" (i)
1209 : "cc");
1210 }
1211+
1212+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, u64 i)
1213+{
1214+ u64 tmp;
1215+
1216+ __asm__ __volatile__("@ atomic64_set_unchecked\n"
1217+"1: ldrexd %0, %H0, [%2]\n"
1218+" strexd %0, %3, %H3, [%2]\n"
1219+" teq %0, #0\n"
1220+" bne 1b"
1221+ : "=&r" (tmp), "=Qo" (v->counter)
1222+ : "r" (&v->counter), "r" (i)
1223+ : "cc");
1224+}
1225+
1226 #endif
1227
1228 static inline void atomic64_add(u64 i, atomic64_t *v)
1229@@ -302,6 +547,36 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1230 __asm__ __volatile__("@ atomic64_add\n"
1231 "1: ldrexd %0, %H0, [%3]\n"
1232 " adds %0, %0, %4\n"
1233+" adcs %H0, %H0, %H4\n"
1234+
1235+#ifdef CONFIG_PAX_REFCOUNT
1236+" bvc 3f\n"
1237+"2: bkpt 0xf103\n"
1238+"3:\n"
1239+#endif
1240+
1241+" strexd %1, %0, %H0, [%3]\n"
1242+" teq %1, #0\n"
1243+" bne 1b"
1244+
1245+#ifdef CONFIG_PAX_REFCOUNT
1246+"\n4:\n"
1247+ _ASM_EXTABLE(2b, 4b)
1248+#endif
1249+
1250+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1251+ : "r" (&v->counter), "r" (i)
1252+ : "cc");
1253+}
1254+
1255+static inline void atomic64_add_unchecked(u64 i, atomic64_unchecked_t *v)
1256+{
1257+ u64 result;
1258+ unsigned long tmp;
1259+
1260+ __asm__ __volatile__("@ atomic64_add_unchecked\n"
1261+"1: ldrexd %0, %H0, [%3]\n"
1262+" adds %0, %0, %4\n"
1263 " adc %H0, %H0, %H4\n"
1264 " strexd %1, %0, %H0, [%3]\n"
1265 " teq %1, #0\n"
1266@@ -313,12 +588,49 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1267
1268 static inline u64 atomic64_add_return(u64 i, atomic64_t *v)
1269 {
1270- u64 result;
1271- unsigned long tmp;
1272+ u64 result, tmp;
1273
1274 smp_mb();
1275
1276 __asm__ __volatile__("@ atomic64_add_return\n"
1277+"1: ldrexd %1, %H1, [%3]\n"
1278+" adds %0, %1, %4\n"
1279+" adcs %H0, %H1, %H4\n"
1280+
1281+#ifdef CONFIG_PAX_REFCOUNT
1282+" bvc 3f\n"
1283+" mov %0, %1\n"
1284+" mov %H0, %H1\n"
1285+"2: bkpt 0xf103\n"
1286+"3:\n"
1287+#endif
1288+
1289+" strexd %1, %0, %H0, [%3]\n"
1290+" teq %1, #0\n"
1291+" bne 1b"
1292+
1293+#ifdef CONFIG_PAX_REFCOUNT
1294+"\n4:\n"
1295+ _ASM_EXTABLE(2b, 4b)
1296+#endif
1297+
1298+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1299+ : "r" (&v->counter), "r" (i)
1300+ : "cc");
1301+
1302+ smp_mb();
1303+
1304+ return result;
1305+}
1306+
1307+static inline u64 atomic64_add_return_unchecked(u64 i, atomic64_unchecked_t *v)
1308+{
1309+ u64 result;
1310+ unsigned long tmp;
1311+
1312+ smp_mb();
1313+
1314+ __asm__ __volatile__("@ atomic64_add_return_unchecked\n"
1315 "1: ldrexd %0, %H0, [%3]\n"
1316 " adds %0, %0, %4\n"
1317 " adc %H0, %H0, %H4\n"
1318@@ -342,6 +654,36 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1319 __asm__ __volatile__("@ atomic64_sub\n"
1320 "1: ldrexd %0, %H0, [%3]\n"
1321 " subs %0, %0, %4\n"
1322+" sbcs %H0, %H0, %H4\n"
1323+
1324+#ifdef CONFIG_PAX_REFCOUNT
1325+" bvc 3f\n"
1326+"2: bkpt 0xf103\n"
1327+"3:\n"
1328+#endif
1329+
1330+" strexd %1, %0, %H0, [%3]\n"
1331+" teq %1, #0\n"
1332+" bne 1b"
1333+
1334+#ifdef CONFIG_PAX_REFCOUNT
1335+"\n4:\n"
1336+ _ASM_EXTABLE(2b, 4b)
1337+#endif
1338+
1339+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1340+ : "r" (&v->counter), "r" (i)
1341+ : "cc");
1342+}
1343+
1344+static inline void atomic64_sub_unchecked(u64 i, atomic64_unchecked_t *v)
1345+{
1346+ u64 result;
1347+ unsigned long tmp;
1348+
1349+ __asm__ __volatile__("@ atomic64_sub_unchecked\n"
1350+"1: ldrexd %0, %H0, [%3]\n"
1351+" subs %0, %0, %4\n"
1352 " sbc %H0, %H0, %H4\n"
1353 " strexd %1, %0, %H0, [%3]\n"
1354 " teq %1, #0\n"
1355@@ -353,18 +695,32 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1356
1357 static inline u64 atomic64_sub_return(u64 i, atomic64_t *v)
1358 {
1359- u64 result;
1360- unsigned long tmp;
1361+ u64 result, tmp;
1362
1363 smp_mb();
1364
1365 __asm__ __volatile__("@ atomic64_sub_return\n"
1366-"1: ldrexd %0, %H0, [%3]\n"
1367-" subs %0, %0, %4\n"
1368-" sbc %H0, %H0, %H4\n"
1369+"1: ldrexd %1, %H1, [%3]\n"
1370+" subs %0, %1, %4\n"
1371+" sbcs %H0, %H1, %H4\n"
1372+
1373+#ifdef CONFIG_PAX_REFCOUNT
1374+" bvc 3f\n"
1375+" mov %0, %1\n"
1376+" mov %H0, %H1\n"
1377+"2: bkpt 0xf103\n"
1378+"3:\n"
1379+#endif
1380+
1381 " strexd %1, %0, %H0, [%3]\n"
1382 " teq %1, #0\n"
1383 " bne 1b"
1384+
1385+#ifdef CONFIG_PAX_REFCOUNT
1386+"\n4:\n"
1387+ _ASM_EXTABLE(2b, 4b)
1388+#endif
1389+
1390 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1391 : "r" (&v->counter), "r" (i)
1392 : "cc");
1393@@ -398,6 +754,30 @@ static inline u64 atomic64_cmpxchg(atomic64_t *ptr, u64 old, u64 new)
1394 return oldval;
1395 }
1396
1397+static inline u64 atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, u64 old, u64 new)
1398+{
1399+ u64 oldval;
1400+ unsigned long res;
1401+
1402+ smp_mb();
1403+
1404+ do {
1405+ __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1406+ "ldrexd %1, %H1, [%3]\n"
1407+ "mov %0, #0\n"
1408+ "teq %1, %4\n"
1409+ "teqeq %H1, %H4\n"
1410+ "strexdeq %0, %5, %H5, [%3]"
1411+ : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1412+ : "r" (&ptr->counter), "r" (old), "r" (new)
1413+ : "cc");
1414+ } while (res);
1415+
1416+ smp_mb();
1417+
1418+ return oldval;
1419+}
1420+
1421 static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1422 {
1423 u64 result;
1424@@ -421,21 +801,34 @@ static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1425
1426 static inline u64 atomic64_dec_if_positive(atomic64_t *v)
1427 {
1428- u64 result;
1429- unsigned long tmp;
1430+ u64 result, tmp;
1431
1432 smp_mb();
1433
1434 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1435-"1: ldrexd %0, %H0, [%3]\n"
1436-" subs %0, %0, #1\n"
1437-" sbc %H0, %H0, #0\n"
1438+"1: ldrexd %1, %H1, [%3]\n"
1439+" subs %0, %1, #1\n"
1440+" sbcs %H0, %H1, #0\n"
1441+
1442+#ifdef CONFIG_PAX_REFCOUNT
1443+" bvc 3f\n"
1444+" mov %0, %1\n"
1445+" mov %H0, %H1\n"
1446+"2: bkpt 0xf103\n"
1447+"3:\n"
1448+#endif
1449+
1450 " teq %H0, #0\n"
1451-" bmi 2f\n"
1452+" bmi 4f\n"
1453 " strexd %1, %0, %H0, [%3]\n"
1454 " teq %1, #0\n"
1455 " bne 1b\n"
1456-"2:"
1457+"4:\n"
1458+
1459+#ifdef CONFIG_PAX_REFCOUNT
1460+ _ASM_EXTABLE(2b, 4b)
1461+#endif
1462+
1463 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1464 : "r" (&v->counter)
1465 : "cc");
1466@@ -458,13 +851,25 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1467 " teq %0, %5\n"
1468 " teqeq %H0, %H5\n"
1469 " moveq %1, #0\n"
1470-" beq 2f\n"
1471+" beq 4f\n"
1472 " adds %0, %0, %6\n"
1473-" adc %H0, %H0, %H6\n"
1474+" adcs %H0, %H0, %H6\n"
1475+
1476+#ifdef CONFIG_PAX_REFCOUNT
1477+" bvc 3f\n"
1478+"2: bkpt 0xf103\n"
1479+"3:\n"
1480+#endif
1481+
1482 " strexd %2, %0, %H0, [%4]\n"
1483 " teq %2, #0\n"
1484 " bne 1b\n"
1485-"2:"
1486+"4:\n"
1487+
1488+#ifdef CONFIG_PAX_REFCOUNT
1489+ _ASM_EXTABLE(2b, 4b)
1490+#endif
1491+
1492 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1493 : "r" (&v->counter), "r" (u), "r" (a)
1494 : "cc");
1495@@ -477,10 +882,13 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1496
1497 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1498 #define atomic64_inc(v) atomic64_add(1LL, (v))
1499+#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1500 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1501+#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1502 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1503 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1504 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1505+#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1506 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1507 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1508 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1509diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1510index 75fe66b..ba3dee4 100644
1511--- a/arch/arm/include/asm/cache.h
1512+++ b/arch/arm/include/asm/cache.h
1513@@ -4,8 +4,10 @@
1514 #ifndef __ASMARM_CACHE_H
1515 #define __ASMARM_CACHE_H
1516
1517+#include <linux/const.h>
1518+
1519 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1520-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1521+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1522
1523 /*
1524 * Memory returned by kmalloc() may be used for DMA, so we must make
1525@@ -24,5 +26,6 @@
1526 #endif
1527
1528 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
1529+#define __read_only __attribute__ ((__section__(".data..read_only")))
1530
1531 #endif
1532diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1533index 15f2d5b..43ffa53 100644
1534--- a/arch/arm/include/asm/cacheflush.h
1535+++ b/arch/arm/include/asm/cacheflush.h
1536@@ -116,7 +116,7 @@ struct cpu_cache_fns {
1537 void (*dma_unmap_area)(const void *, size_t, int);
1538
1539 void (*dma_flush_range)(const void *, const void *);
1540-};
1541+} __no_const;
1542
1543 /*
1544 * Select the calling method
1545diff --git a/arch/arm/include/asm/checksum.h b/arch/arm/include/asm/checksum.h
1546index 6dcc164..b14d917 100644
1547--- a/arch/arm/include/asm/checksum.h
1548+++ b/arch/arm/include/asm/checksum.h
1549@@ -37,7 +37,19 @@ __wsum
1550 csum_partial_copy_nocheck(const void *src, void *dst, int len, __wsum sum);
1551
1552 __wsum
1553-csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1554+__csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1555+
1556+static inline __wsum
1557+csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr)
1558+{
1559+ __wsum ret;
1560+ pax_open_userland();
1561+ ret = __csum_partial_copy_from_user(src, dst, len, sum, err_ptr);
1562+ pax_close_userland();
1563+ return ret;
1564+}
1565+
1566+
1567
1568 /*
1569 * Fold a partial checksum without adding pseudo headers
1570diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
1571index 4f009c1..466c59b 100644
1572--- a/arch/arm/include/asm/cmpxchg.h
1573+++ b/arch/arm/include/asm/cmpxchg.h
1574@@ -102,6 +102,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
1575
1576 #define xchg(ptr,x) \
1577 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1578+#define xchg_unchecked(ptr,x) \
1579+ ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1580
1581 #include <asm-generic/cmpxchg-local.h>
1582
1583diff --git a/arch/arm/include/asm/domain.h b/arch/arm/include/asm/domain.h
1584index 6ddbe44..b5e38b1 100644
1585--- a/arch/arm/include/asm/domain.h
1586+++ b/arch/arm/include/asm/domain.h
1587@@ -48,18 +48,37 @@
1588 * Domain types
1589 */
1590 #define DOMAIN_NOACCESS 0
1591-#define DOMAIN_CLIENT 1
1592 #ifdef CONFIG_CPU_USE_DOMAINS
1593+#define DOMAIN_USERCLIENT 1
1594+#define DOMAIN_KERNELCLIENT 1
1595 #define DOMAIN_MANAGER 3
1596+#define DOMAIN_VECTORS DOMAIN_USER
1597 #else
1598+
1599+#ifdef CONFIG_PAX_KERNEXEC
1600 #define DOMAIN_MANAGER 1
1601+#define DOMAIN_KERNEXEC 3
1602+#else
1603+#define DOMAIN_MANAGER 1
1604+#endif
1605+
1606+#ifdef CONFIG_PAX_MEMORY_UDEREF
1607+#define DOMAIN_USERCLIENT 0
1608+#define DOMAIN_UDEREF 1
1609+#define DOMAIN_VECTORS DOMAIN_KERNEL
1610+#else
1611+#define DOMAIN_USERCLIENT 1
1612+#define DOMAIN_VECTORS DOMAIN_USER
1613+#endif
1614+#define DOMAIN_KERNELCLIENT 1
1615+
1616 #endif
1617
1618 #define domain_val(dom,type) ((type) << (2*(dom)))
1619
1620 #ifndef __ASSEMBLY__
1621
1622-#ifdef CONFIG_CPU_USE_DOMAINS
1623+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
1624 static inline void set_domain(unsigned val)
1625 {
1626 asm volatile(
1627@@ -68,15 +87,7 @@ static inline void set_domain(unsigned val)
1628 isb();
1629 }
1630
1631-#define modify_domain(dom,type) \
1632- do { \
1633- struct thread_info *thread = current_thread_info(); \
1634- unsigned int domain = thread->cpu_domain; \
1635- domain &= ~domain_val(dom, DOMAIN_MANAGER); \
1636- thread->cpu_domain = domain | domain_val(dom, type); \
1637- set_domain(thread->cpu_domain); \
1638- } while (0)
1639-
1640+extern void modify_domain(unsigned int dom, unsigned int type);
1641 #else
1642 static inline void set_domain(unsigned val) { }
1643 static inline void modify_domain(unsigned dom, unsigned type) { }
1644diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1645index f4b46d3..abc9b2b 100644
1646--- a/arch/arm/include/asm/elf.h
1647+++ b/arch/arm/include/asm/elf.h
1648@@ -114,7 +114,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1649 the loader. We need to make sure that it is out of the way of the program
1650 that it will "exec", and that there is sufficient room for the brk. */
1651
1652-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1653+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1654+
1655+#ifdef CONFIG_PAX_ASLR
1656+#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1657+
1658+#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1659+#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1660+#endif
1661
1662 /* When the program starts, a1 contains a pointer to a function to be
1663 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1664@@ -124,10 +131,6 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1665 extern void elf_set_personality(const struct elf32_hdr *);
1666 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1667
1668-struct mm_struct;
1669-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1670-#define arch_randomize_brk arch_randomize_brk
1671-
1672 #ifdef CONFIG_MMU
1673 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
1674 struct linux_binprm;
1675diff --git a/arch/arm/include/asm/fncpy.h b/arch/arm/include/asm/fncpy.h
1676index de53547..52b9a28 100644
1677--- a/arch/arm/include/asm/fncpy.h
1678+++ b/arch/arm/include/asm/fncpy.h
1679@@ -81,7 +81,9 @@
1680 BUG_ON((uintptr_t)(dest_buf) & (FNCPY_ALIGN - 1) || \
1681 (__funcp_address & ~(uintptr_t)1 & (FNCPY_ALIGN - 1))); \
1682 \
1683+ pax_open_kernel(); \
1684 memcpy(dest_buf, (void const *)(__funcp_address & ~1), size); \
1685+ pax_close_kernel(); \
1686 flush_icache_range((unsigned long)(dest_buf), \
1687 (unsigned long)(dest_buf) + (size)); \
1688 \
1689diff --git a/arch/arm/include/asm/futex.h b/arch/arm/include/asm/futex.h
1690index e42cf59..7b94b8f 100644
1691--- a/arch/arm/include/asm/futex.h
1692+++ b/arch/arm/include/asm/futex.h
1693@@ -50,6 +50,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1694 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1695 return -EFAULT;
1696
1697+ pax_open_userland();
1698+
1699 smp_mb();
1700 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1701 "1: ldrex %1, [%4]\n"
1702@@ -65,6 +67,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1703 : "cc", "memory");
1704 smp_mb();
1705
1706+ pax_close_userland();
1707+
1708 *uval = val;
1709 return ret;
1710 }
1711@@ -95,6 +99,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1712 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1713 return -EFAULT;
1714
1715+ pax_open_userland();
1716+
1717 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1718 "1: " TUSER(ldr) " %1, [%4]\n"
1719 " teq %1, %2\n"
1720@@ -105,6 +111,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1721 : "r" (oldval), "r" (newval), "r" (uaddr), "Ir" (-EFAULT)
1722 : "cc", "memory");
1723
1724+ pax_close_userland();
1725+
1726 *uval = val;
1727 return ret;
1728 }
1729@@ -127,6 +135,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1730 return -EFAULT;
1731
1732 pagefault_disable(); /* implies preempt_disable() */
1733+ pax_open_userland();
1734
1735 switch (op) {
1736 case FUTEX_OP_SET:
1737@@ -148,6 +157,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1738 ret = -ENOSYS;
1739 }
1740
1741+ pax_close_userland();
1742 pagefault_enable(); /* subsumes preempt_enable() */
1743
1744 if (!ret) {
1745diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1746index 83eb2f7..ed77159 100644
1747--- a/arch/arm/include/asm/kmap_types.h
1748+++ b/arch/arm/include/asm/kmap_types.h
1749@@ -4,6 +4,6 @@
1750 /*
1751 * This is the "bare minimum". AIO seems to require this.
1752 */
1753-#define KM_TYPE_NR 16
1754+#define KM_TYPE_NR 17
1755
1756 #endif
1757diff --git a/arch/arm/include/asm/mach/dma.h b/arch/arm/include/asm/mach/dma.h
1758index 9e614a1..3302cca 100644
1759--- a/arch/arm/include/asm/mach/dma.h
1760+++ b/arch/arm/include/asm/mach/dma.h
1761@@ -22,7 +22,7 @@ struct dma_ops {
1762 int (*residue)(unsigned int, dma_t *); /* optional */
1763 int (*setspeed)(unsigned int, dma_t *, int); /* optional */
1764 const char *type;
1765-};
1766+} __do_const;
1767
1768 struct dma_struct {
1769 void *addr; /* single DMA address */
1770diff --git a/arch/arm/include/asm/mach/map.h b/arch/arm/include/asm/mach/map.h
1771index 2fe141f..192dc01 100644
1772--- a/arch/arm/include/asm/mach/map.h
1773+++ b/arch/arm/include/asm/mach/map.h
1774@@ -27,13 +27,16 @@ struct map_desc {
1775 #define MT_MINICLEAN 6
1776 #define MT_LOW_VECTORS 7
1777 #define MT_HIGH_VECTORS 8
1778-#define MT_MEMORY 9
1779+#define MT_MEMORY_RWX 9
1780 #define MT_ROM 10
1781-#define MT_MEMORY_NONCACHED 11
1782+#define MT_MEMORY_NONCACHED_RX 11
1783 #define MT_MEMORY_DTCM 12
1784 #define MT_MEMORY_ITCM 13
1785 #define MT_MEMORY_SO 14
1786 #define MT_MEMORY_DMA_READY 15
1787+#define MT_MEMORY_RW 16
1788+#define MT_MEMORY_RX 17
1789+#define MT_MEMORY_NONCACHED_RW 18
1790
1791 #ifdef CONFIG_MMU
1792 extern void iotable_init(struct map_desc *, int);
1793diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1794index f94784f..41c7f61 100644
1795--- a/arch/arm/include/asm/outercache.h
1796+++ b/arch/arm/include/asm/outercache.h
1797@@ -35,7 +35,7 @@ struct outer_cache_fns {
1798 #endif
1799 void (*set_debug)(unsigned long);
1800 void (*resume)(void);
1801-};
1802+} __do_const;
1803
1804 extern struct outer_cache_fns outer_cache;
1805
1806diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1807index 4355f0e..c229913 100644
1808--- a/arch/arm/include/asm/page.h
1809+++ b/arch/arm/include/asm/page.h
1810@@ -114,7 +114,7 @@ struct cpu_user_fns {
1811 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1812 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1813 unsigned long vaddr, struct vm_area_struct *vma);
1814-};
1815+} __no_const;
1816
1817 #ifdef MULTI_USER
1818 extern struct cpu_user_fns cpu_user;
1819diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
1820index 943504f..c37a730 100644
1821--- a/arch/arm/include/asm/pgalloc.h
1822+++ b/arch/arm/include/asm/pgalloc.h
1823@@ -17,6 +17,7 @@
1824 #include <asm/processor.h>
1825 #include <asm/cacheflush.h>
1826 #include <asm/tlbflush.h>
1827+#include <asm/system_info.h>
1828
1829 #define check_pgt_cache() do { } while (0)
1830
1831@@ -43,6 +44,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1832 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
1833 }
1834
1835+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1836+{
1837+ pud_populate(mm, pud, pmd);
1838+}
1839+
1840 #else /* !CONFIG_ARM_LPAE */
1841
1842 /*
1843@@ -51,6 +57,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1844 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
1845 #define pmd_free(mm, pmd) do { } while (0)
1846 #define pud_populate(mm,pmd,pte) BUG()
1847+#define pud_populate_kernel(mm,pmd,pte) BUG()
1848
1849 #endif /* CONFIG_ARM_LPAE */
1850
1851@@ -126,6 +133,19 @@ static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
1852 __free_page(pte);
1853 }
1854
1855+static inline void __section_update(pmd_t *pmdp, unsigned long addr, pmdval_t prot)
1856+{
1857+#ifdef CONFIG_ARM_LPAE
1858+ pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1859+#else
1860+ if (addr & SECTION_SIZE)
1861+ pmdp[1] = __pmd(pmd_val(pmdp[1]) | prot);
1862+ else
1863+ pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1864+#endif
1865+ flush_pmd_entry(pmdp);
1866+}
1867+
1868 static inline void __pmd_populate(pmd_t *pmdp, phys_addr_t pte,
1869 pmdval_t prot)
1870 {
1871@@ -155,7 +175,7 @@ pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp, pte_t *ptep)
1872 static inline void
1873 pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep)
1874 {
1875- __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE);
1876+ __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE | __supported_pmd_mask);
1877 }
1878 #define pmd_pgtable(pmd) pmd_page(pmd)
1879
1880diff --git a/arch/arm/include/asm/pgtable-2level-hwdef.h b/arch/arm/include/asm/pgtable-2level-hwdef.h
1881index 5cfba15..f415e1a 100644
1882--- a/arch/arm/include/asm/pgtable-2level-hwdef.h
1883+++ b/arch/arm/include/asm/pgtable-2level-hwdef.h
1884@@ -20,12 +20,15 @@
1885 #define PMD_TYPE_FAULT (_AT(pmdval_t, 0) << 0)
1886 #define PMD_TYPE_TABLE (_AT(pmdval_t, 1) << 0)
1887 #define PMD_TYPE_SECT (_AT(pmdval_t, 2) << 0)
1888+#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 2) /* v7 */
1889 #define PMD_BIT4 (_AT(pmdval_t, 1) << 4)
1890 #define PMD_DOMAIN(x) (_AT(pmdval_t, (x)) << 5)
1891 #define PMD_PROTECTION (_AT(pmdval_t, 1) << 9) /* v5 */
1892+
1893 /*
1894 * - section
1895 */
1896+#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 0) /* v7 */
1897 #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
1898 #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
1899 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 4) /* v6 */
1900@@ -37,6 +40,7 @@
1901 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 17) /* v6 */
1902 #define PMD_SECT_SUPER (_AT(pmdval_t, 1) << 18) /* v6 */
1903 #define PMD_SECT_AF (_AT(pmdval_t, 0))
1904+#define PMD_SECT_RDONLY (_AT(pmdval_t, 0))
1905
1906 #define PMD_SECT_UNCACHED (_AT(pmdval_t, 0))
1907 #define PMD_SECT_BUFFERED (PMD_SECT_BUFFERABLE)
1908@@ -66,6 +70,7 @@
1909 * - extended small page/tiny page
1910 */
1911 #define PTE_EXT_XN (_AT(pteval_t, 1) << 0) /* v6 */
1912+#define PTE_EXT_PXN (_AT(pteval_t, 1) << 2) /* v7 */
1913 #define PTE_EXT_AP_MASK (_AT(pteval_t, 3) << 4)
1914 #define PTE_EXT_AP0 (_AT(pteval_t, 1) << 4)
1915 #define PTE_EXT_AP1 (_AT(pteval_t, 2) << 4)
1916diff --git a/arch/arm/include/asm/pgtable-2level.h b/arch/arm/include/asm/pgtable-2level.h
1917index f97ee02..cc9fe9e 100644
1918--- a/arch/arm/include/asm/pgtable-2level.h
1919+++ b/arch/arm/include/asm/pgtable-2level.h
1920@@ -126,6 +126,9 @@
1921 #define L_PTE_SHARED (_AT(pteval_t, 1) << 10) /* shared(v6), coherent(xsc3) */
1922 #define L_PTE_NONE (_AT(pteval_t, 1) << 11)
1923
1924+/* Two-level page tables only have PXN in the PGD, not in the PTE. */
1925+#define L_PTE_PXN (_AT(pteval_t, 0))
1926+
1927 /*
1928 * These are the memory types, defined to be compatible with
1929 * pre-ARMv6 CPUs cacheable and bufferable bits: XXCB
1930diff --git a/arch/arm/include/asm/pgtable-3level-hwdef.h b/arch/arm/include/asm/pgtable-3level-hwdef.h
1931index 626989f..9d67a33 100644
1932--- a/arch/arm/include/asm/pgtable-3level-hwdef.h
1933+++ b/arch/arm/include/asm/pgtable-3level-hwdef.h
1934@@ -75,6 +75,7 @@
1935 #define PTE_EXT_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1936 #define PTE_EXT_AF (_AT(pteval_t, 1) << 10) /* Access Flag */
1937 #define PTE_EXT_NG (_AT(pteval_t, 1) << 11) /* nG */
1938+#define PTE_EXT_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1939 #define PTE_EXT_XN (_AT(pteval_t, 1) << 54) /* XN */
1940
1941 /*
1942diff --git a/arch/arm/include/asm/pgtable-3level.h b/arch/arm/include/asm/pgtable-3level.h
1943index 5689c18..eea12f9 100644
1944--- a/arch/arm/include/asm/pgtable-3level.h
1945+++ b/arch/arm/include/asm/pgtable-3level.h
1946@@ -82,6 +82,7 @@
1947 #define L_PTE_RDONLY (_AT(pteval_t, 1) << 7) /* AP[2] */
1948 #define L_PTE_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1949 #define L_PTE_YOUNG (_AT(pteval_t, 1) << 10) /* AF */
1950+#define L_PTE_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1951 #define L_PTE_XN (_AT(pteval_t, 1) << 54) /* XN */
1952 #define L_PTE_DIRTY (_AT(pteval_t, 1) << 55) /* unused */
1953 #define L_PTE_SPECIAL (_AT(pteval_t, 1) << 56) /* unused */
1954@@ -95,6 +96,7 @@
1955 /*
1956 * To be used in assembly code with the upper page attributes.
1957 */
1958+#define L_PTE_PXN_HIGH (1 << (53 - 32))
1959 #define L_PTE_XN_HIGH (1 << (54 - 32))
1960 #define L_PTE_DIRTY_HIGH (1 << (55 - 32))
1961
1962diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h
1963index be956db..c8f25e2 100644
1964--- a/arch/arm/include/asm/pgtable.h
1965+++ b/arch/arm/include/asm/pgtable.h
1966@@ -33,6 +33,9 @@
1967 #include <asm/pgtable-2level.h>
1968 #endif
1969
1970+#define ktla_ktva(addr) (addr)
1971+#define ktva_ktla(addr) (addr)
1972+
1973 /*
1974 * Just any arbitrary offset to the start of the vmalloc VM area: the
1975 * current 8MB value just means that there will be a 8MB "hole" after the
1976@@ -48,6 +51,9 @@
1977 #define LIBRARY_TEXT_START 0x0c000000
1978
1979 #ifndef __ASSEMBLY__
1980+extern pteval_t __supported_pte_mask;
1981+extern pmdval_t __supported_pmd_mask;
1982+
1983 extern void __pte_error(const char *file, int line, pte_t);
1984 extern void __pmd_error(const char *file, int line, pmd_t);
1985 extern void __pgd_error(const char *file, int line, pgd_t);
1986@@ -56,6 +62,48 @@ extern void __pgd_error(const char *file, int line, pgd_t);
1987 #define pmd_ERROR(pmd) __pmd_error(__FILE__, __LINE__, pmd)
1988 #define pgd_ERROR(pgd) __pgd_error(__FILE__, __LINE__, pgd)
1989
1990+#define __HAVE_ARCH_PAX_OPEN_KERNEL
1991+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
1992+
1993+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
1994+#include <asm/domain.h>
1995+#include <linux/thread_info.h>
1996+#include <linux/preempt.h>
1997+
1998+static inline int test_domain(int domain, int domaintype)
1999+{
2000+ return ((current_thread_info()->cpu_domain) & domain_val(domain, 3)) == domain_val(domain, domaintype);
2001+}
2002+#endif
2003+
2004+#ifdef CONFIG_PAX_KERNEXEC
2005+static inline unsigned long pax_open_kernel(void) {
2006+#ifdef CONFIG_ARM_LPAE
2007+ /* TODO */
2008+#else
2009+ preempt_disable();
2010+ BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC));
2011+ modify_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC);
2012+#endif
2013+ return 0;
2014+}
2015+
2016+static inline unsigned long pax_close_kernel(void) {
2017+#ifdef CONFIG_ARM_LPAE
2018+ /* TODO */
2019+#else
2020+ BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_MANAGER));
2021+ /* DOMAIN_MANAGER = "client" under KERNEXEC */
2022+ modify_domain(DOMAIN_KERNEL, DOMAIN_MANAGER);
2023+ preempt_enable_no_resched();
2024+#endif
2025+ return 0;
2026+}
2027+#else
2028+static inline unsigned long pax_open_kernel(void) { return 0; }
2029+static inline unsigned long pax_close_kernel(void) { return 0; }
2030+#endif
2031+
2032 /*
2033 * This is the lowest virtual address we can permit any user space
2034 * mapping to be mapped at. This is particularly important for
2035@@ -75,8 +123,8 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2036 /*
2037 * The pgprot_* and protection_map entries will be fixed up in runtime
2038 * to include the cachable and bufferable bits based on memory policy,
2039- * as well as any architecture dependent bits like global/ASID and SMP
2040- * shared mapping bits.
2041+ * as well as any architecture dependent bits like global/ASID, PXN,
2042+ * and SMP shared mapping bits.
2043 */
2044 #define _L_PTE_DEFAULT L_PTE_PRESENT | L_PTE_YOUNG
2045
2046@@ -260,7 +308,7 @@ static inline pte_t pte_mkspecial(pte_t pte) { return pte; }
2047 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
2048 {
2049 const pteval_t mask = L_PTE_XN | L_PTE_RDONLY | L_PTE_USER |
2050- L_PTE_NONE | L_PTE_VALID;
2051+ L_PTE_NONE | L_PTE_VALID | __supported_pte_mask;
2052 pte_val(pte) = (pte_val(pte) & ~mask) | (pgprot_val(newprot) & mask);
2053 return pte;
2054 }
2055diff --git a/arch/arm/include/asm/proc-fns.h b/arch/arm/include/asm/proc-fns.h
2056index 5324c11..bcae5f0 100644
2057--- a/arch/arm/include/asm/proc-fns.h
2058+++ b/arch/arm/include/asm/proc-fns.h
2059@@ -75,7 +75,7 @@ extern struct processor {
2060 unsigned int suspend_size;
2061 void (*do_suspend)(void *);
2062 void (*do_resume)(void *);
2063-} processor;
2064+} __do_const processor;
2065
2066 #ifndef MULTI_CPU
2067 extern void cpu_proc_init(void);
2068diff --git a/arch/arm/include/asm/psci.h b/arch/arm/include/asm/psci.h
2069index c4ae171..ea0c0c2 100644
2070--- a/arch/arm/include/asm/psci.h
2071+++ b/arch/arm/include/asm/psci.h
2072@@ -29,7 +29,7 @@ struct psci_operations {
2073 int (*cpu_off)(struct psci_power_state state);
2074 int (*cpu_on)(unsigned long cpuid, unsigned long entry_point);
2075 int (*migrate)(unsigned long cpuid);
2076-};
2077+} __no_const;
2078
2079 extern struct psci_operations psci_ops;
2080 extern struct smp_operations psci_smp_ops;
2081diff --git a/arch/arm/include/asm/smp.h b/arch/arm/include/asm/smp.h
2082index a8cae71c..65dd797 100644
2083--- a/arch/arm/include/asm/smp.h
2084+++ b/arch/arm/include/asm/smp.h
2085@@ -110,7 +110,7 @@ struct smp_operations {
2086 int (*cpu_disable)(unsigned int cpu);
2087 #endif
2088 #endif
2089-};
2090+} __no_const;
2091
2092 /*
2093 * set platform specific SMP operations
2094diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
2095index df5e13d..97efb82 100644
2096--- a/arch/arm/include/asm/thread_info.h
2097+++ b/arch/arm/include/asm/thread_info.h
2098@@ -88,9 +88,9 @@ struct thread_info {
2099 .flags = 0, \
2100 .preempt_count = INIT_PREEMPT_COUNT, \
2101 .addr_limit = KERNEL_DS, \
2102- .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2103- domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2104- domain_val(DOMAIN_IO, DOMAIN_CLIENT), \
2105+ .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_USERCLIENT) | \
2106+ domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT) | \
2107+ domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT), \
2108 .restart_block = { \
2109 .fn = do_no_restart_syscall, \
2110 }, \
2111@@ -163,7 +163,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2112 #define TIF_SYSCALL_AUDIT 9
2113 #define TIF_SYSCALL_TRACEPOINT 10
2114 #define TIF_SECCOMP 11 /* seccomp syscall filtering active */
2115-#define TIF_NOHZ 12 /* in adaptive nohz mode */
2116+/* within 8 bits of TIF_SYSCALL_TRACE
2117+ * to meet flexible second operand requirements
2118+ */
2119+#define TIF_GRSEC_SETXID 12
2120+#define TIF_NOHZ 13 /* in adaptive nohz mode */
2121 #define TIF_USING_IWMMXT 17
2122 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
2123 #define TIF_RESTORE_SIGMASK 20
2124@@ -176,10 +180,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2125 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
2126 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
2127 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
2128+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
2129
2130 /* Checks for any syscall work in entry-common.S */
2131 #define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
2132- _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
2133+ _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | _TIF_GRSEC_SETXID)
2134
2135 /*
2136 * Change these and you break ASM code in entry-common.S
2137diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
2138index 72abdc5..9eba222 100644
2139--- a/arch/arm/include/asm/uaccess.h
2140+++ b/arch/arm/include/asm/uaccess.h
2141@@ -18,6 +18,7 @@
2142 #include <asm/domain.h>
2143 #include <asm/unified.h>
2144 #include <asm/compiler.h>
2145+#include <asm/pgtable.h>
2146
2147 #if __LINUX_ARM_ARCH__ < 6
2148 #include <asm-generic/uaccess-unaligned.h>
2149@@ -70,11 +71,38 @@ extern int __put_user_bad(void);
2150 static inline void set_fs(mm_segment_t fs)
2151 {
2152 current_thread_info()->addr_limit = fs;
2153- modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_CLIENT : DOMAIN_MANAGER);
2154+ modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_KERNELCLIENT : DOMAIN_MANAGER);
2155 }
2156
2157 #define segment_eq(a,b) ((a) == (b))
2158
2159+#define __HAVE_ARCH_PAX_OPEN_USERLAND
2160+#define __HAVE_ARCH_PAX_CLOSE_USERLAND
2161+
2162+static inline void pax_open_userland(void)
2163+{
2164+
2165+#ifdef CONFIG_PAX_MEMORY_UDEREF
2166+ if (segment_eq(get_fs(), USER_DS)) {
2167+ BUG_ON(test_domain(DOMAIN_USER, DOMAIN_UDEREF));
2168+ modify_domain(DOMAIN_USER, DOMAIN_UDEREF);
2169+ }
2170+#endif
2171+
2172+}
2173+
2174+static inline void pax_close_userland(void)
2175+{
2176+
2177+#ifdef CONFIG_PAX_MEMORY_UDEREF
2178+ if (segment_eq(get_fs(), USER_DS)) {
2179+ BUG_ON(test_domain(DOMAIN_USER, DOMAIN_NOACCESS));
2180+ modify_domain(DOMAIN_USER, DOMAIN_NOACCESS);
2181+ }
2182+#endif
2183+
2184+}
2185+
2186 #define __addr_ok(addr) ({ \
2187 unsigned long flag; \
2188 __asm__("cmp %2, %0; movlo %0, #0" \
2189@@ -150,8 +178,12 @@ extern int __get_user_4(void *);
2190
2191 #define get_user(x,p) \
2192 ({ \
2193+ int __e; \
2194 might_fault(); \
2195- __get_user_check(x,p); \
2196+ pax_open_userland(); \
2197+ __e = __get_user_check(x,p); \
2198+ pax_close_userland(); \
2199+ __e; \
2200 })
2201
2202 extern int __put_user_1(void *, unsigned int);
2203@@ -195,8 +227,12 @@ extern int __put_user_8(void *, unsigned long long);
2204
2205 #define put_user(x,p) \
2206 ({ \
2207+ int __e; \
2208 might_fault(); \
2209- __put_user_check(x,p); \
2210+ pax_open_userland(); \
2211+ __e = __put_user_check(x,p); \
2212+ pax_close_userland(); \
2213+ __e; \
2214 })
2215
2216 #else /* CONFIG_MMU */
2217@@ -237,13 +273,17 @@ static inline void set_fs(mm_segment_t fs)
2218 #define __get_user(x,ptr) \
2219 ({ \
2220 long __gu_err = 0; \
2221+ pax_open_userland(); \
2222 __get_user_err((x),(ptr),__gu_err); \
2223+ pax_close_userland(); \
2224 __gu_err; \
2225 })
2226
2227 #define __get_user_error(x,ptr,err) \
2228 ({ \
2229+ pax_open_userland(); \
2230 __get_user_err((x),(ptr),err); \
2231+ pax_close_userland(); \
2232 (void) 0; \
2233 })
2234
2235@@ -319,13 +359,17 @@ do { \
2236 #define __put_user(x,ptr) \
2237 ({ \
2238 long __pu_err = 0; \
2239+ pax_open_userland(); \
2240 __put_user_err((x),(ptr),__pu_err); \
2241+ pax_close_userland(); \
2242 __pu_err; \
2243 })
2244
2245 #define __put_user_error(x,ptr,err) \
2246 ({ \
2247+ pax_open_userland(); \
2248 __put_user_err((x),(ptr),err); \
2249+ pax_close_userland(); \
2250 (void) 0; \
2251 })
2252
2253@@ -425,11 +469,44 @@ do { \
2254
2255
2256 #ifdef CONFIG_MMU
2257-extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
2258-extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
2259+extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
2260+extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
2261+
2262+static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
2263+{
2264+ unsigned long ret;
2265+
2266+ check_object_size(to, n, false);
2267+ pax_open_userland();
2268+ ret = ___copy_from_user(to, from, n);
2269+ pax_close_userland();
2270+ return ret;
2271+}
2272+
2273+static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
2274+{
2275+ unsigned long ret;
2276+
2277+ check_object_size(from, n, true);
2278+ pax_open_userland();
2279+ ret = ___copy_to_user(to, from, n);
2280+ pax_close_userland();
2281+ return ret;
2282+}
2283+
2284 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
2285-extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
2286+extern unsigned long __must_check ___clear_user(void __user *addr, unsigned long n);
2287 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
2288+
2289+static inline unsigned long __must_check __clear_user(void __user *addr, unsigned long n)
2290+{
2291+ unsigned long ret;
2292+ pax_open_userland();
2293+ ret = ___clear_user(addr, n);
2294+ pax_close_userland();
2295+ return ret;
2296+}
2297+
2298 #else
2299 #define __copy_from_user(to,from,n) (memcpy(to, (void __force *)from, n), 0)
2300 #define __copy_to_user(to,from,n) (memcpy((void __force *)to, from, n), 0)
2301@@ -438,6 +515,9 @@ extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned l
2302
2303 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
2304 {
2305+ if ((long)n < 0)
2306+ return n;
2307+
2308 if (access_ok(VERIFY_READ, from, n))
2309 n = __copy_from_user(to, from, n);
2310 else /* security hole - plug it */
2311@@ -447,6 +527,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
2312
2313 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
2314 {
2315+ if ((long)n < 0)
2316+ return n;
2317+
2318 if (access_ok(VERIFY_WRITE, to, n))
2319 n = __copy_to_user(to, from, n);
2320 return n;
2321diff --git a/arch/arm/include/uapi/asm/ptrace.h b/arch/arm/include/uapi/asm/ptrace.h
2322index 5af0ed1..cea83883 100644
2323--- a/arch/arm/include/uapi/asm/ptrace.h
2324+++ b/arch/arm/include/uapi/asm/ptrace.h
2325@@ -92,7 +92,7 @@
2326 * ARMv7 groups of PSR bits
2327 */
2328 #define APSR_MASK 0xf80f0000 /* N, Z, C, V, Q and GE flags */
2329-#define PSR_ISET_MASK 0x01000010 /* ISA state (J, T) mask */
2330+#define PSR_ISET_MASK 0x01000020 /* ISA state (J, T) mask */
2331 #define PSR_IT_MASK 0x0600fc00 /* If-Then execution state mask */
2332 #define PSR_ENDIAN_MASK 0x00000200 /* Endianness state mask */
2333
2334diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
2335index 60d3b73..e5a0f22 100644
2336--- a/arch/arm/kernel/armksyms.c
2337+++ b/arch/arm/kernel/armksyms.c
2338@@ -53,7 +53,7 @@ EXPORT_SYMBOL(arm_delay_ops);
2339
2340 /* networking */
2341 EXPORT_SYMBOL(csum_partial);
2342-EXPORT_SYMBOL(csum_partial_copy_from_user);
2343+EXPORT_SYMBOL(__csum_partial_copy_from_user);
2344 EXPORT_SYMBOL(csum_partial_copy_nocheck);
2345 EXPORT_SYMBOL(__csum_ipv6_magic);
2346
2347@@ -89,9 +89,9 @@ EXPORT_SYMBOL(__memzero);
2348 #ifdef CONFIG_MMU
2349 EXPORT_SYMBOL(copy_page);
2350
2351-EXPORT_SYMBOL(__copy_from_user);
2352-EXPORT_SYMBOL(__copy_to_user);
2353-EXPORT_SYMBOL(__clear_user);
2354+EXPORT_SYMBOL(___copy_from_user);
2355+EXPORT_SYMBOL(___copy_to_user);
2356+EXPORT_SYMBOL(___clear_user);
2357
2358 EXPORT_SYMBOL(__get_user_1);
2359 EXPORT_SYMBOL(__get_user_2);
2360diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S
2361index 9cbe70c..a7b5e34 100644
2362--- a/arch/arm/kernel/entry-armv.S
2363+++ b/arch/arm/kernel/entry-armv.S
2364@@ -47,6 +47,87 @@
2365 9997:
2366 .endm
2367
2368+ .macro pax_enter_kernel
2369+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2370+ @ make aligned space for saved DACR
2371+ sub sp, sp, #8
2372+ @ save regs
2373+ stmdb sp!, {r1, r2}
2374+ @ read DACR from cpu_domain into r1
2375+ mov r2, sp
2376+ @ assume 8K pages, since we have to split the immediate in two
2377+ bic r2, r2, #(0x1fc0)
2378+ bic r2, r2, #(0x3f)
2379+ ldr r1, [r2, #TI_CPU_DOMAIN]
2380+ @ store old DACR on stack
2381+ str r1, [sp, #8]
2382+#ifdef CONFIG_PAX_KERNEXEC
2383+ @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2384+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2385+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2386+#endif
2387+#ifdef CONFIG_PAX_MEMORY_UDEREF
2388+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2389+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2390+#endif
2391+ @ write r1 to current_thread_info()->cpu_domain
2392+ str r1, [r2, #TI_CPU_DOMAIN]
2393+ @ write r1 to DACR
2394+ mcr p15, 0, r1, c3, c0, 0
2395+ @ instruction sync
2396+ instr_sync
2397+ @ restore regs
2398+ ldmia sp!, {r1, r2}
2399+#endif
2400+ .endm
2401+
2402+ .macro pax_open_userland
2403+#ifdef CONFIG_PAX_MEMORY_UDEREF
2404+ @ save regs
2405+ stmdb sp!, {r0, r1}
2406+ @ read DACR from cpu_domain into r1
2407+ mov r0, sp
2408+ @ assume 8K pages, since we have to split the immediate in two
2409+ bic r0, r0, #(0x1fc0)
2410+ bic r0, r0, #(0x3f)
2411+ ldr r1, [r0, #TI_CPU_DOMAIN]
2412+ @ set current DOMAIN_USER to DOMAIN_CLIENT
2413+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2414+ orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2415+ @ write r1 to current_thread_info()->cpu_domain
2416+ str r1, [r0, #TI_CPU_DOMAIN]
2417+ @ write r1 to DACR
2418+ mcr p15, 0, r1, c3, c0, 0
2419+ @ instruction sync
2420+ instr_sync
2421+ @ restore regs
2422+ ldmia sp!, {r0, r1}
2423+#endif
2424+ .endm
2425+
2426+ .macro pax_close_userland
2427+#ifdef CONFIG_PAX_MEMORY_UDEREF
2428+ @ save regs
2429+ stmdb sp!, {r0, r1}
2430+ @ read DACR from cpu_domain into r1
2431+ mov r0, sp
2432+ @ assume 8K pages, since we have to split the immediate in two
2433+ bic r0, r0, #(0x1fc0)
2434+ bic r0, r0, #(0x3f)
2435+ ldr r1, [r0, #TI_CPU_DOMAIN]
2436+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2437+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2438+ @ write r1 to current_thread_info()->cpu_domain
2439+ str r1, [r0, #TI_CPU_DOMAIN]
2440+ @ write r1 to DACR
2441+ mcr p15, 0, r1, c3, c0, 0
2442+ @ instruction sync
2443+ instr_sync
2444+ @ restore regs
2445+ ldmia sp!, {r0, r1}
2446+#endif
2447+ .endm
2448+
2449 .macro pabt_helper
2450 @ PABORT handler takes pt_regs in r2, fault address in r4 and psr in r5
2451 #ifdef MULTI_PABORT
2452@@ -89,11 +170,15 @@
2453 * Invalid mode handlers
2454 */
2455 .macro inv_entry, reason
2456+
2457+ pax_enter_kernel
2458+
2459 sub sp, sp, #S_FRAME_SIZE
2460 ARM( stmib sp, {r1 - lr} )
2461 THUMB( stmia sp, {r0 - r12} )
2462 THUMB( str sp, [sp, #S_SP] )
2463 THUMB( str lr, [sp, #S_LR] )
2464+
2465 mov r1, #\reason
2466 .endm
2467
2468@@ -149,7 +234,11 @@ ENDPROC(__und_invalid)
2469 .macro svc_entry, stack_hole=0
2470 UNWIND(.fnstart )
2471 UNWIND(.save {r0 - pc} )
2472+
2473+ pax_enter_kernel
2474+
2475 sub sp, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2476+
2477 #ifdef CONFIG_THUMB2_KERNEL
2478 SPFIX( str r0, [sp] ) @ temporarily saved
2479 SPFIX( mov r0, sp )
2480@@ -164,7 +253,12 @@ ENDPROC(__und_invalid)
2481 ldmia r0, {r3 - r5}
2482 add r7, sp, #S_SP - 4 @ here for interlock avoidance
2483 mov r6, #-1 @ "" "" "" ""
2484+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2485+ @ offset sp by 8 as done in pax_enter_kernel
2486+ add r2, sp, #(S_FRAME_SIZE + \stack_hole + 4)
2487+#else
2488 add r2, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2489+#endif
2490 SPFIX( addeq r2, r2, #4 )
2491 str r3, [sp, #-4]! @ save the "real" r0 copied
2492 @ from the exception stack
2493@@ -316,6 +410,9 @@ ENDPROC(__pabt_svc)
2494 .macro usr_entry
2495 UNWIND(.fnstart )
2496 UNWIND(.cantunwind ) @ don't unwind the user space
2497+
2498+ pax_enter_kernel_user
2499+
2500 sub sp, sp, #S_FRAME_SIZE
2501 ARM( stmib sp, {r1 - r12} )
2502 THUMB( stmia sp, {r0 - r12} )
2503@@ -415,7 +512,9 @@ __und_usr:
2504 tst r3, #PSR_T_BIT @ Thumb mode?
2505 bne __und_usr_thumb
2506 sub r4, r2, #4 @ ARM instr at LR - 4
2507+ pax_open_userland
2508 1: ldrt r0, [r4]
2509+ pax_close_userland
2510 #ifdef CONFIG_CPU_ENDIAN_BE8
2511 rev r0, r0 @ little endian instruction
2512 #endif
2513@@ -450,10 +549,14 @@ __und_usr_thumb:
2514 */
2515 .arch armv6t2
2516 #endif
2517+ pax_open_userland
2518 2: ldrht r5, [r4]
2519+ pax_close_userland
2520 cmp r5, #0xe800 @ 32bit instruction if xx != 0
2521 blo __und_usr_fault_16 @ 16bit undefined instruction
2522+ pax_open_userland
2523 3: ldrht r0, [r2]
2524+ pax_close_userland
2525 add r2, r2, #2 @ r2 is PC + 2, make it PC + 4
2526 str r2, [sp, #S_PC] @ it's a 2x16bit instr, update
2527 orr r0, r0, r5, lsl #16
2528@@ -482,7 +585,8 @@ ENDPROC(__und_usr)
2529 */
2530 .pushsection .fixup, "ax"
2531 .align 2
2532-4: mov pc, r9
2533+4: pax_close_userland
2534+ mov pc, r9
2535 .popsection
2536 .pushsection __ex_table,"a"
2537 .long 1b, 4b
2538@@ -692,7 +796,7 @@ ENTRY(__switch_to)
2539 THUMB( str lr, [ip], #4 )
2540 ldr r4, [r2, #TI_TP_VALUE]
2541 ldr r5, [r2, #TI_TP_VALUE + 4]
2542-#ifdef CONFIG_CPU_USE_DOMAINS
2543+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2544 ldr r6, [r2, #TI_CPU_DOMAIN]
2545 #endif
2546 switch_tls r1, r4, r5, r3, r7
2547@@ -701,7 +805,7 @@ ENTRY(__switch_to)
2548 ldr r8, =__stack_chk_guard
2549 ldr r7, [r7, #TSK_STACK_CANARY]
2550 #endif
2551-#ifdef CONFIG_CPU_USE_DOMAINS
2552+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2553 mcr p15, 0, r6, c3, c0, 0 @ Set domain register
2554 #endif
2555 mov r5, r0
2556diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
2557index bc6bd96..bd026cb 100644
2558--- a/arch/arm/kernel/entry-common.S
2559+++ b/arch/arm/kernel/entry-common.S
2560@@ -10,18 +10,46 @@
2561
2562 #include <asm/unistd.h>
2563 #include <asm/ftrace.h>
2564+#include <asm/domain.h>
2565 #include <asm/unwind.h>
2566
2567+#include "entry-header.S"
2568+
2569 #ifdef CONFIG_NEED_RET_TO_USER
2570 #include <mach/entry-macro.S>
2571 #else
2572 .macro arch_ret_to_user, tmp1, tmp2
2573+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2574+ @ save regs
2575+ stmdb sp!, {r1, r2}
2576+ @ read DACR from cpu_domain into r1
2577+ mov r2, sp
2578+ @ assume 8K pages, since we have to split the immediate in two
2579+ bic r2, r2, #(0x1fc0)
2580+ bic r2, r2, #(0x3f)
2581+ ldr r1, [r2, #TI_CPU_DOMAIN]
2582+#ifdef CONFIG_PAX_KERNEXEC
2583+ @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2584+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2585+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2586+#endif
2587+#ifdef CONFIG_PAX_MEMORY_UDEREF
2588+ @ set current DOMAIN_USER to DOMAIN_UDEREF
2589+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2590+ orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2591+#endif
2592+ @ write r1 to current_thread_info()->cpu_domain
2593+ str r1, [r2, #TI_CPU_DOMAIN]
2594+ @ write r1 to DACR
2595+ mcr p15, 0, r1, c3, c0, 0
2596+ @ instruction sync
2597+ instr_sync
2598+ @ restore regs
2599+ ldmia sp!, {r1, r2}
2600+#endif
2601 .endm
2602 #endif
2603
2604-#include "entry-header.S"
2605-
2606-
2607 .align 5
2608 /*
2609 * This is the fast syscall return path. We do as little as
2610@@ -413,6 +441,12 @@ ENTRY(vector_swi)
2611 USER( ldr scno, [lr, #-4] ) @ get SWI instruction
2612 #endif
2613
2614+ /*
2615+ * do this here to avoid a performance hit of wrapping the code above
2616+ * that directly dereferences userland to parse the SWI instruction
2617+ */
2618+ pax_enter_kernel_user
2619+
2620 adr tbl, sys_call_table @ load syscall table pointer
2621
2622 #if defined(CONFIG_OABI_COMPAT)
2623diff --git a/arch/arm/kernel/entry-header.S b/arch/arm/kernel/entry-header.S
2624index 39f89fb..d612bd9 100644
2625--- a/arch/arm/kernel/entry-header.S
2626+++ b/arch/arm/kernel/entry-header.S
2627@@ -184,6 +184,60 @@
2628 msr cpsr_c, \rtemp @ switch back to the SVC mode
2629 .endm
2630
2631+ .macro pax_enter_kernel_user
2632+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2633+ @ save regs
2634+ stmdb sp!, {r0, r1}
2635+ @ read DACR from cpu_domain into r1
2636+ mov r0, sp
2637+ @ assume 8K pages, since we have to split the immediate in two
2638+ bic r0, r0, #(0x1fc0)
2639+ bic r0, r0, #(0x3f)
2640+ ldr r1, [r0, #TI_CPU_DOMAIN]
2641+#ifdef CONFIG_PAX_MEMORY_UDEREF
2642+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2643+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2644+#endif
2645+#ifdef CONFIG_PAX_KERNEXEC
2646+ @ set current DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2647+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2648+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2649+#endif
2650+ @ write r1 to current_thread_info()->cpu_domain
2651+ str r1, [r0, #TI_CPU_DOMAIN]
2652+ @ write r1 to DACR
2653+ mcr p15, 0, r1, c3, c0, 0
2654+ @ instruction sync
2655+ instr_sync
2656+ @ restore regs
2657+ ldmia sp!, {r0, r1}
2658+#endif
2659+ .endm
2660+
2661+ .macro pax_exit_kernel
2662+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2663+ @ save regs
2664+ stmdb sp!, {r0, r1}
2665+ @ read old DACR from stack into r1
2666+ ldr r1, [sp, #(8 + S_SP)]
2667+ sub r1, r1, #8
2668+ ldr r1, [r1]
2669+
2670+ @ write r1 to current_thread_info()->cpu_domain
2671+ mov r0, sp
2672+ @ assume 8K pages, since we have to split the immediate in two
2673+ bic r0, r0, #(0x1fc0)
2674+ bic r0, r0, #(0x3f)
2675+ str r1, [r0, #TI_CPU_DOMAIN]
2676+ @ write r1 to DACR
2677+ mcr p15, 0, r1, c3, c0, 0
2678+ @ instruction sync
2679+ instr_sync
2680+ @ restore regs
2681+ ldmia sp!, {r0, r1}
2682+#endif
2683+ .endm
2684+
2685 #ifndef CONFIG_THUMB2_KERNEL
2686 .macro svc_exit, rpsr, irq = 0
2687 .if \irq != 0
2688@@ -203,6 +257,9 @@
2689 blne trace_hardirqs_off
2690 #endif
2691 .endif
2692+
2693+ pax_exit_kernel
2694+
2695 msr spsr_cxsf, \rpsr
2696 #if defined(CONFIG_CPU_V6)
2697 ldr r0, [sp]
2698@@ -266,6 +323,9 @@
2699 blne trace_hardirqs_off
2700 #endif
2701 .endif
2702+
2703+ pax_exit_kernel
2704+
2705 ldr lr, [sp, #S_SP] @ top of the stack
2706 ldrd r0, r1, [sp, #S_LR] @ calling lr and pc
2707 clrex @ clear the exclusive monitor
2708diff --git a/arch/arm/kernel/fiq.c b/arch/arm/kernel/fiq.c
2709index 918875d..cd5fa27 100644
2710--- a/arch/arm/kernel/fiq.c
2711+++ b/arch/arm/kernel/fiq.c
2712@@ -87,7 +87,10 @@ void set_fiq_handler(void *start, unsigned int length)
2713 void *base = vectors_page;
2714 unsigned offset = FIQ_OFFSET;
2715
2716+ pax_open_kernel();
2717 memcpy(base + offset, start, length);
2718+ pax_close_kernel();
2719+
2720 if (!cache_is_vipt_nonaliasing())
2721 flush_icache_range((unsigned long)base + offset, offset +
2722 length);
2723diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S
2724index 476de57..4857a76 100644
2725--- a/arch/arm/kernel/head.S
2726+++ b/arch/arm/kernel/head.S
2727@@ -52,7 +52,9 @@
2728 .equ swapper_pg_dir, KERNEL_RAM_VADDR - PG_DIR_SIZE
2729
2730 .macro pgtbl, rd, phys
2731- add \rd, \phys, #TEXT_OFFSET - PG_DIR_SIZE
2732+ mov \rd, #TEXT_OFFSET
2733+ sub \rd, #PG_DIR_SIZE
2734+ add \rd, \rd, \phys
2735 .endm
2736
2737 /*
2738@@ -432,7 +434,7 @@ __enable_mmu:
2739 mov r5, #(domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2740 domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2741 domain_val(DOMAIN_TABLE, DOMAIN_MANAGER) | \
2742- domain_val(DOMAIN_IO, DOMAIN_CLIENT))
2743+ domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT))
2744 mcr p15, 0, r5, c3, c0, 0 @ load domain access register
2745 mcr p15, 0, r4, c2, c0, 0 @ load page table pointer
2746 #endif
2747diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c
2748index 084dc88..fce4e68 100644
2749--- a/arch/arm/kernel/module.c
2750+++ b/arch/arm/kernel/module.c
2751@@ -37,12 +37,39 @@
2752 #endif
2753
2754 #ifdef CONFIG_MMU
2755-void *module_alloc(unsigned long size)
2756+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
2757 {
2758+ if (!size || PAGE_ALIGN(size) > MODULES_END - MODULES_VADDR)
2759+ return NULL;
2760 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
2761- GFP_KERNEL, PAGE_KERNEL_EXEC, -1,
2762+ GFP_KERNEL, prot, -1,
2763 __builtin_return_address(0));
2764 }
2765+
2766+void *module_alloc(unsigned long size)
2767+{
2768+
2769+#ifdef CONFIG_PAX_KERNEXEC
2770+ return __module_alloc(size, PAGE_KERNEL);
2771+#else
2772+ return __module_alloc(size, PAGE_KERNEL_EXEC);
2773+#endif
2774+
2775+}
2776+
2777+#ifdef CONFIG_PAX_KERNEXEC
2778+void module_free_exec(struct module *mod, void *module_region)
2779+{
2780+ module_free(mod, module_region);
2781+}
2782+EXPORT_SYMBOL(module_free_exec);
2783+
2784+void *module_alloc_exec(unsigned long size)
2785+{
2786+ return __module_alloc(size, PAGE_KERNEL_EXEC);
2787+}
2788+EXPORT_SYMBOL(module_alloc_exec);
2789+#endif
2790 #endif
2791
2792 int
2793diff --git a/arch/arm/kernel/patch.c b/arch/arm/kernel/patch.c
2794index 07314af..c46655c 100644
2795--- a/arch/arm/kernel/patch.c
2796+++ b/arch/arm/kernel/patch.c
2797@@ -18,6 +18,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2798 bool thumb2 = IS_ENABLED(CONFIG_THUMB2_KERNEL);
2799 int size;
2800
2801+ pax_open_kernel();
2802 if (thumb2 && __opcode_is_thumb16(insn)) {
2803 *(u16 *)addr = __opcode_to_mem_thumb16(insn);
2804 size = sizeof(u16);
2805@@ -39,6 +40,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2806 *(u32 *)addr = insn;
2807 size = sizeof(u32);
2808 }
2809+ pax_close_kernel();
2810
2811 flush_icache_range((uintptr_t)(addr),
2812 (uintptr_t)(addr) + size);
2813diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
2814index 94f6b05..efd7312 100644
2815--- a/arch/arm/kernel/process.c
2816+++ b/arch/arm/kernel/process.c
2817@@ -217,6 +217,7 @@ void machine_power_off(void)
2818
2819 if (pm_power_off)
2820 pm_power_off();
2821+ BUG();
2822 }
2823
2824 /*
2825@@ -230,7 +231,7 @@ void machine_power_off(void)
2826 * executing pre-reset code, and using RAM that the primary CPU's code wishes
2827 * to use. Implementing such co-ordination would be essentially impossible.
2828 */
2829-void machine_restart(char *cmd)
2830+__noreturn void machine_restart(char *cmd)
2831 {
2832 local_irq_disable();
2833 smp_send_stop();
2834@@ -253,8 +254,8 @@ void __show_regs(struct pt_regs *regs)
2835
2836 show_regs_print_info(KERN_DEFAULT);
2837
2838- print_symbol("PC is at %s\n", instruction_pointer(regs));
2839- print_symbol("LR is at %s\n", regs->ARM_lr);
2840+ printk("PC is at %pA\n", (void *)instruction_pointer(regs));
2841+ printk("LR is at %pA\n", (void *)regs->ARM_lr);
2842 printk("pc : [<%08lx>] lr : [<%08lx>] psr: %08lx\n"
2843 "sp : %08lx ip : %08lx fp : %08lx\n",
2844 regs->ARM_pc, regs->ARM_lr, regs->ARM_cpsr,
2845@@ -422,12 +423,6 @@ unsigned long get_wchan(struct task_struct *p)
2846 return 0;
2847 }
2848
2849-unsigned long arch_randomize_brk(struct mm_struct *mm)
2850-{
2851- unsigned long range_end = mm->brk + 0x02000000;
2852- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
2853-}
2854-
2855 #ifdef CONFIG_MMU
2856 #ifdef CONFIG_KUSER_HELPERS
2857 /*
2858@@ -443,7 +438,7 @@ static struct vm_area_struct gate_vma = {
2859
2860 static int __init gate_vma_init(void)
2861 {
2862- gate_vma.vm_page_prot = PAGE_READONLY_EXEC;
2863+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
2864 return 0;
2865 }
2866 arch_initcall(gate_vma_init);
2867@@ -469,41 +464,16 @@ int in_gate_area_no_mm(unsigned long addr)
2868
2869 const char *arch_vma_name(struct vm_area_struct *vma)
2870 {
2871- return is_gate_vma(vma) ? "[vectors]" :
2872- (vma->vm_mm && vma->vm_start == vma->vm_mm->context.sigpage) ?
2873- "[sigpage]" : NULL;
2874+ return is_gate_vma(vma) ? "[vectors]" : NULL;
2875 }
2876
2877-static struct page *signal_page;
2878-extern struct page *get_signal_page(void);
2879-
2880 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
2881 {
2882 struct mm_struct *mm = current->mm;
2883- unsigned long addr;
2884- int ret;
2885-
2886- if (!signal_page)
2887- signal_page = get_signal_page();
2888- if (!signal_page)
2889- return -ENOMEM;
2890
2891 down_write(&mm->mmap_sem);
2892- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
2893- if (IS_ERR_VALUE(addr)) {
2894- ret = addr;
2895- goto up_fail;
2896- }
2897-
2898- ret = install_special_mapping(mm, addr, PAGE_SIZE,
2899- VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC,
2900- &signal_page);
2901-
2902- if (ret == 0)
2903- mm->context.sigpage = addr;
2904-
2905- up_fail:
2906+ mm->context.sigpage = (PAGE_OFFSET + (get_random_int() % 0x3FFEFFE0)) & 0xFFFFFFFC;
2907 up_write(&mm->mmap_sem);
2908- return ret;
2909+ return 0;
2910 }
2911 #endif
2912diff --git a/arch/arm/kernel/psci.c b/arch/arm/kernel/psci.c
2913index 4693188..4596c5e 100644
2914--- a/arch/arm/kernel/psci.c
2915+++ b/arch/arm/kernel/psci.c
2916@@ -24,7 +24,7 @@
2917 #include <asm/opcodes-virt.h>
2918 #include <asm/psci.h>
2919
2920-struct psci_operations psci_ops;
2921+struct psci_operations psci_ops __read_only;
2922
2923 static int (*invoke_psci_fn)(u32, u32, u32, u32);
2924
2925diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
2926index 0dd3b79..e018f64 100644
2927--- a/arch/arm/kernel/ptrace.c
2928+++ b/arch/arm/kernel/ptrace.c
2929@@ -929,10 +929,19 @@ static int tracehook_report_syscall(struct pt_regs *regs,
2930 return current_thread_info()->syscall;
2931 }
2932
2933+#ifdef CONFIG_GRKERNSEC_SETXID
2934+extern void gr_delayed_cred_worker(void);
2935+#endif
2936+
2937 asmlinkage int syscall_trace_enter(struct pt_regs *regs, int scno)
2938 {
2939 current_thread_info()->syscall = scno;
2940
2941+#ifdef CONFIG_GRKERNSEC_SETXID
2942+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
2943+ gr_delayed_cred_worker();
2944+#endif
2945+
2946 /* Do the secure computing check first; failures should be fast. */
2947 if (secure_computing(scno) == -1)
2948 return -1;
2949diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
2950index 0e1e2b3..c0e821d 100644
2951--- a/arch/arm/kernel/setup.c
2952+++ b/arch/arm/kernel/setup.c
2953@@ -98,21 +98,23 @@ EXPORT_SYMBOL(system_serial_high);
2954 unsigned int elf_hwcap __read_mostly;
2955 EXPORT_SYMBOL(elf_hwcap);
2956
2957+pteval_t __supported_pte_mask __read_only;
2958+pmdval_t __supported_pmd_mask __read_only;
2959
2960 #ifdef MULTI_CPU
2961-struct processor processor __read_mostly;
2962+struct processor processor;
2963 #endif
2964 #ifdef MULTI_TLB
2965-struct cpu_tlb_fns cpu_tlb __read_mostly;
2966+struct cpu_tlb_fns cpu_tlb __read_only;
2967 #endif
2968 #ifdef MULTI_USER
2969-struct cpu_user_fns cpu_user __read_mostly;
2970+struct cpu_user_fns cpu_user __read_only;
2971 #endif
2972 #ifdef MULTI_CACHE
2973-struct cpu_cache_fns cpu_cache __read_mostly;
2974+struct cpu_cache_fns cpu_cache __read_only;
2975 #endif
2976 #ifdef CONFIG_OUTER_CACHE
2977-struct outer_cache_fns outer_cache __read_mostly;
2978+struct outer_cache_fns outer_cache __read_only;
2979 EXPORT_SYMBOL(outer_cache);
2980 #endif
2981
2982@@ -245,9 +247,13 @@ static int __get_cpu_architecture(void)
2983 asm("mrc p15, 0, %0, c0, c1, 4"
2984 : "=r" (mmfr0));
2985 if ((mmfr0 & 0x0000000f) >= 0x00000003 ||
2986- (mmfr0 & 0x000000f0) >= 0x00000030)
2987+ (mmfr0 & 0x000000f0) >= 0x00000030) {
2988 cpu_arch = CPU_ARCH_ARMv7;
2989- else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
2990+ if ((mmfr0 & 0x0000000f) == 0x00000005 || (mmfr0 & 0x0000000f) == 0x00000004) {
2991+ __supported_pte_mask |= L_PTE_PXN;
2992+ __supported_pmd_mask |= PMD_PXNTABLE;
2993+ }
2994+ } else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
2995 (mmfr0 & 0x000000f0) == 0x00000020)
2996 cpu_arch = CPU_ARCH_ARMv6;
2997 else
2998@@ -571,7 +577,7 @@ static void __init setup_processor(void)
2999 __cpu_architecture = __get_cpu_architecture();
3000
3001 #ifdef MULTI_CPU
3002- processor = *list->proc;
3003+ memcpy((void *)&processor, list->proc, sizeof processor);
3004 #endif
3005 #ifdef MULTI_TLB
3006 cpu_tlb = *list->tlb;
3007diff --git a/arch/arm/kernel/signal.c b/arch/arm/kernel/signal.c
3008index ab33042..11248a8 100644
3009--- a/arch/arm/kernel/signal.c
3010+++ b/arch/arm/kernel/signal.c
3011@@ -45,8 +45,6 @@ static const unsigned long sigreturn_codes[7] = {
3012 MOV_R7_NR_RT_SIGRETURN, SWI_SYS_RT_SIGRETURN, SWI_THUMB_RT_SIGRETURN,
3013 };
3014
3015-static unsigned long signal_return_offset;
3016-
3017 #ifdef CONFIG_CRUNCH
3018 static int preserve_crunch_context(struct crunch_sigframe __user *frame)
3019 {
3020@@ -411,8 +409,7 @@ setup_return(struct pt_regs *regs, struct ksignal *ksig,
3021 * except when the MPU has protected the vectors
3022 * page from PL0
3023 */
3024- retcode = mm->context.sigpage + signal_return_offset +
3025- (idx << 2) + thumb;
3026+ retcode = mm->context.sigpage + (idx << 2) + thumb;
3027 } else
3028 #endif
3029 {
3030@@ -616,33 +613,3 @@ do_work_pending(struct pt_regs *regs, unsigned int thread_flags, int syscall)
3031 } while (thread_flags & _TIF_WORK_MASK);
3032 return 0;
3033 }
3034-
3035-struct page *get_signal_page(void)
3036-{
3037- unsigned long ptr;
3038- unsigned offset;
3039- struct page *page;
3040- void *addr;
3041-
3042- page = alloc_pages(GFP_KERNEL, 0);
3043-
3044- if (!page)
3045- return NULL;
3046-
3047- addr = page_address(page);
3048-
3049- /* Give the signal return code some randomness */
3050- offset = 0x200 + (get_random_int() & 0x7fc);
3051- signal_return_offset = offset;
3052-
3053- /*
3054- * Copy signal return handlers into the vector page, and
3055- * set sigreturn to be a pointer to these.
3056- */
3057- memcpy(addr + offset, sigreturn_codes, sizeof(sigreturn_codes));
3058-
3059- ptr = (unsigned long)addr + offset;
3060- flush_icache_range(ptr, ptr + sizeof(sigreturn_codes));
3061-
3062- return page;
3063-}
3064diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
3065index 72024ea..ae302dd 100644
3066--- a/arch/arm/kernel/smp.c
3067+++ b/arch/arm/kernel/smp.c
3068@@ -70,7 +70,7 @@ enum ipi_msg_type {
3069
3070 static DECLARE_COMPLETION(cpu_running);
3071
3072-static struct smp_operations smp_ops;
3073+static struct smp_operations smp_ops __read_only;
3074
3075 void __init smp_set_ops(struct smp_operations *ops)
3076 {
3077diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
3078index 8fcda14..4512b9d 100644
3079--- a/arch/arm/kernel/traps.c
3080+++ b/arch/arm/kernel/traps.c
3081@@ -55,7 +55,7 @@ static void dump_mem(const char *, const char *, unsigned long, unsigned long);
3082 void dump_backtrace_entry(unsigned long where, unsigned long from, unsigned long frame)
3083 {
3084 #ifdef CONFIG_KALLSYMS
3085- printk("[<%08lx>] (%pS) from [<%08lx>] (%pS)\n", where, (void *)where, from, (void *)from);
3086+ printk("[<%08lx>] (%pA) from [<%08lx>] (%pA)\n", where, (void *)where, from, (void *)from);
3087 #else
3088 printk("Function entered at [<%08lx>] from [<%08lx>]\n", where, from);
3089 #endif
3090@@ -257,6 +257,8 @@ static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
3091 static int die_owner = -1;
3092 static unsigned int die_nest_count;
3093
3094+extern void gr_handle_kernel_exploit(void);
3095+
3096 static unsigned long oops_begin(void)
3097 {
3098 int cpu;
3099@@ -299,6 +301,9 @@ static void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
3100 panic("Fatal exception in interrupt");
3101 if (panic_on_oops)
3102 panic("Fatal exception");
3103+
3104+ gr_handle_kernel_exploit();
3105+
3106 if (signr)
3107 do_exit(signr);
3108 }
3109@@ -628,7 +633,9 @@ asmlinkage int arm_syscall(int no, struct pt_regs *regs)
3110 * The user helper at 0xffff0fe0 must be used instead.
3111 * (see entry-armv.S for details)
3112 */
3113+ pax_open_kernel();
3114 *((unsigned int *)0xffff0ff0) = regs->ARM_r0;
3115+ pax_close_kernel();
3116 }
3117 return 0;
3118
3119@@ -885,7 +892,11 @@ void __init early_trap_init(void *vectors_base)
3120 kuser_init(vectors_base);
3121
3122 flush_icache_range(vectors, vectors + PAGE_SIZE * 2);
3123- modify_domain(DOMAIN_USER, DOMAIN_CLIENT);
3124+
3125+#ifndef CONFIG_PAX_MEMORY_UDEREF
3126+ modify_domain(DOMAIN_USER, DOMAIN_USERCLIENT);
3127+#endif
3128+
3129 #else /* ifndef CONFIG_CPU_V7M */
3130 /*
3131 * on V7-M there is no need to copy the vector table to a dedicated
3132diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
3133index 7bcee5c..e2f3249 100644
3134--- a/arch/arm/kernel/vmlinux.lds.S
3135+++ b/arch/arm/kernel/vmlinux.lds.S
3136@@ -8,7 +8,11 @@
3137 #include <asm/thread_info.h>
3138 #include <asm/memory.h>
3139 #include <asm/page.h>
3140-
3141+
3142+#ifdef CONFIG_PAX_KERNEXEC
3143+#include <asm/pgtable.h>
3144+#endif
3145+
3146 #define PROC_INFO \
3147 . = ALIGN(4); \
3148 VMLINUX_SYMBOL(__proc_info_begin) = .; \
3149@@ -34,7 +38,7 @@
3150 #endif
3151
3152 #if (defined(CONFIG_SMP_ON_UP) && !defined(CONFIG_DEBUG_SPINLOCK)) || \
3153- defined(CONFIG_GENERIC_BUG)
3154+ defined(CONFIG_GENERIC_BUG) || defined(CONFIG_PAX_REFCOUNT)
3155 #define ARM_EXIT_KEEP(x) x
3156 #define ARM_EXIT_DISCARD(x)
3157 #else
3158@@ -90,6 +94,11 @@ SECTIONS
3159 _text = .;
3160 HEAD_TEXT
3161 }
3162+
3163+#ifdef CONFIG_PAX_KERNEXEC
3164+ . = ALIGN(1<<SECTION_SHIFT);
3165+#endif
3166+
3167 .text : { /* Real text segment */
3168 _stext = .; /* Text and read-only data */
3169 __exception_text_start = .;
3170@@ -112,6 +121,8 @@ SECTIONS
3171 ARM_CPU_KEEP(PROC_INFO)
3172 }
3173
3174+ _etext = .; /* End of text section */
3175+
3176 RO_DATA(PAGE_SIZE)
3177
3178 . = ALIGN(4);
3179@@ -142,7 +153,9 @@ SECTIONS
3180
3181 NOTES
3182
3183- _etext = .; /* End of text and rodata section */
3184+#ifdef CONFIG_PAX_KERNEXEC
3185+ . = ALIGN(1<<SECTION_SHIFT);
3186+#endif
3187
3188 #ifndef CONFIG_XIP_KERNEL
3189 . = ALIGN(PAGE_SIZE);
3190@@ -220,6 +233,11 @@ SECTIONS
3191 . = PAGE_OFFSET + TEXT_OFFSET;
3192 #else
3193 __init_end = .;
3194+
3195+#ifdef CONFIG_PAX_KERNEXEC
3196+ . = ALIGN(1<<SECTION_SHIFT);
3197+#endif
3198+
3199 . = ALIGN(THREAD_SIZE);
3200 __data_loc = .;
3201 #endif
3202diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
3203index 9c697db..115237f 100644
3204--- a/arch/arm/kvm/arm.c
3205+++ b/arch/arm/kvm/arm.c
3206@@ -56,7 +56,7 @@ static unsigned long hyp_default_vectors;
3207 static DEFINE_PER_CPU(struct kvm_vcpu *, kvm_arm_running_vcpu);
3208
3209 /* The VMID used in the VTTBR */
3210-static atomic64_t kvm_vmid_gen = ATOMIC64_INIT(1);
3211+static atomic64_unchecked_t kvm_vmid_gen = ATOMIC64_INIT(1);
3212 static u8 kvm_next_vmid;
3213 static DEFINE_SPINLOCK(kvm_vmid_lock);
3214
3215@@ -396,7 +396,7 @@ void force_vm_exit(const cpumask_t *mask)
3216 */
3217 static bool need_new_vmid_gen(struct kvm *kvm)
3218 {
3219- return unlikely(kvm->arch.vmid_gen != atomic64_read(&kvm_vmid_gen));
3220+ return unlikely(kvm->arch.vmid_gen != atomic64_read_unchecked(&kvm_vmid_gen));
3221 }
3222
3223 /**
3224@@ -429,7 +429,7 @@ static void update_vttbr(struct kvm *kvm)
3225
3226 /* First user of a new VMID generation? */
3227 if (unlikely(kvm_next_vmid == 0)) {
3228- atomic64_inc(&kvm_vmid_gen);
3229+ atomic64_inc_unchecked(&kvm_vmid_gen);
3230 kvm_next_vmid = 1;
3231
3232 /*
3233@@ -446,7 +446,7 @@ static void update_vttbr(struct kvm *kvm)
3234 kvm_call_hyp(__kvm_flush_vm_context);
3235 }
3236
3237- kvm->arch.vmid_gen = atomic64_read(&kvm_vmid_gen);
3238+ kvm->arch.vmid_gen = atomic64_read_unchecked(&kvm_vmid_gen);
3239 kvm->arch.vmid = kvm_next_vmid;
3240 kvm_next_vmid++;
3241
3242diff --git a/arch/arm/lib/clear_user.S b/arch/arm/lib/clear_user.S
3243index 14a0d98..7771a7d 100644
3244--- a/arch/arm/lib/clear_user.S
3245+++ b/arch/arm/lib/clear_user.S
3246@@ -12,14 +12,14 @@
3247
3248 .text
3249
3250-/* Prototype: int __clear_user(void *addr, size_t sz)
3251+/* Prototype: int ___clear_user(void *addr, size_t sz)
3252 * Purpose : clear some user memory
3253 * Params : addr - user memory address to clear
3254 * : sz - number of bytes to clear
3255 * Returns : number of bytes NOT cleared
3256 */
3257 ENTRY(__clear_user_std)
3258-WEAK(__clear_user)
3259+WEAK(___clear_user)
3260 stmfd sp!, {r1, lr}
3261 mov r2, #0
3262 cmp r1, #4
3263@@ -44,7 +44,7 @@ WEAK(__clear_user)
3264 USER( strnebt r2, [r0])
3265 mov r0, #0
3266 ldmfd sp!, {r1, pc}
3267-ENDPROC(__clear_user)
3268+ENDPROC(___clear_user)
3269 ENDPROC(__clear_user_std)
3270
3271 .pushsection .fixup,"ax"
3272diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
3273index 66a477a..bee61d3 100644
3274--- a/arch/arm/lib/copy_from_user.S
3275+++ b/arch/arm/lib/copy_from_user.S
3276@@ -16,7 +16,7 @@
3277 /*
3278 * Prototype:
3279 *
3280- * size_t __copy_from_user(void *to, const void *from, size_t n)
3281+ * size_t ___copy_from_user(void *to, const void *from, size_t n)
3282 *
3283 * Purpose:
3284 *
3285@@ -84,11 +84,11 @@
3286
3287 .text
3288
3289-ENTRY(__copy_from_user)
3290+ENTRY(___copy_from_user)
3291
3292 #include "copy_template.S"
3293
3294-ENDPROC(__copy_from_user)
3295+ENDPROC(___copy_from_user)
3296
3297 .pushsection .fixup,"ax"
3298 .align 0
3299diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
3300index 6ee2f67..d1cce76 100644
3301--- a/arch/arm/lib/copy_page.S
3302+++ b/arch/arm/lib/copy_page.S
3303@@ -10,6 +10,7 @@
3304 * ASM optimised string functions
3305 */
3306 #include <linux/linkage.h>
3307+#include <linux/const.h>
3308 #include <asm/assembler.h>
3309 #include <asm/asm-offsets.h>
3310 #include <asm/cache.h>
3311diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
3312index d066df6..df28194 100644
3313--- a/arch/arm/lib/copy_to_user.S
3314+++ b/arch/arm/lib/copy_to_user.S
3315@@ -16,7 +16,7 @@
3316 /*
3317 * Prototype:
3318 *
3319- * size_t __copy_to_user(void *to, const void *from, size_t n)
3320+ * size_t ___copy_to_user(void *to, const void *from, size_t n)
3321 *
3322 * Purpose:
3323 *
3324@@ -88,11 +88,11 @@
3325 .text
3326
3327 ENTRY(__copy_to_user_std)
3328-WEAK(__copy_to_user)
3329+WEAK(___copy_to_user)
3330
3331 #include "copy_template.S"
3332
3333-ENDPROC(__copy_to_user)
3334+ENDPROC(___copy_to_user)
3335 ENDPROC(__copy_to_user_std)
3336
3337 .pushsection .fixup,"ax"
3338diff --git a/arch/arm/lib/csumpartialcopyuser.S b/arch/arm/lib/csumpartialcopyuser.S
3339index 7d08b43..f7ca7ea 100644
3340--- a/arch/arm/lib/csumpartialcopyuser.S
3341+++ b/arch/arm/lib/csumpartialcopyuser.S
3342@@ -57,8 +57,8 @@
3343 * Returns : r0 = checksum, [[sp, #0], #0] = 0 or -EFAULT
3344 */
3345
3346-#define FN_ENTRY ENTRY(csum_partial_copy_from_user)
3347-#define FN_EXIT ENDPROC(csum_partial_copy_from_user)
3348+#define FN_ENTRY ENTRY(__csum_partial_copy_from_user)
3349+#define FN_EXIT ENDPROC(__csum_partial_copy_from_user)
3350
3351 #include "csumpartialcopygeneric.S"
3352
3353diff --git a/arch/arm/lib/delay.c b/arch/arm/lib/delay.c
3354index 5306de3..aed6d03 100644
3355--- a/arch/arm/lib/delay.c
3356+++ b/arch/arm/lib/delay.c
3357@@ -28,7 +28,7 @@
3358 /*
3359 * Default to the loop-based delay implementation.
3360 */
3361-struct arm_delay_ops arm_delay_ops = {
3362+struct arm_delay_ops arm_delay_ops __read_only = {
3363 .delay = __loop_delay,
3364 .const_udelay = __loop_const_udelay,
3365 .udelay = __loop_udelay,
3366diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
3367index 025f742..a9e5b3b 100644
3368--- a/arch/arm/lib/uaccess_with_memcpy.c
3369+++ b/arch/arm/lib/uaccess_with_memcpy.c
3370@@ -104,7 +104,7 @@ out:
3371 }
3372
3373 unsigned long
3374-__copy_to_user(void __user *to, const void *from, unsigned long n)
3375+___copy_to_user(void __user *to, const void *from, unsigned long n)
3376 {
3377 /*
3378 * This test is stubbed out of the main function above to keep
3379@@ -155,7 +155,7 @@ out:
3380 return n;
3381 }
3382
3383-unsigned long __clear_user(void __user *addr, unsigned long n)
3384+unsigned long ___clear_user(void __user *addr, unsigned long n)
3385 {
3386 /* See rational for this in __copy_to_user() above. */
3387 if (n < 64)
3388diff --git a/arch/arm/mach-kirkwood/common.c b/arch/arm/mach-kirkwood/common.c
3389index 1767611..d2e7e24 100644
3390--- a/arch/arm/mach-kirkwood/common.c
3391+++ b/arch/arm/mach-kirkwood/common.c
3392@@ -156,7 +156,16 @@ static void clk_gate_fn_disable(struct clk_hw *hw)
3393 clk_gate_ops.disable(hw);
3394 }
3395
3396-static struct clk_ops clk_gate_fn_ops;
3397+static int clk_gate_fn_is_enabled(struct clk_hw *hw)
3398+{
3399+ return clk_gate_ops.is_enabled(hw);
3400+}
3401+
3402+static struct clk_ops clk_gate_fn_ops = {
3403+ .enable = clk_gate_fn_enable,
3404+ .disable = clk_gate_fn_disable,
3405+ .is_enabled = clk_gate_fn_is_enabled,
3406+};
3407
3408 static struct clk __init *clk_register_gate_fn(struct device *dev,
3409 const char *name,
3410@@ -190,14 +199,6 @@ static struct clk __init *clk_register_gate_fn(struct device *dev,
3411 gate_fn->fn_en = fn_en;
3412 gate_fn->fn_dis = fn_dis;
3413
3414- /* ops is the gate ops, but with our enable/disable functions */
3415- if (clk_gate_fn_ops.enable != clk_gate_fn_enable ||
3416- clk_gate_fn_ops.disable != clk_gate_fn_disable) {
3417- clk_gate_fn_ops = clk_gate_ops;
3418- clk_gate_fn_ops.enable = clk_gate_fn_enable;
3419- clk_gate_fn_ops.disable = clk_gate_fn_disable;
3420- }
3421-
3422 clk = clk_register(dev, &gate_fn->gate.hw);
3423
3424 if (IS_ERR(clk))
3425diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
3426index 827d1500..2885dc6 100644
3427--- a/arch/arm/mach-omap2/board-n8x0.c
3428+++ b/arch/arm/mach-omap2/board-n8x0.c
3429@@ -627,7 +627,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
3430 }
3431 #endif
3432
3433-static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
3434+static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
3435 .late_init = n8x0_menelaus_late_init,
3436 };
3437
3438diff --git a/arch/arm/mach-omap2/gpmc.c b/arch/arm/mach-omap2/gpmc.c
3439index 579697a..1d5a3b2 100644
3440--- a/arch/arm/mach-omap2/gpmc.c
3441+++ b/arch/arm/mach-omap2/gpmc.c
3442@@ -148,7 +148,6 @@ struct omap3_gpmc_regs {
3443 };
3444
3445 static struct gpmc_client_irq gpmc_client_irq[GPMC_NR_IRQ];
3446-static struct irq_chip gpmc_irq_chip;
3447 static int gpmc_irq_start;
3448
3449 static struct resource gpmc_mem_root;
3450@@ -716,6 +715,18 @@ static void gpmc_irq_noop(struct irq_data *data) { }
3451
3452 static unsigned int gpmc_irq_noop_ret(struct irq_data *data) { return 0; }
3453
3454+static struct irq_chip gpmc_irq_chip = {
3455+ .name = "gpmc",
3456+ .irq_startup = gpmc_irq_noop_ret,
3457+ .irq_enable = gpmc_irq_enable,
3458+ .irq_disable = gpmc_irq_disable,
3459+ .irq_shutdown = gpmc_irq_noop,
3460+ .irq_ack = gpmc_irq_noop,
3461+ .irq_mask = gpmc_irq_noop,
3462+ .irq_unmask = gpmc_irq_noop,
3463+
3464+};
3465+
3466 static int gpmc_setup_irq(void)
3467 {
3468 int i;
3469@@ -730,15 +741,6 @@ static int gpmc_setup_irq(void)
3470 return gpmc_irq_start;
3471 }
3472
3473- gpmc_irq_chip.name = "gpmc";
3474- gpmc_irq_chip.irq_startup = gpmc_irq_noop_ret;
3475- gpmc_irq_chip.irq_enable = gpmc_irq_enable;
3476- gpmc_irq_chip.irq_disable = gpmc_irq_disable;
3477- gpmc_irq_chip.irq_shutdown = gpmc_irq_noop;
3478- gpmc_irq_chip.irq_ack = gpmc_irq_noop;
3479- gpmc_irq_chip.irq_mask = gpmc_irq_noop;
3480- gpmc_irq_chip.irq_unmask = gpmc_irq_noop;
3481-
3482 gpmc_client_irq[0].bitmask = GPMC_IRQ_FIFOEVENTENABLE;
3483 gpmc_client_irq[1].bitmask = GPMC_IRQ_COUNT_EVENT;
3484
3485diff --git a/arch/arm/mach-omap2/omap-mpuss-lowpower.c b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3486index f991016..145ebeb 100644
3487--- a/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3488+++ b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3489@@ -84,7 +84,7 @@ struct cpu_pm_ops {
3490 int (*finish_suspend)(unsigned long cpu_state);
3491 void (*resume)(void);
3492 void (*scu_prepare)(unsigned int cpu_id, unsigned int cpu_state);
3493-};
3494+} __no_const;
3495
3496 static DEFINE_PER_CPU(struct omap4_cpu_pm_info, omap4_pm_info);
3497 static struct powerdomain *mpuss_pd;
3498@@ -102,7 +102,7 @@ static void dummy_cpu_resume(void)
3499 static void dummy_scu_prepare(unsigned int cpu_id, unsigned int cpu_state)
3500 {}
3501
3502-struct cpu_pm_ops omap_pm_ops = {
3503+static struct cpu_pm_ops omap_pm_ops __read_only = {
3504 .finish_suspend = default_finish_suspend,
3505 .resume = dummy_cpu_resume,
3506 .scu_prepare = dummy_scu_prepare,
3507diff --git a/arch/arm/mach-omap2/omap-wakeupgen.c b/arch/arm/mach-omap2/omap-wakeupgen.c
3508index 813c615..ce467c6 100644
3509--- a/arch/arm/mach-omap2/omap-wakeupgen.c
3510+++ b/arch/arm/mach-omap2/omap-wakeupgen.c
3511@@ -339,7 +339,7 @@ static int irq_cpu_hotplug_notify(struct notifier_block *self,
3512 return NOTIFY_OK;
3513 }
3514
3515-static struct notifier_block __refdata irq_hotplug_notifier = {
3516+static struct notifier_block irq_hotplug_notifier = {
3517 .notifier_call = irq_cpu_hotplug_notify,
3518 };
3519
3520diff --git a/arch/arm/mach-omap2/omap_device.c b/arch/arm/mach-omap2/omap_device.c
3521index b69dd9a..70e5409 100644
3522--- a/arch/arm/mach-omap2/omap_device.c
3523+++ b/arch/arm/mach-omap2/omap_device.c
3524@@ -504,7 +504,7 @@ void omap_device_delete(struct omap_device *od)
3525 struct platform_device __init *omap_device_build(const char *pdev_name,
3526 int pdev_id,
3527 struct omap_hwmod *oh,
3528- void *pdata, int pdata_len)
3529+ const void *pdata, int pdata_len)
3530 {
3531 struct omap_hwmod *ohs[] = { oh };
3532
3533@@ -532,7 +532,7 @@ struct platform_device __init *omap_device_build(const char *pdev_name,
3534 struct platform_device __init *omap_device_build_ss(const char *pdev_name,
3535 int pdev_id,
3536 struct omap_hwmod **ohs,
3537- int oh_cnt, void *pdata,
3538+ int oh_cnt, const void *pdata,
3539 int pdata_len)
3540 {
3541 int ret = -ENOMEM;
3542diff --git a/arch/arm/mach-omap2/omap_device.h b/arch/arm/mach-omap2/omap_device.h
3543index 17ca1ae..beba869 100644
3544--- a/arch/arm/mach-omap2/omap_device.h
3545+++ b/arch/arm/mach-omap2/omap_device.h
3546@@ -71,12 +71,12 @@ int omap_device_idle(struct platform_device *pdev);
3547 /* Core code interface */
3548
3549 struct platform_device *omap_device_build(const char *pdev_name, int pdev_id,
3550- struct omap_hwmod *oh, void *pdata,
3551+ struct omap_hwmod *oh, const void *pdata,
3552 int pdata_len);
3553
3554 struct platform_device *omap_device_build_ss(const char *pdev_name, int pdev_id,
3555 struct omap_hwmod **oh, int oh_cnt,
3556- void *pdata, int pdata_len);
3557+ const void *pdata, int pdata_len);
3558
3559 struct omap_device *omap_device_alloc(struct platform_device *pdev,
3560 struct omap_hwmod **ohs, int oh_cnt);
3561diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
3562index d9ee0ff..24f224a 100644
3563--- a/arch/arm/mach-omap2/omap_hwmod.c
3564+++ b/arch/arm/mach-omap2/omap_hwmod.c
3565@@ -194,10 +194,10 @@ struct omap_hwmod_soc_ops {
3566 int (*init_clkdm)(struct omap_hwmod *oh);
3567 void (*update_context_lost)(struct omap_hwmod *oh);
3568 int (*get_context_lost)(struct omap_hwmod *oh);
3569-};
3570+} __no_const;
3571
3572 /* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
3573-static struct omap_hwmod_soc_ops soc_ops;
3574+static struct omap_hwmod_soc_ops soc_ops __read_only;
3575
3576 /* omap_hwmod_list contains all registered struct omap_hwmods */
3577 static LIST_HEAD(omap_hwmod_list);
3578diff --git a/arch/arm/mach-omap2/wd_timer.c b/arch/arm/mach-omap2/wd_timer.c
3579index d15c7bb..b2d1f0c 100644
3580--- a/arch/arm/mach-omap2/wd_timer.c
3581+++ b/arch/arm/mach-omap2/wd_timer.c
3582@@ -110,7 +110,9 @@ static int __init omap_init_wdt(void)
3583 struct omap_hwmod *oh;
3584 char *oh_name = "wd_timer2";
3585 char *dev_name = "omap_wdt";
3586- struct omap_wd_timer_platform_data pdata;
3587+ static struct omap_wd_timer_platform_data pdata = {
3588+ .read_reset_sources = prm_read_reset_sources
3589+ };
3590
3591 if (!cpu_class_is_omap2() || of_have_populated_dt())
3592 return 0;
3593@@ -121,8 +123,6 @@ static int __init omap_init_wdt(void)
3594 return -EINVAL;
3595 }
3596
3597- pdata.read_reset_sources = prm_read_reset_sources;
3598-
3599 pdev = omap_device_build(dev_name, id, oh, &pdata,
3600 sizeof(struct omap_wd_timer_platform_data));
3601 WARN(IS_ERR(pdev), "Can't build omap_device for %s:%s.\n",
3602diff --git a/arch/arm/mach-tegra/cpuidle-tegra20.c b/arch/arm/mach-tegra/cpuidle-tegra20.c
3603index b82dcae..44ee5b6 100644
3604--- a/arch/arm/mach-tegra/cpuidle-tegra20.c
3605+++ b/arch/arm/mach-tegra/cpuidle-tegra20.c
3606@@ -180,7 +180,7 @@ static int tegra20_idle_lp2_coupled(struct cpuidle_device *dev,
3607 bool entered_lp2 = false;
3608
3609 if (tegra_pending_sgi())
3610- ACCESS_ONCE(abort_flag) = true;
3611+ ACCESS_ONCE_RW(abort_flag) = true;
3612
3613 cpuidle_coupled_parallel_barrier(dev, &abort_barrier);
3614
3615diff --git a/arch/arm/mach-ux500/setup.h b/arch/arm/mach-ux500/setup.h
3616index 656324a..0beba28 100644
3617--- a/arch/arm/mach-ux500/setup.h
3618+++ b/arch/arm/mach-ux500/setup.h
3619@@ -40,13 +40,6 @@ extern void ux500_timer_init(void);
3620 .type = MT_DEVICE, \
3621 }
3622
3623-#define __MEM_DEV_DESC(x, sz) { \
3624- .virtual = IO_ADDRESS(x), \
3625- .pfn = __phys_to_pfn(x), \
3626- .length = sz, \
3627- .type = MT_MEMORY, \
3628-}
3629-
3630 extern struct smp_operations ux500_smp_ops;
3631 extern void ux500_cpu_die(unsigned int cpu);
3632
3633diff --git a/arch/arm/mm/Kconfig b/arch/arm/mm/Kconfig
3634index cd2c88e..4dd9b67 100644
3635--- a/arch/arm/mm/Kconfig
3636+++ b/arch/arm/mm/Kconfig
3637@@ -446,7 +446,7 @@ config CPU_32v5
3638
3639 config CPU_32v6
3640 bool
3641- select CPU_USE_DOMAINS if CPU_V6 && MMU
3642+ select CPU_USE_DOMAINS if CPU_V6 && MMU && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3643 select TLS_REG_EMUL if !CPU_32v6K && !MMU
3644
3645 config CPU_32v6K
3646@@ -601,6 +601,7 @@ config CPU_CP15_MPU
3647
3648 config CPU_USE_DOMAINS
3649 bool
3650+ depends on !ARM_LPAE && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3651 help
3652 This option enables or disables the use of domain switching
3653 via the set_fs() function.
3654@@ -800,6 +801,7 @@ config NEED_KUSER_HELPERS
3655 config KUSER_HELPERS
3656 bool "Enable kuser helpers in vector page" if !NEED_KUSER_HELPERS
3657 default y
3658+ depends on !(CPU_V6 || CPU_V6K || CPU_V7) || GRKERNSEC_OLD_ARM_USERLAND
3659 help
3660 Warning: disabling this option may break user programs.
3661
3662@@ -812,7 +814,7 @@ config KUSER_HELPERS
3663 See Documentation/arm/kernel_user_helpers.txt for details.
3664
3665 However, the fixed address nature of these helpers can be used
3666- by ROP (return orientated programming) authors when creating
3667+ by ROP (Return Oriented Programming) authors when creating
3668 exploits.
3669
3670 If all of the binaries and libraries which run on your platform
3671diff --git a/arch/arm/mm/alignment.c b/arch/arm/mm/alignment.c
3672index 6f4585b..7b6f52b 100644
3673--- a/arch/arm/mm/alignment.c
3674+++ b/arch/arm/mm/alignment.c
3675@@ -211,10 +211,12 @@ union offset_union {
3676 #define __get16_unaligned_check(ins,val,addr) \
3677 do { \
3678 unsigned int err = 0, v, a = addr; \
3679+ pax_open_userland(); \
3680 __get8_unaligned_check(ins,v,a,err); \
3681 val = v << ((BE) ? 8 : 0); \
3682 __get8_unaligned_check(ins,v,a,err); \
3683 val |= v << ((BE) ? 0 : 8); \
3684+ pax_close_userland(); \
3685 if (err) \
3686 goto fault; \
3687 } while (0)
3688@@ -228,6 +230,7 @@ union offset_union {
3689 #define __get32_unaligned_check(ins,val,addr) \
3690 do { \
3691 unsigned int err = 0, v, a = addr; \
3692+ pax_open_userland(); \
3693 __get8_unaligned_check(ins,v,a,err); \
3694 val = v << ((BE) ? 24 : 0); \
3695 __get8_unaligned_check(ins,v,a,err); \
3696@@ -236,6 +239,7 @@ union offset_union {
3697 val |= v << ((BE) ? 8 : 16); \
3698 __get8_unaligned_check(ins,v,a,err); \
3699 val |= v << ((BE) ? 0 : 24); \
3700+ pax_close_userland(); \
3701 if (err) \
3702 goto fault; \
3703 } while (0)
3704@@ -249,6 +253,7 @@ union offset_union {
3705 #define __put16_unaligned_check(ins,val,addr) \
3706 do { \
3707 unsigned int err = 0, v = val, a = addr; \
3708+ pax_open_userland(); \
3709 __asm__( FIRST_BYTE_16 \
3710 ARM( "1: "ins" %1, [%2], #1\n" ) \
3711 THUMB( "1: "ins" %1, [%2]\n" ) \
3712@@ -268,6 +273,7 @@ union offset_union {
3713 " .popsection\n" \
3714 : "=r" (err), "=&r" (v), "=&r" (a) \
3715 : "0" (err), "1" (v), "2" (a)); \
3716+ pax_close_userland(); \
3717 if (err) \
3718 goto fault; \
3719 } while (0)
3720@@ -281,6 +287,7 @@ union offset_union {
3721 #define __put32_unaligned_check(ins,val,addr) \
3722 do { \
3723 unsigned int err = 0, v = val, a = addr; \
3724+ pax_open_userland(); \
3725 __asm__( FIRST_BYTE_32 \
3726 ARM( "1: "ins" %1, [%2], #1\n" ) \
3727 THUMB( "1: "ins" %1, [%2]\n" ) \
3728@@ -310,6 +317,7 @@ union offset_union {
3729 " .popsection\n" \
3730 : "=r" (err), "=&r" (v), "=&r" (a) \
3731 : "0" (err), "1" (v), "2" (a)); \
3732+ pax_close_userland(); \
3733 if (err) \
3734 goto fault; \
3735 } while (0)
3736diff --git a/arch/arm/mm/context.c b/arch/arm/mm/context.c
3737index 84e6f77..0b52f31 100644
3738--- a/arch/arm/mm/context.c
3739+++ b/arch/arm/mm/context.c
3740@@ -43,7 +43,7 @@
3741 #define NUM_USER_ASIDS ASID_FIRST_VERSION
3742
3743 static DEFINE_RAW_SPINLOCK(cpu_asid_lock);
3744-static atomic64_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
3745+static atomic64_unchecked_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
3746 static DECLARE_BITMAP(asid_map, NUM_USER_ASIDS);
3747
3748 static DEFINE_PER_CPU(atomic64_t, active_asids);
3749@@ -180,7 +180,7 @@ static int is_reserved_asid(u64 asid)
3750 static u64 new_context(struct mm_struct *mm, unsigned int cpu)
3751 {
3752 u64 asid = atomic64_read(&mm->context.id);
3753- u64 generation = atomic64_read(&asid_generation);
3754+ u64 generation = atomic64_read_unchecked(&asid_generation);
3755
3756 if (asid != 0 && is_reserved_asid(asid)) {
3757 /*
3758@@ -198,7 +198,7 @@ static u64 new_context(struct mm_struct *mm, unsigned int cpu)
3759 */
3760 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, 1);
3761 if (asid == NUM_USER_ASIDS) {
3762- generation = atomic64_add_return(ASID_FIRST_VERSION,
3763+ generation = atomic64_add_return_unchecked(ASID_FIRST_VERSION,
3764 &asid_generation);
3765 flush_context(cpu);
3766 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, 1);
3767@@ -227,14 +227,14 @@ void check_and_switch_context(struct mm_struct *mm, struct task_struct *tsk)
3768 cpu_set_reserved_ttbr0();
3769
3770 asid = atomic64_read(&mm->context.id);
3771- if (!((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS)
3772+ if (!((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS)
3773 && atomic64_xchg(&per_cpu(active_asids, cpu), asid))
3774 goto switch_mm_fastpath;
3775
3776 raw_spin_lock_irqsave(&cpu_asid_lock, flags);
3777 /* Check that our ASID belongs to the current generation. */
3778 asid = atomic64_read(&mm->context.id);
3779- if ((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS) {
3780+ if ((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS) {
3781 asid = new_context(mm, cpu);
3782 atomic64_set(&mm->context.id, asid);
3783 }
3784diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
3785index eb8830a..5360ce7 100644
3786--- a/arch/arm/mm/fault.c
3787+++ b/arch/arm/mm/fault.c
3788@@ -25,6 +25,7 @@
3789 #include <asm/system_misc.h>
3790 #include <asm/system_info.h>
3791 #include <asm/tlbflush.h>
3792+#include <asm/sections.h>
3793
3794 #include "fault.h"
3795
3796@@ -138,6 +139,31 @@ __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
3797 if (fixup_exception(regs))
3798 return;
3799
3800+#ifdef CONFIG_PAX_MEMORY_UDEREF
3801+ if (addr < TASK_SIZE) {
3802+ if (current->signal->curr_ip)
3803+ 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),
3804+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3805+ else
3806+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
3807+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3808+ }
3809+#endif
3810+
3811+#ifdef CONFIG_PAX_KERNEXEC
3812+ if ((fsr & FSR_WRITE) &&
3813+ (((unsigned long)_stext <= addr && addr < init_mm.end_code) ||
3814+ (MODULES_VADDR <= addr && addr < MODULES_END)))
3815+ {
3816+ if (current->signal->curr_ip)
3817+ 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),
3818+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3819+ else
3820+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
3821+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3822+ }
3823+#endif
3824+
3825 /*
3826 * No handler, we'll have to terminate things with extreme prejudice.
3827 */
3828@@ -174,6 +200,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
3829 }
3830 #endif
3831
3832+#ifdef CONFIG_PAX_PAGEEXEC
3833+ if (fsr & FSR_LNX_PF) {
3834+ pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
3835+ do_group_exit(SIGKILL);
3836+ }
3837+#endif
3838+
3839 tsk->thread.address = addr;
3840 tsk->thread.error_code = fsr;
3841 tsk->thread.trap_no = 14;
3842@@ -401,6 +434,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3843 }
3844 #endif /* CONFIG_MMU */
3845
3846+#ifdef CONFIG_PAX_PAGEEXEC
3847+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3848+{
3849+ long i;
3850+
3851+ printk(KERN_ERR "PAX: bytes at PC: ");
3852+ for (i = 0; i < 20; i++) {
3853+ unsigned char c;
3854+ if (get_user(c, (__force unsigned char __user *)pc+i))
3855+ printk(KERN_CONT "?? ");
3856+ else
3857+ printk(KERN_CONT "%02x ", c);
3858+ }
3859+ printk("\n");
3860+
3861+ printk(KERN_ERR "PAX: bytes at SP-4: ");
3862+ for (i = -1; i < 20; i++) {
3863+ unsigned long c;
3864+ if (get_user(c, (__force unsigned long __user *)sp+i))
3865+ printk(KERN_CONT "???????? ");
3866+ else
3867+ printk(KERN_CONT "%08lx ", c);
3868+ }
3869+ printk("\n");
3870+}
3871+#endif
3872+
3873 /*
3874 * First Level Translation Fault Handler
3875 *
3876@@ -548,9 +608,22 @@ do_DataAbort(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3877 const struct fsr_info *inf = fsr_info + fsr_fs(fsr);
3878 struct siginfo info;
3879
3880+#ifdef CONFIG_PAX_MEMORY_UDEREF
3881+ if (addr < TASK_SIZE && is_domain_fault(fsr)) {
3882+ if (current->signal->curr_ip)
3883+ 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),
3884+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3885+ else
3886+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
3887+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3888+ goto die;
3889+ }
3890+#endif
3891+
3892 if (!inf->fn(addr, fsr & ~FSR_LNX_PF, regs))
3893 return;
3894
3895+die:
3896 printk(KERN_ALERT "Unhandled fault: %s (0x%03x) at 0x%08lx\n",
3897 inf->name, fsr, addr);
3898
3899@@ -574,15 +647,98 @@ hook_ifault_code(int nr, int (*fn)(unsigned long, unsigned int, struct pt_regs *
3900 ifsr_info[nr].name = name;
3901 }
3902
3903+asmlinkage int sys_sigreturn(struct pt_regs *regs);
3904+asmlinkage int sys_rt_sigreturn(struct pt_regs *regs);
3905+
3906 asmlinkage void __exception
3907 do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
3908 {
3909 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
3910 struct siginfo info;
3911+ unsigned long pc = instruction_pointer(regs);
3912+
3913+ if (user_mode(regs)) {
3914+ unsigned long sigpage = current->mm->context.sigpage;
3915+
3916+ if (sigpage <= pc && pc < sigpage + 7*4) {
3917+ if (pc < sigpage + 3*4)
3918+ sys_sigreturn(regs);
3919+ else
3920+ sys_rt_sigreturn(regs);
3921+ return;
3922+ }
3923+ if (pc == 0xffff0f60UL) {
3924+ /*
3925+ * PaX: __kuser_cmpxchg64 emulation
3926+ */
3927+ // TODO
3928+ //regs->ARM_pc = regs->ARM_lr;
3929+ //return;
3930+ }
3931+ if (pc == 0xffff0fa0UL) {
3932+ /*
3933+ * PaX: __kuser_memory_barrier emulation
3934+ */
3935+ // dmb(); implied by the exception
3936+ regs->ARM_pc = regs->ARM_lr;
3937+ return;
3938+ }
3939+ if (pc == 0xffff0fc0UL) {
3940+ /*
3941+ * PaX: __kuser_cmpxchg emulation
3942+ */
3943+ // TODO
3944+ //long new;
3945+ //int op;
3946+
3947+ //op = FUTEX_OP_SET << 28;
3948+ //new = futex_atomic_op_inuser(op, regs->ARM_r2);
3949+ //regs->ARM_r0 = old != new;
3950+ //regs->ARM_pc = regs->ARM_lr;
3951+ //return;
3952+ }
3953+ if (pc == 0xffff0fe0UL) {
3954+ /*
3955+ * PaX: __kuser_get_tls emulation
3956+ */
3957+ regs->ARM_r0 = current_thread_info()->tp_value[0];
3958+ regs->ARM_pc = regs->ARM_lr;
3959+ return;
3960+ }
3961+ }
3962+
3963+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
3964+ else if (is_domain_fault(ifsr) || is_xn_fault(ifsr)) {
3965+ if (current->signal->curr_ip)
3966+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", &current->signal->curr_ip, current->comm, task_pid_nr(current),
3967+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
3968+ pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
3969+ else
3970+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", current->comm, task_pid_nr(current),
3971+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
3972+ pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
3973+ goto die;
3974+ }
3975+#endif
3976+
3977+#ifdef CONFIG_PAX_REFCOUNT
3978+ if (fsr_fs(ifsr) == FAULT_CODE_DEBUG) {
3979+ unsigned int bkpt;
3980+
3981+ if (!probe_kernel_address(pc, bkpt) && cpu_to_le32(bkpt) == 0xe12f1073) {
3982+ current->thread.error_code = ifsr;
3983+ current->thread.trap_no = 0;
3984+ pax_report_refcount_overflow(regs);
3985+ fixup_exception(regs);
3986+ return;
3987+ }
3988+ }
3989+#endif
3990
3991 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
3992 return;
3993
3994+die:
3995 printk(KERN_ALERT "Unhandled prefetch abort: %s (0x%03x) at 0x%08lx\n",
3996 inf->name, ifsr, addr);
3997
3998diff --git a/arch/arm/mm/fault.h b/arch/arm/mm/fault.h
3999index cf08bdf..772656c 100644
4000--- a/arch/arm/mm/fault.h
4001+++ b/arch/arm/mm/fault.h
4002@@ -3,6 +3,7 @@
4003
4004 /*
4005 * Fault status register encodings. We steal bit 31 for our own purposes.
4006+ * Set when the FSR value is from an instruction fault.
4007 */
4008 #define FSR_LNX_PF (1 << 31)
4009 #define FSR_WRITE (1 << 11)
4010@@ -22,6 +23,17 @@ static inline int fsr_fs(unsigned int fsr)
4011 }
4012 #endif
4013
4014+/* valid for LPAE and !LPAE */
4015+static inline int is_xn_fault(unsigned int fsr)
4016+{
4017+ return ((fsr_fs(fsr) & 0x3c) == 0xc);
4018+}
4019+
4020+static inline int is_domain_fault(unsigned int fsr)
4021+{
4022+ return ((fsr_fs(fsr) & 0xD) == 0x9);
4023+}
4024+
4025 void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs);
4026 unsigned long search_exception_table(unsigned long addr);
4027
4028diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
4029index 18ec4c5..479bb6a 100644
4030--- a/arch/arm/mm/init.c
4031+++ b/arch/arm/mm/init.c
4032@@ -30,6 +30,8 @@
4033 #include <asm/setup.h>
4034 #include <asm/tlb.h>
4035 #include <asm/fixmap.h>
4036+#include <asm/system_info.h>
4037+#include <asm/cp15.h>
4038
4039 #include <asm/mach/arch.h>
4040 #include <asm/mach/map.h>
4041@@ -684,7 +686,46 @@ void free_initmem(void)
4042 {
4043 #ifdef CONFIG_HAVE_TCM
4044 extern char __tcm_start, __tcm_end;
4045+#endif
4046
4047+#ifdef CONFIG_PAX_KERNEXEC
4048+ unsigned long addr;
4049+ pgd_t *pgd;
4050+ pud_t *pud;
4051+ pmd_t *pmd;
4052+ int cpu_arch = cpu_architecture();
4053+ unsigned int cr = get_cr();
4054+
4055+ if (cpu_arch >= CPU_ARCH_ARMv6 && (cr & CR_XP)) {
4056+ /* make pages tables, etc before .text NX */
4057+ for (addr = PAGE_OFFSET; addr < (unsigned long)_stext; addr += SECTION_SIZE) {
4058+ pgd = pgd_offset_k(addr);
4059+ pud = pud_offset(pgd, addr);
4060+ pmd = pmd_offset(pud, addr);
4061+ __section_update(pmd, addr, PMD_SECT_XN);
4062+ }
4063+ /* make init NX */
4064+ for (addr = (unsigned long)__init_begin; addr < (unsigned long)_sdata; addr += SECTION_SIZE) {
4065+ pgd = pgd_offset_k(addr);
4066+ pud = pud_offset(pgd, addr);
4067+ pmd = pmd_offset(pud, addr);
4068+ __section_update(pmd, addr, PMD_SECT_XN);
4069+ }
4070+ /* make kernel code/rodata RX */
4071+ for (addr = (unsigned long)_stext; addr < (unsigned long)__init_begin; addr += SECTION_SIZE) {
4072+ pgd = pgd_offset_k(addr);
4073+ pud = pud_offset(pgd, addr);
4074+ pmd = pmd_offset(pud, addr);
4075+#ifdef CONFIG_ARM_LPAE
4076+ __section_update(pmd, addr, PMD_SECT_RDONLY);
4077+#else
4078+ __section_update(pmd, addr, PMD_SECT_APX|PMD_SECT_AP_WRITE);
4079+#endif
4080+ }
4081+ }
4082+#endif
4083+
4084+#ifdef CONFIG_HAVE_TCM
4085 poison_init_mem(&__tcm_start, &__tcm_end - &__tcm_start);
4086 free_reserved_area(&__tcm_start, &__tcm_end, -1, "TCM link");
4087 #endif
4088diff --git a/arch/arm/mm/ioremap.c b/arch/arm/mm/ioremap.c
4089index f123d6e..04bf569 100644
4090--- a/arch/arm/mm/ioremap.c
4091+++ b/arch/arm/mm/ioremap.c
4092@@ -392,9 +392,9 @@ __arm_ioremap_exec(phys_addr_t phys_addr, size_t size, bool cached)
4093 unsigned int mtype;
4094
4095 if (cached)
4096- mtype = MT_MEMORY;
4097+ mtype = MT_MEMORY_RX;
4098 else
4099- mtype = MT_MEMORY_NONCACHED;
4100+ mtype = MT_MEMORY_NONCACHED_RX;
4101
4102 return __arm_ioremap_caller(phys_addr, size, mtype,
4103 __builtin_return_address(0));
4104diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
4105index 0c63562..7128a90 100644
4106--- a/arch/arm/mm/mmap.c
4107+++ b/arch/arm/mm/mmap.c
4108@@ -59,6 +59,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4109 struct vm_area_struct *vma;
4110 int do_align = 0;
4111 int aliasing = cache_is_vipt_aliasing();
4112+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4113 struct vm_unmapped_area_info info;
4114
4115 /*
4116@@ -81,6 +82,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4117 if (len > TASK_SIZE)
4118 return -ENOMEM;
4119
4120+#ifdef CONFIG_PAX_RANDMMAP
4121+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4122+#endif
4123+
4124 if (addr) {
4125 if (do_align)
4126 addr = COLOUR_ALIGN(addr, pgoff);
4127@@ -88,8 +93,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4128 addr = PAGE_ALIGN(addr);
4129
4130 vma = find_vma(mm, addr);
4131- if (TASK_SIZE - len >= addr &&
4132- (!vma || addr + len <= vma->vm_start))
4133+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4134 return addr;
4135 }
4136
4137@@ -99,6 +103,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4138 info.high_limit = TASK_SIZE;
4139 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4140 info.align_offset = pgoff << PAGE_SHIFT;
4141+ info.threadstack_offset = offset;
4142 return vm_unmapped_area(&info);
4143 }
4144
4145@@ -112,6 +117,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4146 unsigned long addr = addr0;
4147 int do_align = 0;
4148 int aliasing = cache_is_vipt_aliasing();
4149+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4150 struct vm_unmapped_area_info info;
4151
4152 /*
4153@@ -132,6 +138,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4154 return addr;
4155 }
4156
4157+#ifdef CONFIG_PAX_RANDMMAP
4158+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4159+#endif
4160+
4161 /* requesting a specific address */
4162 if (addr) {
4163 if (do_align)
4164@@ -139,8 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4165 else
4166 addr = PAGE_ALIGN(addr);
4167 vma = find_vma(mm, addr);
4168- if (TASK_SIZE - len >= addr &&
4169- (!vma || addr + len <= vma->vm_start))
4170+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4171 return addr;
4172 }
4173
4174@@ -150,6 +159,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4175 info.high_limit = mm->mmap_base;
4176 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4177 info.align_offset = pgoff << PAGE_SHIFT;
4178+ info.threadstack_offset = offset;
4179 addr = vm_unmapped_area(&info);
4180
4181 /*
4182@@ -173,6 +183,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4183 {
4184 unsigned long random_factor = 0UL;
4185
4186+#ifdef CONFIG_PAX_RANDMMAP
4187+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4188+#endif
4189+
4190 /* 8 bits of randomness in 20 address space bits */
4191 if ((current->flags & PF_RANDOMIZE) &&
4192 !(current->personality & ADDR_NO_RANDOMIZE))
4193@@ -180,9 +194,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4194
4195 if (mmap_is_legacy()) {
4196 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
4197+
4198+#ifdef CONFIG_PAX_RANDMMAP
4199+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4200+ mm->mmap_base += mm->delta_mmap;
4201+#endif
4202+
4203 mm->get_unmapped_area = arch_get_unmapped_area;
4204 } else {
4205 mm->mmap_base = mmap_base(random_factor);
4206+
4207+#ifdef CONFIG_PAX_RANDMMAP
4208+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4209+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4210+#endif
4211+
4212 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4213 }
4214 }
4215diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
4216index b1d17ee..7a6f4d3 100644
4217--- a/arch/arm/mm/mmu.c
4218+++ b/arch/arm/mm/mmu.c
4219@@ -36,6 +36,22 @@
4220 #include "mm.h"
4221 #include "tcm.h"
4222
4223+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4224+void modify_domain(unsigned int dom, unsigned int type)
4225+{
4226+ struct thread_info *thread = current_thread_info();
4227+ unsigned int domain = thread->cpu_domain;
4228+ /*
4229+ * DOMAIN_MANAGER might be defined to some other value,
4230+ * use the arch-defined constant
4231+ */
4232+ domain &= ~domain_val(dom, 3);
4233+ thread->cpu_domain = domain | domain_val(dom, type);
4234+ set_domain(thread->cpu_domain);
4235+}
4236+EXPORT_SYMBOL(modify_domain);
4237+#endif
4238+
4239 /*
4240 * empty_zero_page is a special page that is used for
4241 * zero-initialized data and COW.
4242@@ -228,10 +244,18 @@ __setup("noalign", noalign_setup);
4243
4244 #endif /* ifdef CONFIG_CPU_CP15 / else */
4245
4246-#define PROT_PTE_DEVICE L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY|L_PTE_XN
4247+#define PROT_PTE_DEVICE L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY
4248 #define PROT_SECT_DEVICE PMD_TYPE_SECT|PMD_SECT_AP_WRITE
4249
4250-static struct mem_type mem_types[] = {
4251+#ifdef CONFIG_PAX_KERNEXEC
4252+#define L_PTE_KERNEXEC L_PTE_RDONLY
4253+#define PMD_SECT_KERNEXEC PMD_SECT_RDONLY
4254+#else
4255+#define L_PTE_KERNEXEC L_PTE_DIRTY
4256+#define PMD_SECT_KERNEXEC PMD_SECT_AP_WRITE
4257+#endif
4258+
4259+static struct mem_type mem_types[] __read_only = {
4260 [MT_DEVICE] = { /* Strongly ordered / ARMv6 shared device */
4261 .prot_pte = PROT_PTE_DEVICE | L_PTE_MT_DEV_SHARED |
4262 L_PTE_SHARED,
4263@@ -260,16 +284,16 @@ static struct mem_type mem_types[] = {
4264 [MT_UNCACHED] = {
4265 .prot_pte = PROT_PTE_DEVICE,
4266 .prot_l1 = PMD_TYPE_TABLE,
4267- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4268+ .prot_sect = PROT_SECT_DEVICE,
4269 .domain = DOMAIN_IO,
4270 },
4271 [MT_CACHECLEAN] = {
4272- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4273+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4274 .domain = DOMAIN_KERNEL,
4275 },
4276 #ifndef CONFIG_ARM_LPAE
4277 [MT_MINICLEAN] = {
4278- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE,
4279+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_MINICACHE | PMD_SECT_RDONLY,
4280 .domain = DOMAIN_KERNEL,
4281 },
4282 #endif
4283@@ -277,36 +301,54 @@ static struct mem_type mem_types[] = {
4284 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4285 L_PTE_RDONLY,
4286 .prot_l1 = PMD_TYPE_TABLE,
4287- .domain = DOMAIN_USER,
4288+ .domain = DOMAIN_VECTORS,
4289 },
4290 [MT_HIGH_VECTORS] = {
4291 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4292 L_PTE_USER | L_PTE_RDONLY,
4293 .prot_l1 = PMD_TYPE_TABLE,
4294- .domain = DOMAIN_USER,
4295+ .domain = DOMAIN_VECTORS,
4296 },
4297- [MT_MEMORY] = {
4298+ [MT_MEMORY_RWX] = {
4299 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4300 .prot_l1 = PMD_TYPE_TABLE,
4301 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4302 .domain = DOMAIN_KERNEL,
4303 },
4304+ [MT_MEMORY_RW] = {
4305+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4306+ .prot_l1 = PMD_TYPE_TABLE,
4307+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4308+ .domain = DOMAIN_KERNEL,
4309+ },
4310+ [MT_MEMORY_RX] = {
4311+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4312+ .prot_l1 = PMD_TYPE_TABLE,
4313+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4314+ .domain = DOMAIN_KERNEL,
4315+ },
4316 [MT_ROM] = {
4317- .prot_sect = PMD_TYPE_SECT,
4318+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4319 .domain = DOMAIN_KERNEL,
4320 },
4321- [MT_MEMORY_NONCACHED] = {
4322+ [MT_MEMORY_NONCACHED_RW] = {
4323 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4324 L_PTE_MT_BUFFERABLE,
4325 .prot_l1 = PMD_TYPE_TABLE,
4326 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4327 .domain = DOMAIN_KERNEL,
4328 },
4329+ [MT_MEMORY_NONCACHED_RX] = {
4330+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC |
4331+ L_PTE_MT_BUFFERABLE,
4332+ .prot_l1 = PMD_TYPE_TABLE,
4333+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4334+ .domain = DOMAIN_KERNEL,
4335+ },
4336 [MT_MEMORY_DTCM] = {
4337- .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4338- L_PTE_XN,
4339+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4340 .prot_l1 = PMD_TYPE_TABLE,
4341- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4342+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4343 .domain = DOMAIN_KERNEL,
4344 },
4345 [MT_MEMORY_ITCM] = {
4346@@ -316,10 +358,10 @@ static struct mem_type mem_types[] = {
4347 },
4348 [MT_MEMORY_SO] = {
4349 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4350- L_PTE_MT_UNCACHED | L_PTE_XN,
4351+ L_PTE_MT_UNCACHED,
4352 .prot_l1 = PMD_TYPE_TABLE,
4353 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE | PMD_SECT_S |
4354- PMD_SECT_UNCACHED | PMD_SECT_XN,
4355+ PMD_SECT_UNCACHED,
4356 .domain = DOMAIN_KERNEL,
4357 },
4358 [MT_MEMORY_DMA_READY] = {
4359@@ -405,9 +447,35 @@ static void __init build_mem_type_table(void)
4360 * to prevent speculative instruction fetches.
4361 */
4362 mem_types[MT_DEVICE].prot_sect |= PMD_SECT_XN;
4363+ mem_types[MT_DEVICE].prot_pte |= L_PTE_XN;
4364 mem_types[MT_DEVICE_NONSHARED].prot_sect |= PMD_SECT_XN;
4365+ mem_types[MT_DEVICE_NONSHARED].prot_pte |= L_PTE_XN;
4366 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_XN;
4367+ mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_XN;
4368 mem_types[MT_DEVICE_WC].prot_sect |= PMD_SECT_XN;
4369+ mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_XN;
4370+
4371+ /* Mark other regions on ARMv6+ as execute-never */
4372+
4373+#ifdef CONFIG_PAX_KERNEXEC
4374+ mem_types[MT_UNCACHED].prot_sect |= PMD_SECT_XN;
4375+ mem_types[MT_UNCACHED].prot_pte |= L_PTE_XN;
4376+ mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_XN;
4377+ mem_types[MT_CACHECLEAN].prot_pte |= L_PTE_XN;
4378+#ifndef CONFIG_ARM_LPAE
4379+ mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_XN;
4380+ mem_types[MT_MINICLEAN].prot_pte |= L_PTE_XN;
4381+#endif
4382+ mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_XN;
4383+ mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_XN;
4384+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_XN;
4385+ mem_types[MT_MEMORY_NONCACHED_RW].prot_pte |= PMD_SECT_XN;
4386+ mem_types[MT_MEMORY_DTCM].prot_sect |= PMD_SECT_XN;
4387+ mem_types[MT_MEMORY_DTCM].prot_pte |= L_PTE_XN;
4388+#endif
4389+
4390+ mem_types[MT_MEMORY_SO].prot_sect |= PMD_SECT_XN;
4391+ mem_types[MT_MEMORY_SO].prot_pte |= L_PTE_XN;
4392 }
4393 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4394 /*
4395@@ -468,6 +536,9 @@ static void __init build_mem_type_table(void)
4396 * from SVC mode and no access from userspace.
4397 */
4398 mem_types[MT_ROM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4399+#ifdef CONFIG_PAX_KERNEXEC
4400+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4401+#endif
4402 mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4403 mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4404 #endif
4405@@ -485,11 +556,17 @@ static void __init build_mem_type_table(void)
4406 mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_SHARED;
4407 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_S;
4408 mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_SHARED;
4409- mem_types[MT_MEMORY].prot_sect |= PMD_SECT_S;
4410- mem_types[MT_MEMORY].prot_pte |= L_PTE_SHARED;
4411+ mem_types[MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
4412+ mem_types[MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
4413+ mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_S;
4414+ mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_SHARED;
4415+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_S;
4416+ mem_types[MT_MEMORY_RX].prot_pte |= L_PTE_SHARED;
4417 mem_types[MT_MEMORY_DMA_READY].prot_pte |= L_PTE_SHARED;
4418- mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_S;
4419- mem_types[MT_MEMORY_NONCACHED].prot_pte |= L_PTE_SHARED;
4420+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_S;
4421+ mem_types[MT_MEMORY_NONCACHED_RW].prot_pte |= L_PTE_SHARED;
4422+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= PMD_SECT_S;
4423+ mem_types[MT_MEMORY_NONCACHED_RX].prot_pte |= L_PTE_SHARED;
4424 }
4425 }
4426
4427@@ -500,15 +577,20 @@ static void __init build_mem_type_table(void)
4428 if (cpu_arch >= CPU_ARCH_ARMv6) {
4429 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4430 /* Non-cacheable Normal is XCB = 001 */
4431- mem_types[MT_MEMORY_NONCACHED].prot_sect |=
4432+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |=
4433+ PMD_SECT_BUFFERED;
4434+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |=
4435 PMD_SECT_BUFFERED;
4436 } else {
4437 /* For both ARMv6 and non-TEX-remapping ARMv7 */
4438- mem_types[MT_MEMORY_NONCACHED].prot_sect |=
4439+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |=
4440+ PMD_SECT_TEX(1);
4441+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |=
4442 PMD_SECT_TEX(1);
4443 }
4444 } else {
4445- mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4446+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_BUFFERABLE;
4447+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= PMD_SECT_BUFFERABLE;
4448 }
4449
4450 #ifdef CONFIG_ARM_LPAE
4451@@ -524,6 +606,8 @@ static void __init build_mem_type_table(void)
4452 vecs_pgprot |= PTE_EXT_AF;
4453 #endif
4454
4455+ user_pgprot |= __supported_pte_mask;
4456+
4457 for (i = 0; i < 16; i++) {
4458 pteval_t v = pgprot_val(protection_map[i]);
4459 protection_map[i] = __pgprot(v | user_pgprot);
4460@@ -541,10 +625,15 @@ static void __init build_mem_type_table(void)
4461
4462 mem_types[MT_LOW_VECTORS].prot_l1 |= ecc_mask;
4463 mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
4464- mem_types[MT_MEMORY].prot_sect |= ecc_mask | cp->pmd;
4465- mem_types[MT_MEMORY].prot_pte |= kern_pgprot;
4466+ mem_types[MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
4467+ mem_types[MT_MEMORY_RWX].prot_pte |= kern_pgprot;
4468+ mem_types[MT_MEMORY_RW].prot_sect |= ecc_mask | cp->pmd;
4469+ mem_types[MT_MEMORY_RW].prot_pte |= kern_pgprot;
4470+ mem_types[MT_MEMORY_RX].prot_sect |= ecc_mask | cp->pmd;
4471+ mem_types[MT_MEMORY_RX].prot_pte |= kern_pgprot;
4472 mem_types[MT_MEMORY_DMA_READY].prot_pte |= kern_pgprot;
4473- mem_types[MT_MEMORY_NONCACHED].prot_sect |= ecc_mask;
4474+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= ecc_mask;
4475+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= ecc_mask;
4476 mem_types[MT_ROM].prot_sect |= cp->pmd;
4477
4478 switch (cp->pmd) {
4479@@ -1186,18 +1275,15 @@ void __init arm_mm_memblock_reserve(void)
4480 * called function. This means you can't use any function or debugging
4481 * method which may touch any device, otherwise the kernel _will_ crash.
4482 */
4483+
4484+static char vectors[PAGE_SIZE * 2] __read_only __aligned(PAGE_SIZE);
4485+
4486 static void __init devicemaps_init(const struct machine_desc *mdesc)
4487 {
4488 struct map_desc map;
4489 unsigned long addr;
4490- void *vectors;
4491
4492- /*
4493- * Allocate the vector page early.
4494- */
4495- vectors = early_alloc(PAGE_SIZE * 2);
4496-
4497- early_trap_init(vectors);
4498+ early_trap_init(&vectors);
4499
4500 for (addr = VMALLOC_START; addr; addr += PMD_SIZE)
4501 pmd_clear(pmd_off_k(addr));
4502@@ -1237,7 +1323,7 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4503 * location (0xffff0000). If we aren't using high-vectors, also
4504 * create a mapping at the low-vectors virtual address.
4505 */
4506- map.pfn = __phys_to_pfn(virt_to_phys(vectors));
4507+ map.pfn = __phys_to_pfn(virt_to_phys(&vectors));
4508 map.virtual = 0xffff0000;
4509 map.length = PAGE_SIZE;
4510 #ifdef CONFIG_KUSER_HELPERS
4511@@ -1309,8 +1395,39 @@ static void __init map_lowmem(void)
4512 map.pfn = __phys_to_pfn(start);
4513 map.virtual = __phys_to_virt(start);
4514 map.length = end - start;
4515- map.type = MT_MEMORY;
4516
4517+#ifdef CONFIG_PAX_KERNEXEC
4518+ if (map.virtual <= (unsigned long)_stext && ((unsigned long)_end < (map.virtual + map.length))) {
4519+ struct map_desc kernel;
4520+ struct map_desc initmap;
4521+
4522+ /* when freeing initmem we will make this RW */
4523+ initmap.pfn = __phys_to_pfn(__pa(__init_begin));
4524+ initmap.virtual = (unsigned long)__init_begin;
4525+ initmap.length = _sdata - __init_begin;
4526+ initmap.type = MT_MEMORY_RWX;
4527+ create_mapping(&initmap);
4528+
4529+ /* when freeing initmem we will make this RX */
4530+ kernel.pfn = __phys_to_pfn(__pa(_stext));
4531+ kernel.virtual = (unsigned long)_stext;
4532+ kernel.length = __init_begin - _stext;
4533+ kernel.type = MT_MEMORY_RWX;
4534+ create_mapping(&kernel);
4535+
4536+ if (map.virtual < (unsigned long)_stext) {
4537+ map.length = (unsigned long)_stext - map.virtual;
4538+ map.type = MT_MEMORY_RWX;
4539+ create_mapping(&map);
4540+ }
4541+
4542+ map.pfn = __phys_to_pfn(__pa(_sdata));
4543+ map.virtual = (unsigned long)_sdata;
4544+ map.length = end - __pa(_sdata);
4545+ }
4546+#endif
4547+
4548+ map.type = MT_MEMORY_RW;
4549 create_mapping(&map);
4550 }
4551 }
4552diff --git a/arch/arm/plat-omap/sram.c b/arch/arm/plat-omap/sram.c
4553index a5bc92d..0bb4730 100644
4554--- a/arch/arm/plat-omap/sram.c
4555+++ b/arch/arm/plat-omap/sram.c
4556@@ -93,6 +93,8 @@ void __init omap_map_sram(unsigned long start, unsigned long size,
4557 * Looks like we need to preserve some bootloader code at the
4558 * beginning of SRAM for jumping to flash for reboot to work...
4559 */
4560+ pax_open_kernel();
4561 memset_io(omap_sram_base + omap_sram_skip, 0,
4562 omap_sram_size - omap_sram_skip);
4563+ pax_close_kernel();
4564 }
4565diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
4566index ce6d763..cfea917 100644
4567--- a/arch/arm/plat-samsung/include/plat/dma-ops.h
4568+++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
4569@@ -47,7 +47,7 @@ struct samsung_dma_ops {
4570 int (*started)(unsigned ch);
4571 int (*flush)(unsigned ch);
4572 int (*stop)(unsigned ch);
4573-};
4574+} __no_const;
4575
4576 extern void *samsung_dmadev_get_ops(void);
4577 extern void *s3c_dma_get_ops(void);
4578diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
4579index c3a58a1..78fbf54 100644
4580--- a/arch/avr32/include/asm/cache.h
4581+++ b/arch/avr32/include/asm/cache.h
4582@@ -1,8 +1,10 @@
4583 #ifndef __ASM_AVR32_CACHE_H
4584 #define __ASM_AVR32_CACHE_H
4585
4586+#include <linux/const.h>
4587+
4588 #define L1_CACHE_SHIFT 5
4589-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4590+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4591
4592 /*
4593 * Memory returned by kmalloc() may be used for DMA, so we must make
4594diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
4595index d232888..87c8df1 100644
4596--- a/arch/avr32/include/asm/elf.h
4597+++ b/arch/avr32/include/asm/elf.h
4598@@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
4599 the loader. We need to make sure that it is out of the way of the program
4600 that it will "exec", and that there is sufficient room for the brk. */
4601
4602-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
4603+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
4604
4605+#ifdef CONFIG_PAX_ASLR
4606+#define PAX_ELF_ET_DYN_BASE 0x00001000UL
4607+
4608+#define PAX_DELTA_MMAP_LEN 15
4609+#define PAX_DELTA_STACK_LEN 15
4610+#endif
4611
4612 /* This yields a mask that user programs can use to figure out what
4613 instruction set this CPU supports. This could be done in user space,
4614diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
4615index 479330b..53717a8 100644
4616--- a/arch/avr32/include/asm/kmap_types.h
4617+++ b/arch/avr32/include/asm/kmap_types.h
4618@@ -2,9 +2,9 @@
4619 #define __ASM_AVR32_KMAP_TYPES_H
4620
4621 #ifdef CONFIG_DEBUG_HIGHMEM
4622-# define KM_TYPE_NR 29
4623+# define KM_TYPE_NR 30
4624 #else
4625-# define KM_TYPE_NR 14
4626+# define KM_TYPE_NR 15
4627 #endif
4628
4629 #endif /* __ASM_AVR32_KMAP_TYPES_H */
4630diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
4631index 0eca933..eb78c7b 100644
4632--- a/arch/avr32/mm/fault.c
4633+++ b/arch/avr32/mm/fault.c
4634@@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
4635
4636 int exception_trace = 1;
4637
4638+#ifdef CONFIG_PAX_PAGEEXEC
4639+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4640+{
4641+ unsigned long i;
4642+
4643+ printk(KERN_ERR "PAX: bytes at PC: ");
4644+ for (i = 0; i < 20; i++) {
4645+ unsigned char c;
4646+ if (get_user(c, (unsigned char *)pc+i))
4647+ printk(KERN_CONT "???????? ");
4648+ else
4649+ printk(KERN_CONT "%02x ", c);
4650+ }
4651+ printk("\n");
4652+}
4653+#endif
4654+
4655 /*
4656 * This routine handles page faults. It determines the address and the
4657 * problem, and then passes it off to one of the appropriate routines.
4658@@ -176,6 +193,16 @@ bad_area:
4659 up_read(&mm->mmap_sem);
4660
4661 if (user_mode(regs)) {
4662+
4663+#ifdef CONFIG_PAX_PAGEEXEC
4664+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4665+ if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
4666+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
4667+ do_group_exit(SIGKILL);
4668+ }
4669+ }
4670+#endif
4671+
4672 if (exception_trace && printk_ratelimit())
4673 printk("%s%s[%d]: segfault at %08lx pc %08lx "
4674 "sp %08lx ecr %lu\n",
4675diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
4676index 568885a..f8008df 100644
4677--- a/arch/blackfin/include/asm/cache.h
4678+++ b/arch/blackfin/include/asm/cache.h
4679@@ -7,6 +7,7 @@
4680 #ifndef __ARCH_BLACKFIN_CACHE_H
4681 #define __ARCH_BLACKFIN_CACHE_H
4682
4683+#include <linux/const.h>
4684 #include <linux/linkage.h> /* for asmlinkage */
4685
4686 /*
4687@@ -14,7 +15,7 @@
4688 * Blackfin loads 32 bytes for cache
4689 */
4690 #define L1_CACHE_SHIFT 5
4691-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4692+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4693 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4694
4695 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
4696diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
4697index aea2718..3639a60 100644
4698--- a/arch/cris/include/arch-v10/arch/cache.h
4699+++ b/arch/cris/include/arch-v10/arch/cache.h
4700@@ -1,8 +1,9 @@
4701 #ifndef _ASM_ARCH_CACHE_H
4702 #define _ASM_ARCH_CACHE_H
4703
4704+#include <linux/const.h>
4705 /* Etrax 100LX have 32-byte cache-lines. */
4706-#define L1_CACHE_BYTES 32
4707 #define L1_CACHE_SHIFT 5
4708+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4709
4710 #endif /* _ASM_ARCH_CACHE_H */
4711diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
4712index 7caf25d..ee65ac5 100644
4713--- a/arch/cris/include/arch-v32/arch/cache.h
4714+++ b/arch/cris/include/arch-v32/arch/cache.h
4715@@ -1,11 +1,12 @@
4716 #ifndef _ASM_CRIS_ARCH_CACHE_H
4717 #define _ASM_CRIS_ARCH_CACHE_H
4718
4719+#include <linux/const.h>
4720 #include <arch/hwregs/dma.h>
4721
4722 /* A cache-line is 32 bytes. */
4723-#define L1_CACHE_BYTES 32
4724 #define L1_CACHE_SHIFT 5
4725+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4726
4727 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4728
4729diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
4730index b86329d..6709906 100644
4731--- a/arch/frv/include/asm/atomic.h
4732+++ b/arch/frv/include/asm/atomic.h
4733@@ -186,6 +186,16 @@ static inline void atomic64_dec(atomic64_t *v)
4734 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
4735 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
4736
4737+#define atomic64_read_unchecked(v) atomic64_read(v)
4738+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4739+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4740+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4741+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4742+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4743+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4744+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4745+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4746+
4747 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
4748 {
4749 int c, old;
4750diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
4751index 2797163..c2a401d 100644
4752--- a/arch/frv/include/asm/cache.h
4753+++ b/arch/frv/include/asm/cache.h
4754@@ -12,10 +12,11 @@
4755 #ifndef __ASM_CACHE_H
4756 #define __ASM_CACHE_H
4757
4758+#include <linux/const.h>
4759
4760 /* bytes per L1 cache line */
4761 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
4762-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4763+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4764
4765 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4766 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4767diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
4768index 43901f2..0d8b865 100644
4769--- a/arch/frv/include/asm/kmap_types.h
4770+++ b/arch/frv/include/asm/kmap_types.h
4771@@ -2,6 +2,6 @@
4772 #ifndef _ASM_KMAP_TYPES_H
4773 #define _ASM_KMAP_TYPES_H
4774
4775-#define KM_TYPE_NR 17
4776+#define KM_TYPE_NR 18
4777
4778 #endif
4779diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
4780index 836f147..4cf23f5 100644
4781--- a/arch/frv/mm/elf-fdpic.c
4782+++ b/arch/frv/mm/elf-fdpic.c
4783@@ -61,6 +61,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4784 {
4785 struct vm_area_struct *vma;
4786 struct vm_unmapped_area_info info;
4787+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
4788
4789 if (len > TASK_SIZE)
4790 return -ENOMEM;
4791@@ -73,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4792 if (addr) {
4793 addr = PAGE_ALIGN(addr);
4794 vma = find_vma(current->mm, addr);
4795- if (TASK_SIZE - len >= addr &&
4796- (!vma || addr + len <= vma->vm_start))
4797+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4798 goto success;
4799 }
4800
4801@@ -85,6 +85,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4802 info.high_limit = (current->mm->start_stack - 0x00200000);
4803 info.align_mask = 0;
4804 info.align_offset = 0;
4805+ info.threadstack_offset = offset;
4806 addr = vm_unmapped_area(&info);
4807 if (!(addr & ~PAGE_MASK))
4808 goto success;
4809diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
4810index f4ca594..adc72fd6 100644
4811--- a/arch/hexagon/include/asm/cache.h
4812+++ b/arch/hexagon/include/asm/cache.h
4813@@ -21,9 +21,11 @@
4814 #ifndef __ASM_CACHE_H
4815 #define __ASM_CACHE_H
4816
4817+#include <linux/const.h>
4818+
4819 /* Bytes per L1 cache line */
4820-#define L1_CACHE_SHIFT (5)
4821-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4822+#define L1_CACHE_SHIFT 5
4823+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4824
4825 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
4826 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
4827diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
4828index 6e6fe18..a6ae668 100644
4829--- a/arch/ia64/include/asm/atomic.h
4830+++ b/arch/ia64/include/asm/atomic.h
4831@@ -208,6 +208,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
4832 #define atomic64_inc(v) atomic64_add(1, (v))
4833 #define atomic64_dec(v) atomic64_sub(1, (v))
4834
4835+#define atomic64_read_unchecked(v) atomic64_read(v)
4836+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4837+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4838+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4839+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4840+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4841+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4842+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4843+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4844+
4845 /* Atomic operations are already serializing */
4846 #define smp_mb__before_atomic_dec() barrier()
4847 #define smp_mb__after_atomic_dec() barrier()
4848diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
4849index 988254a..e1ee885 100644
4850--- a/arch/ia64/include/asm/cache.h
4851+++ b/arch/ia64/include/asm/cache.h
4852@@ -1,6 +1,7 @@
4853 #ifndef _ASM_IA64_CACHE_H
4854 #define _ASM_IA64_CACHE_H
4855
4856+#include <linux/const.h>
4857
4858 /*
4859 * Copyright (C) 1998-2000 Hewlett-Packard Co
4860@@ -9,7 +10,7 @@
4861
4862 /* Bytes per L1 (data) cache line. */
4863 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
4864-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4865+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4866
4867 #ifdef CONFIG_SMP
4868 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
4869diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
4870index 5a83c5c..4d7f553 100644
4871--- a/arch/ia64/include/asm/elf.h
4872+++ b/arch/ia64/include/asm/elf.h
4873@@ -42,6 +42,13 @@
4874 */
4875 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
4876
4877+#ifdef CONFIG_PAX_ASLR
4878+#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
4879+
4880+#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
4881+#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
4882+#endif
4883+
4884 #define PT_IA_64_UNWIND 0x70000001
4885
4886 /* IA-64 relocations: */
4887diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
4888index 96a8d92..617a1cf 100644
4889--- a/arch/ia64/include/asm/pgalloc.h
4890+++ b/arch/ia64/include/asm/pgalloc.h
4891@@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
4892 pgd_val(*pgd_entry) = __pa(pud);
4893 }
4894
4895+static inline void
4896+pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
4897+{
4898+ pgd_populate(mm, pgd_entry, pud);
4899+}
4900+
4901 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
4902 {
4903 return quicklist_alloc(0, GFP_KERNEL, NULL);
4904@@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
4905 pud_val(*pud_entry) = __pa(pmd);
4906 }
4907
4908+static inline void
4909+pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
4910+{
4911+ pud_populate(mm, pud_entry, pmd);
4912+}
4913+
4914 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
4915 {
4916 return quicklist_alloc(0, GFP_KERNEL, NULL);
4917diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
4918index 7935115..c0eca6a 100644
4919--- a/arch/ia64/include/asm/pgtable.h
4920+++ b/arch/ia64/include/asm/pgtable.h
4921@@ -12,7 +12,7 @@
4922 * David Mosberger-Tang <davidm@hpl.hp.com>
4923 */
4924
4925-
4926+#include <linux/const.h>
4927 #include <asm/mman.h>
4928 #include <asm/page.h>
4929 #include <asm/processor.h>
4930@@ -142,6 +142,17 @@
4931 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4932 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4933 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
4934+
4935+#ifdef CONFIG_PAX_PAGEEXEC
4936+# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
4937+# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4938+# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4939+#else
4940+# define PAGE_SHARED_NOEXEC PAGE_SHARED
4941+# define PAGE_READONLY_NOEXEC PAGE_READONLY
4942+# define PAGE_COPY_NOEXEC PAGE_COPY
4943+#endif
4944+
4945 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
4946 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
4947 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
4948diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
4949index 45698cd..e8e2dbc 100644
4950--- a/arch/ia64/include/asm/spinlock.h
4951+++ b/arch/ia64/include/asm/spinlock.h
4952@@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
4953 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
4954
4955 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
4956- ACCESS_ONCE(*p) = (tmp + 2) & ~1;
4957+ ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
4958 }
4959
4960 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
4961diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
4962index 449c8c0..18965fb 100644
4963--- a/arch/ia64/include/asm/uaccess.h
4964+++ b/arch/ia64/include/asm/uaccess.h
4965@@ -240,12 +240,24 @@ extern unsigned long __must_check __copy_user (void __user *to, const void __use
4966 static inline unsigned long
4967 __copy_to_user (void __user *to, const void *from, unsigned long count)
4968 {
4969+ if (count > INT_MAX)
4970+ return count;
4971+
4972+ if (!__builtin_constant_p(count))
4973+ check_object_size(from, count, true);
4974+
4975 return __copy_user(to, (__force void __user *) from, count);
4976 }
4977
4978 static inline unsigned long
4979 __copy_from_user (void *to, const void __user *from, unsigned long count)
4980 {
4981+ if (count > INT_MAX)
4982+ return count;
4983+
4984+ if (!__builtin_constant_p(count))
4985+ check_object_size(to, count, false);
4986+
4987 return __copy_user((__force void __user *) to, from, count);
4988 }
4989
4990@@ -255,10 +267,13 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
4991 ({ \
4992 void __user *__cu_to = (to); \
4993 const void *__cu_from = (from); \
4994- long __cu_len = (n); \
4995+ unsigned long __cu_len = (n); \
4996 \
4997- if (__access_ok(__cu_to, __cu_len, get_fs())) \
4998+ if (__cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) { \
4999+ if (!__builtin_constant_p(n)) \
5000+ check_object_size(__cu_from, __cu_len, true); \
5001 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
5002+ } \
5003 __cu_len; \
5004 })
5005
5006@@ -266,11 +281,14 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5007 ({ \
5008 void *__cu_to = (to); \
5009 const void __user *__cu_from = (from); \
5010- long __cu_len = (n); \
5011+ unsigned long __cu_len = (n); \
5012 \
5013 __chk_user_ptr(__cu_from); \
5014- if (__access_ok(__cu_from, __cu_len, get_fs())) \
5015+ if (__cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) { \
5016+ if (!__builtin_constant_p(n)) \
5017+ check_object_size(__cu_to, __cu_len, false); \
5018 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
5019+ } \
5020 __cu_len; \
5021 })
5022
5023diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
5024index 24603be..948052d 100644
5025--- a/arch/ia64/kernel/module.c
5026+++ b/arch/ia64/kernel/module.c
5027@@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
5028 void
5029 module_free (struct module *mod, void *module_region)
5030 {
5031- if (mod && mod->arch.init_unw_table &&
5032- module_region == mod->module_init) {
5033+ if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
5034 unw_remove_unwind_table(mod->arch.init_unw_table);
5035 mod->arch.init_unw_table = NULL;
5036 }
5037@@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
5038 }
5039
5040 static inline int
5041+in_init_rx (const struct module *mod, uint64_t addr)
5042+{
5043+ return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
5044+}
5045+
5046+static inline int
5047+in_init_rw (const struct module *mod, uint64_t addr)
5048+{
5049+ return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
5050+}
5051+
5052+static inline int
5053 in_init (const struct module *mod, uint64_t addr)
5054 {
5055- return addr - (uint64_t) mod->module_init < mod->init_size;
5056+ return in_init_rx(mod, addr) || in_init_rw(mod, addr);
5057+}
5058+
5059+static inline int
5060+in_core_rx (const struct module *mod, uint64_t addr)
5061+{
5062+ return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
5063+}
5064+
5065+static inline int
5066+in_core_rw (const struct module *mod, uint64_t addr)
5067+{
5068+ return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
5069 }
5070
5071 static inline int
5072 in_core (const struct module *mod, uint64_t addr)
5073 {
5074- return addr - (uint64_t) mod->module_core < mod->core_size;
5075+ return in_core_rx(mod, addr) || in_core_rw(mod, addr);
5076 }
5077
5078 static inline int
5079@@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
5080 break;
5081
5082 case RV_BDREL:
5083- val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
5084+ if (in_init_rx(mod, val))
5085+ val -= (uint64_t) mod->module_init_rx;
5086+ else if (in_init_rw(mod, val))
5087+ val -= (uint64_t) mod->module_init_rw;
5088+ else if (in_core_rx(mod, val))
5089+ val -= (uint64_t) mod->module_core_rx;
5090+ else if (in_core_rw(mod, val))
5091+ val -= (uint64_t) mod->module_core_rw;
5092 break;
5093
5094 case RV_LTV:
5095@@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
5096 * addresses have been selected...
5097 */
5098 uint64_t gp;
5099- if (mod->core_size > MAX_LTOFF)
5100+ if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
5101 /*
5102 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
5103 * at the end of the module.
5104 */
5105- gp = mod->core_size - MAX_LTOFF / 2;
5106+ gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
5107 else
5108- gp = mod->core_size / 2;
5109- gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
5110+ gp = (mod->core_size_rx + mod->core_size_rw) / 2;
5111+ gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
5112 mod->arch.gp = gp;
5113 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
5114 }
5115diff --git a/arch/ia64/kernel/palinfo.c b/arch/ia64/kernel/palinfo.c
5116index ab33328..f39506c 100644
5117--- a/arch/ia64/kernel/palinfo.c
5118+++ b/arch/ia64/kernel/palinfo.c
5119@@ -980,7 +980,7 @@ static int palinfo_cpu_callback(struct notifier_block *nfb,
5120 return NOTIFY_OK;
5121 }
5122
5123-static struct notifier_block __refdata palinfo_cpu_notifier =
5124+static struct notifier_block palinfo_cpu_notifier =
5125 {
5126 .notifier_call = palinfo_cpu_callback,
5127 .priority = 0,
5128diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
5129index 41e33f8..65180b2 100644
5130--- a/arch/ia64/kernel/sys_ia64.c
5131+++ b/arch/ia64/kernel/sys_ia64.c
5132@@ -28,6 +28,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5133 unsigned long align_mask = 0;
5134 struct mm_struct *mm = current->mm;
5135 struct vm_unmapped_area_info info;
5136+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
5137
5138 if (len > RGN_MAP_LIMIT)
5139 return -ENOMEM;
5140@@ -43,6 +44,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5141 if (REGION_NUMBER(addr) == RGN_HPAGE)
5142 addr = 0;
5143 #endif
5144+
5145+#ifdef CONFIG_PAX_RANDMMAP
5146+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5147+ addr = mm->free_area_cache;
5148+ else
5149+#endif
5150+
5151 if (!addr)
5152 addr = TASK_UNMAPPED_BASE;
5153
5154@@ -61,6 +69,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5155 info.high_limit = TASK_SIZE;
5156 info.align_mask = align_mask;
5157 info.align_offset = 0;
5158+ info.threadstack_offset = offset;
5159 return vm_unmapped_area(&info);
5160 }
5161
5162diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
5163index 0ccb28f..8992469 100644
5164--- a/arch/ia64/kernel/vmlinux.lds.S
5165+++ b/arch/ia64/kernel/vmlinux.lds.S
5166@@ -198,7 +198,7 @@ SECTIONS {
5167 /* Per-cpu data: */
5168 . = ALIGN(PERCPU_PAGE_SIZE);
5169 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
5170- __phys_per_cpu_start = __per_cpu_load;
5171+ __phys_per_cpu_start = per_cpu_load;
5172 /*
5173 * ensure percpu data fits
5174 * into percpu page size
5175diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
5176index 7225dad..2a7c8256 100644
5177--- a/arch/ia64/mm/fault.c
5178+++ b/arch/ia64/mm/fault.c
5179@@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
5180 return pte_present(pte);
5181 }
5182
5183+#ifdef CONFIG_PAX_PAGEEXEC
5184+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5185+{
5186+ unsigned long i;
5187+
5188+ printk(KERN_ERR "PAX: bytes at PC: ");
5189+ for (i = 0; i < 8; i++) {
5190+ unsigned int c;
5191+ if (get_user(c, (unsigned int *)pc+i))
5192+ printk(KERN_CONT "???????? ");
5193+ else
5194+ printk(KERN_CONT "%08x ", c);
5195+ }
5196+ printk("\n");
5197+}
5198+#endif
5199+
5200 # define VM_READ_BIT 0
5201 # define VM_WRITE_BIT 1
5202 # define VM_EXEC_BIT 2
5203@@ -151,8 +168,21 @@ retry:
5204 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
5205 goto bad_area;
5206
5207- if ((vma->vm_flags & mask) != mask)
5208+ if ((vma->vm_flags & mask) != mask) {
5209+
5210+#ifdef CONFIG_PAX_PAGEEXEC
5211+ if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
5212+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
5213+ goto bad_area;
5214+
5215+ up_read(&mm->mmap_sem);
5216+ pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
5217+ do_group_exit(SIGKILL);
5218+ }
5219+#endif
5220+
5221 goto bad_area;
5222+ }
5223
5224 /*
5225 * If for any reason at all we couldn't handle the fault, make
5226diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
5227index 68232db..6ca80af 100644
5228--- a/arch/ia64/mm/hugetlbpage.c
5229+++ b/arch/ia64/mm/hugetlbpage.c
5230@@ -154,6 +154,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5231 unsigned long pgoff, unsigned long flags)
5232 {
5233 struct vm_unmapped_area_info info;
5234+ unsigned long offset = gr_rand_threadstack_offset(current->mm, file, flags);
5235
5236 if (len > RGN_MAP_LIMIT)
5237 return -ENOMEM;
5238@@ -177,6 +178,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5239 info.high_limit = HPAGE_REGION_BASE + RGN_MAP_LIMIT;
5240 info.align_mask = PAGE_MASK & (HPAGE_SIZE - 1);
5241 info.align_offset = 0;
5242+ info.threadstack_offset = offset;
5243 return vm_unmapped_area(&info);
5244 }
5245
5246diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
5247index b6f7f43..c04320d 100644
5248--- a/arch/ia64/mm/init.c
5249+++ b/arch/ia64/mm/init.c
5250@@ -120,6 +120,19 @@ ia64_init_addr_space (void)
5251 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
5252 vma->vm_end = vma->vm_start + PAGE_SIZE;
5253 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
5254+
5255+#ifdef CONFIG_PAX_PAGEEXEC
5256+ if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
5257+ vma->vm_flags &= ~VM_EXEC;
5258+
5259+#ifdef CONFIG_PAX_MPROTECT
5260+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
5261+ vma->vm_flags &= ~VM_MAYEXEC;
5262+#endif
5263+
5264+ }
5265+#endif
5266+
5267 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
5268 down_write(&current->mm->mmap_sem);
5269 if (insert_vm_struct(current->mm, vma)) {
5270diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
5271index 40b3ee9..8c2c112 100644
5272--- a/arch/m32r/include/asm/cache.h
5273+++ b/arch/m32r/include/asm/cache.h
5274@@ -1,8 +1,10 @@
5275 #ifndef _ASM_M32R_CACHE_H
5276 #define _ASM_M32R_CACHE_H
5277
5278+#include <linux/const.h>
5279+
5280 /* L1 cache line size */
5281 #define L1_CACHE_SHIFT 4
5282-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5283+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5284
5285 #endif /* _ASM_M32R_CACHE_H */
5286diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
5287index 82abd15..d95ae5d 100644
5288--- a/arch/m32r/lib/usercopy.c
5289+++ b/arch/m32r/lib/usercopy.c
5290@@ -14,6 +14,9 @@
5291 unsigned long
5292 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5293 {
5294+ if ((long)n < 0)
5295+ return n;
5296+
5297 prefetch(from);
5298 if (access_ok(VERIFY_WRITE, to, n))
5299 __copy_user(to,from,n);
5300@@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5301 unsigned long
5302 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
5303 {
5304+ if ((long)n < 0)
5305+ return n;
5306+
5307 prefetchw(to);
5308 if (access_ok(VERIFY_READ, from, n))
5309 __copy_user_zeroing(to,from,n);
5310diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
5311index 0395c51..5f26031 100644
5312--- a/arch/m68k/include/asm/cache.h
5313+++ b/arch/m68k/include/asm/cache.h
5314@@ -4,9 +4,11 @@
5315 #ifndef __ARCH_M68K_CACHE_H
5316 #define __ARCH_M68K_CACHE_H
5317
5318+#include <linux/const.h>
5319+
5320 /* bytes per L1 cache line */
5321 #define L1_CACHE_SHIFT 4
5322-#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
5323+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5324
5325 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
5326
5327diff --git a/arch/metag/mm/hugetlbpage.c b/arch/metag/mm/hugetlbpage.c
5328index 0424315..defcca9 100644
5329--- a/arch/metag/mm/hugetlbpage.c
5330+++ b/arch/metag/mm/hugetlbpage.c
5331@@ -205,6 +205,7 @@ hugetlb_get_unmapped_area_new_pmd(unsigned long len)
5332 info.high_limit = TASK_SIZE;
5333 info.align_mask = PAGE_MASK & HUGEPT_MASK;
5334 info.align_offset = 0;
5335+ info.threadstack_offset = 0;
5336 return vm_unmapped_area(&info);
5337 }
5338
5339diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
5340index 4efe96a..60e8699 100644
5341--- a/arch/microblaze/include/asm/cache.h
5342+++ b/arch/microblaze/include/asm/cache.h
5343@@ -13,11 +13,12 @@
5344 #ifndef _ASM_MICROBLAZE_CACHE_H
5345 #define _ASM_MICROBLAZE_CACHE_H
5346
5347+#include <linux/const.h>
5348 #include <asm/registers.h>
5349
5350 #define L1_CACHE_SHIFT 5
5351 /* word-granular cache in microblaze */
5352-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5353+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5354
5355 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5356
5357diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
5358index 08b6079..8b554d2 100644
5359--- a/arch/mips/include/asm/atomic.h
5360+++ b/arch/mips/include/asm/atomic.h
5361@@ -21,15 +21,39 @@
5362 #include <asm/cmpxchg.h>
5363 #include <asm/war.h>
5364
5365+#ifdef CONFIG_GENERIC_ATOMIC64
5366+#include <asm-generic/atomic64.h>
5367+#endif
5368+
5369 #define ATOMIC_INIT(i) { (i) }
5370
5371+#ifdef CONFIG_64BIT
5372+#define _ASM_EXTABLE(from, to) \
5373+" .section __ex_table,\"a\"\n" \
5374+" .dword " #from ", " #to"\n" \
5375+" .previous\n"
5376+#else
5377+#define _ASM_EXTABLE(from, to) \
5378+" .section __ex_table,\"a\"\n" \
5379+" .word " #from ", " #to"\n" \
5380+" .previous\n"
5381+#endif
5382+
5383 /*
5384 * atomic_read - read atomic variable
5385 * @v: pointer of type atomic_t
5386 *
5387 * Atomically reads the value of @v.
5388 */
5389-#define atomic_read(v) (*(volatile int *)&(v)->counter)
5390+static inline int atomic_read(const atomic_t *v)
5391+{
5392+ return (*(volatile const int *) &v->counter);
5393+}
5394+
5395+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
5396+{
5397+ return (*(volatile const int *) &v->counter);
5398+}
5399
5400 /*
5401 * atomic_set - set atomic variable
5402@@ -38,7 +62,15 @@
5403 *
5404 * Atomically sets the value of @v to @i.
5405 */
5406-#define atomic_set(v, i) ((v)->counter = (i))
5407+static inline void atomic_set(atomic_t *v, int i)
5408+{
5409+ v->counter = i;
5410+}
5411+
5412+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
5413+{
5414+ v->counter = i;
5415+}
5416
5417 /*
5418 * atomic_add - add integer to atomic variable
5419@@ -47,7 +79,67 @@
5420 *
5421 * Atomically adds @i to @v.
5422 */
5423-static __inline__ void atomic_add(int i, atomic_t * v)
5424+static __inline__ void atomic_add(int i, atomic_t *v)
5425+{
5426+ int temp;
5427+
5428+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5429+ __asm__ __volatile__(
5430+ " .set mips3 \n"
5431+ "1: ll %0, %1 # atomic_add \n"
5432+#ifdef CONFIG_PAX_REFCOUNT
5433+ /* Exception on overflow. */
5434+ "2: add %0, %2 \n"
5435+#else
5436+ " addu %0, %2 \n"
5437+#endif
5438+ " sc %0, %1 \n"
5439+ " beqzl %0, 1b \n"
5440+#ifdef CONFIG_PAX_REFCOUNT
5441+ "3: \n"
5442+ _ASM_EXTABLE(2b, 3b)
5443+#endif
5444+ " .set mips0 \n"
5445+ : "=&r" (temp), "+m" (v->counter)
5446+ : "Ir" (i));
5447+ } else if (kernel_uses_llsc) {
5448+ __asm__ __volatile__(
5449+ " .set mips3 \n"
5450+ "1: ll %0, %1 # atomic_add \n"
5451+#ifdef CONFIG_PAX_REFCOUNT
5452+ /* Exception on overflow. */
5453+ "2: add %0, %2 \n"
5454+#else
5455+ " addu %0, %2 \n"
5456+#endif
5457+ " sc %0, %1 \n"
5458+ " beqz %0, 1b \n"
5459+#ifdef CONFIG_PAX_REFCOUNT
5460+ "3: \n"
5461+ _ASM_EXTABLE(2b, 3b)
5462+#endif
5463+ " .set mips0 \n"
5464+ : "=&r" (temp), "+m" (v->counter)
5465+ : "Ir" (i));
5466+ } else {
5467+ unsigned long flags;
5468+
5469+ raw_local_irq_save(flags);
5470+ __asm__ __volatile__(
5471+#ifdef CONFIG_PAX_REFCOUNT
5472+ /* Exception on overflow. */
5473+ "1: add %0, %1 \n"
5474+ "2: \n"
5475+ _ASM_EXTABLE(1b, 2b)
5476+#else
5477+ " addu %0, %1 \n"
5478+#endif
5479+ : "+r" (v->counter) : "Ir" (i));
5480+ raw_local_irq_restore(flags);
5481+ }
5482+}
5483+
5484+static __inline__ void atomic_add_unchecked(int i, atomic_unchecked_t *v)
5485 {
5486 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5487 int temp;
5488@@ -90,7 +182,67 @@ static __inline__ void atomic_add(int i, atomic_t * v)
5489 *
5490 * Atomically subtracts @i from @v.
5491 */
5492-static __inline__ void atomic_sub(int i, atomic_t * v)
5493+static __inline__ void atomic_sub(int i, atomic_t *v)
5494+{
5495+ int temp;
5496+
5497+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5498+ __asm__ __volatile__(
5499+ " .set mips3 \n"
5500+ "1: ll %0, %1 # atomic64_sub \n"
5501+#ifdef CONFIG_PAX_REFCOUNT
5502+ /* Exception on overflow. */
5503+ "2: sub %0, %2 \n"
5504+#else
5505+ " subu %0, %2 \n"
5506+#endif
5507+ " sc %0, %1 \n"
5508+ " beqzl %0, 1b \n"
5509+#ifdef CONFIG_PAX_REFCOUNT
5510+ "3: \n"
5511+ _ASM_EXTABLE(2b, 3b)
5512+#endif
5513+ " .set mips0 \n"
5514+ : "=&r" (temp), "+m" (v->counter)
5515+ : "Ir" (i));
5516+ } else if (kernel_uses_llsc) {
5517+ __asm__ __volatile__(
5518+ " .set mips3 \n"
5519+ "1: ll %0, %1 # atomic64_sub \n"
5520+#ifdef CONFIG_PAX_REFCOUNT
5521+ /* Exception on overflow. */
5522+ "2: sub %0, %2 \n"
5523+#else
5524+ " subu %0, %2 \n"
5525+#endif
5526+ " sc %0, %1 \n"
5527+ " beqz %0, 1b \n"
5528+#ifdef CONFIG_PAX_REFCOUNT
5529+ "3: \n"
5530+ _ASM_EXTABLE(2b, 3b)
5531+#endif
5532+ " .set mips0 \n"
5533+ : "=&r" (temp), "+m" (v->counter)
5534+ : "Ir" (i));
5535+ } else {
5536+ unsigned long flags;
5537+
5538+ raw_local_irq_save(flags);
5539+ __asm__ __volatile__(
5540+#ifdef CONFIG_PAX_REFCOUNT
5541+ /* Exception on overflow. */
5542+ "1: sub %0, %1 \n"
5543+ "2: \n"
5544+ _ASM_EXTABLE(1b, 2b)
5545+#else
5546+ " subu %0, %1 \n"
5547+#endif
5548+ : "+r" (v->counter) : "Ir" (i));
5549+ raw_local_irq_restore(flags);
5550+ }
5551+}
5552+
5553+static __inline__ void atomic_sub_unchecked(long i, atomic_unchecked_t *v)
5554 {
5555 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5556 int temp;
5557@@ -129,7 +281,93 @@ static __inline__ void atomic_sub(int i, atomic_t * v)
5558 /*
5559 * Same as above, but return the result value
5560 */
5561-static __inline__ int atomic_add_return(int i, atomic_t * v)
5562+static __inline__ int atomic_add_return(int i, atomic_t *v)
5563+{
5564+ int result;
5565+ int temp;
5566+
5567+ smp_mb__before_llsc();
5568+
5569+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5570+ __asm__ __volatile__(
5571+ " .set mips3 \n"
5572+ "1: ll %1, %2 # atomic_add_return \n"
5573+#ifdef CONFIG_PAX_REFCOUNT
5574+ "2: add %0, %1, %3 \n"
5575+#else
5576+ " addu %0, %1, %3 \n"
5577+#endif
5578+ " sc %0, %2 \n"
5579+ " beqzl %0, 1b \n"
5580+#ifdef CONFIG_PAX_REFCOUNT
5581+ " b 4f \n"
5582+ " .set noreorder \n"
5583+ "3: b 5f \n"
5584+ " move %0, %1 \n"
5585+ " .set reorder \n"
5586+ _ASM_EXTABLE(2b, 3b)
5587+#endif
5588+ "4: addu %0, %1, %3 \n"
5589+#ifdef CONFIG_PAX_REFCOUNT
5590+ "5: \n"
5591+#endif
5592+ " .set mips0 \n"
5593+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5594+ : "Ir" (i));
5595+ } else if (kernel_uses_llsc) {
5596+ __asm__ __volatile__(
5597+ " .set mips3 \n"
5598+ "1: ll %1, %2 # atomic_add_return \n"
5599+#ifdef CONFIG_PAX_REFCOUNT
5600+ "2: add %0, %1, %3 \n"
5601+#else
5602+ " addu %0, %1, %3 \n"
5603+#endif
5604+ " sc %0, %2 \n"
5605+ " bnez %0, 4f \n"
5606+ " b 1b \n"
5607+#ifdef CONFIG_PAX_REFCOUNT
5608+ " .set noreorder \n"
5609+ "3: b 5f \n"
5610+ " move %0, %1 \n"
5611+ " .set reorder \n"
5612+ _ASM_EXTABLE(2b, 3b)
5613+#endif
5614+ "4: addu %0, %1, %3 \n"
5615+#ifdef CONFIG_PAX_REFCOUNT
5616+ "5: \n"
5617+#endif
5618+ " .set mips0 \n"
5619+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5620+ : "Ir" (i));
5621+ } else {
5622+ unsigned long flags;
5623+
5624+ raw_local_irq_save(flags);
5625+ __asm__ __volatile__(
5626+ " lw %0, %1 \n"
5627+#ifdef CONFIG_PAX_REFCOUNT
5628+ /* Exception on overflow. */
5629+ "1: add %0, %2 \n"
5630+#else
5631+ " addu %0, %2 \n"
5632+#endif
5633+ " sw %0, %1 \n"
5634+#ifdef CONFIG_PAX_REFCOUNT
5635+ /* Note: Dest reg is not modified on overflow */
5636+ "2: \n"
5637+ _ASM_EXTABLE(1b, 2b)
5638+#endif
5639+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
5640+ raw_local_irq_restore(flags);
5641+ }
5642+
5643+ smp_llsc_mb();
5644+
5645+ return result;
5646+}
5647+
5648+static __inline__ int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
5649 {
5650 int result;
5651
5652@@ -178,7 +416,93 @@ static __inline__ int atomic_add_return(int i, atomic_t * v)
5653 return result;
5654 }
5655
5656-static __inline__ int atomic_sub_return(int i, atomic_t * v)
5657+static __inline__ int atomic_sub_return(int i, atomic_t *v)
5658+{
5659+ int result;
5660+ int temp;
5661+
5662+ smp_mb__before_llsc();
5663+
5664+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5665+ __asm__ __volatile__(
5666+ " .set mips3 \n"
5667+ "1: ll %1, %2 # atomic_sub_return \n"
5668+#ifdef CONFIG_PAX_REFCOUNT
5669+ "2: sub %0, %1, %3 \n"
5670+#else
5671+ " subu %0, %1, %3 \n"
5672+#endif
5673+ " sc %0, %2 \n"
5674+ " beqzl %0, 1b \n"
5675+#ifdef CONFIG_PAX_REFCOUNT
5676+ " b 4f \n"
5677+ " .set noreorder \n"
5678+ "3: b 5f \n"
5679+ " move %0, %1 \n"
5680+ " .set reorder \n"
5681+ _ASM_EXTABLE(2b, 3b)
5682+#endif
5683+ "4: subu %0, %1, %3 \n"
5684+#ifdef CONFIG_PAX_REFCOUNT
5685+ "5: \n"
5686+#endif
5687+ " .set mips0 \n"
5688+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
5689+ : "Ir" (i), "m" (v->counter)
5690+ : "memory");
5691+ } else if (kernel_uses_llsc) {
5692+ __asm__ __volatile__(
5693+ " .set mips3 \n"
5694+ "1: ll %1, %2 # atomic_sub_return \n"
5695+#ifdef CONFIG_PAX_REFCOUNT
5696+ "2: sub %0, %1, %3 \n"
5697+#else
5698+ " subu %0, %1, %3 \n"
5699+#endif
5700+ " sc %0, %2 \n"
5701+ " bnez %0, 4f \n"
5702+ " b 1b \n"
5703+#ifdef CONFIG_PAX_REFCOUNT
5704+ " .set noreorder \n"
5705+ "3: b 5f \n"
5706+ " move %0, %1 \n"
5707+ " .set reorder \n"
5708+ _ASM_EXTABLE(2b, 3b)
5709+#endif
5710+ "4: subu %0, %1, %3 \n"
5711+#ifdef CONFIG_PAX_REFCOUNT
5712+ "5: \n"
5713+#endif
5714+ " .set mips0 \n"
5715+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5716+ : "Ir" (i));
5717+ } else {
5718+ unsigned long flags;
5719+
5720+ raw_local_irq_save(flags);
5721+ __asm__ __volatile__(
5722+ " lw %0, %1 \n"
5723+#ifdef CONFIG_PAX_REFCOUNT
5724+ /* Exception on overflow. */
5725+ "1: sub %0, %2 \n"
5726+#else
5727+ " subu %0, %2 \n"
5728+#endif
5729+ " sw %0, %1 \n"
5730+#ifdef CONFIG_PAX_REFCOUNT
5731+ /* Note: Dest reg is not modified on overflow */
5732+ "2: \n"
5733+ _ASM_EXTABLE(1b, 2b)
5734+#endif
5735+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
5736+ raw_local_irq_restore(flags);
5737+ }
5738+
5739+ smp_llsc_mb();
5740+
5741+ return result;
5742+}
5743+static __inline__ int atomic_sub_return_unchecked(int i, atomic_unchecked_t *v)
5744 {
5745 int result;
5746
5747@@ -238,7 +562,7 @@ static __inline__ int atomic_sub_return(int i, atomic_t * v)
5748 * Atomically test @v and subtract @i if @v is greater or equal than @i.
5749 * The function returns the old value of @v minus @i.
5750 */
5751-static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
5752+static __inline__ int atomic_sub_if_positive(int i, atomic_t *v)
5753 {
5754 int result;
5755
5756@@ -295,8 +619,26 @@ static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
5757 return result;
5758 }
5759
5760-#define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
5761-#define atomic_xchg(v, new) (xchg(&((v)->counter), (new)))
5762+static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
5763+{
5764+ return cmpxchg(&v->counter, old, new);
5765+}
5766+
5767+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old,
5768+ int new)
5769+{
5770+ return cmpxchg(&(v->counter), old, new);
5771+}
5772+
5773+static inline int atomic_xchg(atomic_t *v, int new)
5774+{
5775+ return xchg(&v->counter, new);
5776+}
5777+
5778+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
5779+{
5780+ return xchg(&(v->counter), new);
5781+}
5782
5783 /**
5784 * __atomic_add_unless - add unless the number is a given value
5785@@ -324,6 +666,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5786
5787 #define atomic_dec_return(v) atomic_sub_return(1, (v))
5788 #define atomic_inc_return(v) atomic_add_return(1, (v))
5789+static __inline__ int atomic_inc_return_unchecked(atomic_unchecked_t *v)
5790+{
5791+ return atomic_add_return_unchecked(1, v);
5792+}
5793
5794 /*
5795 * atomic_sub_and_test - subtract value from variable and test result
5796@@ -345,6 +691,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5797 * other cases.
5798 */
5799 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
5800+static __inline__ int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
5801+{
5802+ return atomic_add_return_unchecked(1, v) == 0;
5803+}
5804
5805 /*
5806 * atomic_dec_and_test - decrement by 1 and test
5807@@ -369,6 +719,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5808 * Atomically increments @v by 1.
5809 */
5810 #define atomic_inc(v) atomic_add(1, (v))
5811+static __inline__ void atomic_inc_unchecked(atomic_unchecked_t *v)
5812+{
5813+ atomic_add_unchecked(1, v);
5814+}
5815
5816 /*
5817 * atomic_dec - decrement and test
5818@@ -377,6 +731,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5819 * Atomically decrements @v by 1.
5820 */
5821 #define atomic_dec(v) atomic_sub(1, (v))
5822+static __inline__ void atomic_dec_unchecked(atomic_unchecked_t *v)
5823+{
5824+ atomic_sub_unchecked(1, v);
5825+}
5826
5827 /*
5828 * atomic_add_negative - add and test if negative
5829@@ -398,14 +756,30 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5830 * @v: pointer of type atomic64_t
5831 *
5832 */
5833-#define atomic64_read(v) (*(volatile long *)&(v)->counter)
5834+static inline long atomic64_read(const atomic64_t *v)
5835+{
5836+ return (*(volatile const long *) &v->counter);
5837+}
5838+
5839+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
5840+{
5841+ return (*(volatile const long *) &v->counter);
5842+}
5843
5844 /*
5845 * atomic64_set - set atomic variable
5846 * @v: pointer of type atomic64_t
5847 * @i: required value
5848 */
5849-#define atomic64_set(v, i) ((v)->counter = (i))
5850+static inline void atomic64_set(atomic64_t *v, long i)
5851+{
5852+ v->counter = i;
5853+}
5854+
5855+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
5856+{
5857+ v->counter = i;
5858+}
5859
5860 /*
5861 * atomic64_add - add integer to atomic variable
5862@@ -414,7 +788,66 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5863 *
5864 * Atomically adds @i to @v.
5865 */
5866-static __inline__ void atomic64_add(long i, atomic64_t * v)
5867+static __inline__ void atomic64_add(long i, atomic64_t *v)
5868+{
5869+ long temp;
5870+
5871+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5872+ __asm__ __volatile__(
5873+ " .set mips3 \n"
5874+ "1: lld %0, %1 # atomic64_add \n"
5875+#ifdef CONFIG_PAX_REFCOUNT
5876+ /* Exception on overflow. */
5877+ "2: dadd %0, %2 \n"
5878+#else
5879+ " daddu %0, %2 \n"
5880+#endif
5881+ " scd %0, %1 \n"
5882+ " beqzl %0, 1b \n"
5883+#ifdef CONFIG_PAX_REFCOUNT
5884+ "3: \n"
5885+ _ASM_EXTABLE(2b, 3b)
5886+#endif
5887+ " .set mips0 \n"
5888+ : "=&r" (temp), "+m" (v->counter)
5889+ : "Ir" (i));
5890+ } else if (kernel_uses_llsc) {
5891+ __asm__ __volatile__(
5892+ " .set mips3 \n"
5893+ "1: lld %0, %1 # atomic64_add \n"
5894+#ifdef CONFIG_PAX_REFCOUNT
5895+ /* Exception on overflow. */
5896+ "2: dadd %0, %2 \n"
5897+#else
5898+ " daddu %0, %2 \n"
5899+#endif
5900+ " scd %0, %1 \n"
5901+ " beqz %0, 1b \n"
5902+#ifdef CONFIG_PAX_REFCOUNT
5903+ "3: \n"
5904+ _ASM_EXTABLE(2b, 3b)
5905+#endif
5906+ " .set mips0 \n"
5907+ : "=&r" (temp), "+m" (v->counter)
5908+ : "Ir" (i));
5909+ } else {
5910+ unsigned long flags;
5911+
5912+ raw_local_irq_save(flags);
5913+ __asm__ __volatile__(
5914+#ifdef CONFIG_PAX_REFCOUNT
5915+ /* Exception on overflow. */
5916+ "1: dadd %0, %1 \n"
5917+ "2: \n"
5918+ _ASM_EXTABLE(1b, 2b)
5919+#else
5920+ " daddu %0, %1 \n"
5921+#endif
5922+ : "+r" (v->counter) : "Ir" (i));
5923+ raw_local_irq_restore(flags);
5924+ }
5925+}
5926+static __inline__ void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
5927 {
5928 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5929 long temp;
5930@@ -457,7 +890,67 @@ static __inline__ void atomic64_add(long i, atomic64_t * v)
5931 *
5932 * Atomically subtracts @i from @v.
5933 */
5934-static __inline__ void atomic64_sub(long i, atomic64_t * v)
5935+static __inline__ void atomic64_sub(long i, atomic64_t *v)
5936+{
5937+ long temp;
5938+
5939+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5940+ __asm__ __volatile__(
5941+ " .set mips3 \n"
5942+ "1: lld %0, %1 # atomic64_sub \n"
5943+#ifdef CONFIG_PAX_REFCOUNT
5944+ /* Exception on overflow. */
5945+ "2: dsub %0, %2 \n"
5946+#else
5947+ " dsubu %0, %2 \n"
5948+#endif
5949+ " scd %0, %1 \n"
5950+ " beqzl %0, 1b \n"
5951+#ifdef CONFIG_PAX_REFCOUNT
5952+ "3: \n"
5953+ _ASM_EXTABLE(2b, 3b)
5954+#endif
5955+ " .set mips0 \n"
5956+ : "=&r" (temp), "+m" (v->counter)
5957+ : "Ir" (i));
5958+ } else if (kernel_uses_llsc) {
5959+ __asm__ __volatile__(
5960+ " .set mips3 \n"
5961+ "1: lld %0, %1 # atomic64_sub \n"
5962+#ifdef CONFIG_PAX_REFCOUNT
5963+ /* Exception on overflow. */
5964+ "2: dsub %0, %2 \n"
5965+#else
5966+ " dsubu %0, %2 \n"
5967+#endif
5968+ " scd %0, %1 \n"
5969+ " beqz %0, 1b \n"
5970+#ifdef CONFIG_PAX_REFCOUNT
5971+ "3: \n"
5972+ _ASM_EXTABLE(2b, 3b)
5973+#endif
5974+ " .set mips0 \n"
5975+ : "=&r" (temp), "+m" (v->counter)
5976+ : "Ir" (i));
5977+ } else {
5978+ unsigned long flags;
5979+
5980+ raw_local_irq_save(flags);
5981+ __asm__ __volatile__(
5982+#ifdef CONFIG_PAX_REFCOUNT
5983+ /* Exception on overflow. */
5984+ "1: dsub %0, %1 \n"
5985+ "2: \n"
5986+ _ASM_EXTABLE(1b, 2b)
5987+#else
5988+ " dsubu %0, %1 \n"
5989+#endif
5990+ : "+r" (v->counter) : "Ir" (i));
5991+ raw_local_irq_restore(flags);
5992+ }
5993+}
5994+
5995+static __inline__ void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
5996 {
5997 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5998 long temp;
5999@@ -496,7 +989,93 @@ static __inline__ void atomic64_sub(long i, atomic64_t * v)
6000 /*
6001 * Same as above, but return the result value
6002 */
6003-static __inline__ long atomic64_add_return(long i, atomic64_t * v)
6004+static __inline__ long atomic64_add_return(long i, atomic64_t *v)
6005+{
6006+ long result;
6007+ long temp;
6008+
6009+ smp_mb__before_llsc();
6010+
6011+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6012+ __asm__ __volatile__(
6013+ " .set mips3 \n"
6014+ "1: lld %1, %2 # atomic64_add_return \n"
6015+#ifdef CONFIG_PAX_REFCOUNT
6016+ "2: dadd %0, %1, %3 \n"
6017+#else
6018+ " daddu %0, %1, %3 \n"
6019+#endif
6020+ " scd %0, %2 \n"
6021+ " beqzl %0, 1b \n"
6022+#ifdef CONFIG_PAX_REFCOUNT
6023+ " b 4f \n"
6024+ " .set noreorder \n"
6025+ "3: b 5f \n"
6026+ " move %0, %1 \n"
6027+ " .set reorder \n"
6028+ _ASM_EXTABLE(2b, 3b)
6029+#endif
6030+ "4: daddu %0, %1, %3 \n"
6031+#ifdef CONFIG_PAX_REFCOUNT
6032+ "5: \n"
6033+#endif
6034+ " .set mips0 \n"
6035+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
6036+ : "Ir" (i));
6037+ } else if (kernel_uses_llsc) {
6038+ __asm__ __volatile__(
6039+ " .set mips3 \n"
6040+ "1: lld %1, %2 # atomic64_add_return \n"
6041+#ifdef CONFIG_PAX_REFCOUNT
6042+ "2: dadd %0, %1, %3 \n"
6043+#else
6044+ " daddu %0, %1, %3 \n"
6045+#endif
6046+ " scd %0, %2 \n"
6047+ " bnez %0, 4f \n"
6048+ " b 1b \n"
6049+#ifdef CONFIG_PAX_REFCOUNT
6050+ " .set noreorder \n"
6051+ "3: b 5f \n"
6052+ " move %0, %1 \n"
6053+ " .set reorder \n"
6054+ _ASM_EXTABLE(2b, 3b)
6055+#endif
6056+ "4: daddu %0, %1, %3 \n"
6057+#ifdef CONFIG_PAX_REFCOUNT
6058+ "5: \n"
6059+#endif
6060+ " .set mips0 \n"
6061+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6062+ : "Ir" (i), "m" (v->counter)
6063+ : "memory");
6064+ } else {
6065+ unsigned long flags;
6066+
6067+ raw_local_irq_save(flags);
6068+ __asm__ __volatile__(
6069+ " ld %0, %1 \n"
6070+#ifdef CONFIG_PAX_REFCOUNT
6071+ /* Exception on overflow. */
6072+ "1: dadd %0, %2 \n"
6073+#else
6074+ " daddu %0, %2 \n"
6075+#endif
6076+ " sd %0, %1 \n"
6077+#ifdef CONFIG_PAX_REFCOUNT
6078+ /* Note: Dest reg is not modified on overflow */
6079+ "2: \n"
6080+ _ASM_EXTABLE(1b, 2b)
6081+#endif
6082+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6083+ raw_local_irq_restore(flags);
6084+ }
6085+
6086+ smp_llsc_mb();
6087+
6088+ return result;
6089+}
6090+static __inline__ long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
6091 {
6092 long result;
6093
6094@@ -546,7 +1125,97 @@ static __inline__ long atomic64_add_return(long i, atomic64_t * v)
6095 return result;
6096 }
6097
6098-static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
6099+static __inline__ long atomic64_sub_return(long i, atomic64_t *v)
6100+{
6101+ long result;
6102+ long temp;
6103+
6104+ smp_mb__before_llsc();
6105+
6106+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6107+ long temp;
6108+
6109+ __asm__ __volatile__(
6110+ " .set mips3 \n"
6111+ "1: lld %1, %2 # atomic64_sub_return \n"
6112+#ifdef CONFIG_PAX_REFCOUNT
6113+ "2: dsub %0, %1, %3 \n"
6114+#else
6115+ " dsubu %0, %1, %3 \n"
6116+#endif
6117+ " scd %0, %2 \n"
6118+ " beqzl %0, 1b \n"
6119+#ifdef CONFIG_PAX_REFCOUNT
6120+ " b 4f \n"
6121+ " .set noreorder \n"
6122+ "3: b 5f \n"
6123+ " move %0, %1 \n"
6124+ " .set reorder \n"
6125+ _ASM_EXTABLE(2b, 3b)
6126+#endif
6127+ "4: dsubu %0, %1, %3 \n"
6128+#ifdef CONFIG_PAX_REFCOUNT
6129+ "5: \n"
6130+#endif
6131+ " .set mips0 \n"
6132+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6133+ : "Ir" (i), "m" (v->counter)
6134+ : "memory");
6135+ } else if (kernel_uses_llsc) {
6136+ __asm__ __volatile__(
6137+ " .set mips3 \n"
6138+ "1: lld %1, %2 # atomic64_sub_return \n"
6139+#ifdef CONFIG_PAX_REFCOUNT
6140+ "2: dsub %0, %1, %3 \n"
6141+#else
6142+ " dsubu %0, %1, %3 \n"
6143+#endif
6144+ " scd %0, %2 \n"
6145+ " bnez %0, 4f \n"
6146+ " b 1b \n"
6147+#ifdef CONFIG_PAX_REFCOUNT
6148+ " .set noreorder \n"
6149+ "3: b 5f \n"
6150+ " move %0, %1 \n"
6151+ " .set reorder \n"
6152+ _ASM_EXTABLE(2b, 3b)
6153+#endif
6154+ "4: dsubu %0, %1, %3 \n"
6155+#ifdef CONFIG_PAX_REFCOUNT
6156+ "5: \n"
6157+#endif
6158+ " .set mips0 \n"
6159+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6160+ : "Ir" (i), "m" (v->counter)
6161+ : "memory");
6162+ } else {
6163+ unsigned long flags;
6164+
6165+ raw_local_irq_save(flags);
6166+ __asm__ __volatile__(
6167+ " ld %0, %1 \n"
6168+#ifdef CONFIG_PAX_REFCOUNT
6169+ /* Exception on overflow. */
6170+ "1: dsub %0, %2 \n"
6171+#else
6172+ " dsubu %0, %2 \n"
6173+#endif
6174+ " sd %0, %1 \n"
6175+#ifdef CONFIG_PAX_REFCOUNT
6176+ /* Note: Dest reg is not modified on overflow */
6177+ "2: \n"
6178+ _ASM_EXTABLE(1b, 2b)
6179+#endif
6180+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6181+ raw_local_irq_restore(flags);
6182+ }
6183+
6184+ smp_llsc_mb();
6185+
6186+ return result;
6187+}
6188+
6189+static __inline__ long atomic64_sub_return_unchecked(long i, atomic64_unchecked_t *v)
6190 {
6191 long result;
6192
6193@@ -605,7 +1274,7 @@ static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
6194 * Atomically test @v and subtract @i if @v is greater or equal than @i.
6195 * The function returns the old value of @v minus @i.
6196 */
6197-static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6198+static __inline__ long atomic64_sub_if_positive(long i, atomic64_t *v)
6199 {
6200 long result;
6201
6202@@ -662,9 +1331,26 @@ static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6203 return result;
6204 }
6205
6206-#define atomic64_cmpxchg(v, o, n) \
6207- ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
6208-#define atomic64_xchg(v, new) (xchg(&((v)->counter), (new)))
6209+static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
6210+{
6211+ return cmpxchg(&v->counter, old, new);
6212+}
6213+
6214+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old,
6215+ long new)
6216+{
6217+ return cmpxchg(&(v->counter), old, new);
6218+}
6219+
6220+static inline long atomic64_xchg(atomic64_t *v, long new)
6221+{
6222+ return xchg(&v->counter, new);
6223+}
6224+
6225+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
6226+{
6227+ return xchg(&(v->counter), new);
6228+}
6229
6230 /**
6231 * atomic64_add_unless - add unless the number is a given value
6232@@ -694,6 +1380,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6233
6234 #define atomic64_dec_return(v) atomic64_sub_return(1, (v))
6235 #define atomic64_inc_return(v) atomic64_add_return(1, (v))
6236+#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1, (v))
6237
6238 /*
6239 * atomic64_sub_and_test - subtract value from variable and test result
6240@@ -715,6 +1402,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6241 * other cases.
6242 */
6243 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
6244+#define atomic64_inc_and_test_unchecked(v) atomic64_add_return_unchecked(1, (v)) == 0)
6245
6246 /*
6247 * atomic64_dec_and_test - decrement by 1 and test
6248@@ -739,6 +1427,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6249 * Atomically increments @v by 1.
6250 */
6251 #define atomic64_inc(v) atomic64_add(1, (v))
6252+#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1, (v))
6253
6254 /*
6255 * atomic64_dec - decrement and test
6256@@ -747,6 +1436,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6257 * Atomically decrements @v by 1.
6258 */
6259 #define atomic64_dec(v) atomic64_sub(1, (v))
6260+#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1, (v))
6261
6262 /*
6263 * atomic64_add_negative - add and test if negative
6264diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
6265index b4db69f..8f3b093 100644
6266--- a/arch/mips/include/asm/cache.h
6267+++ b/arch/mips/include/asm/cache.h
6268@@ -9,10 +9,11 @@
6269 #ifndef _ASM_CACHE_H
6270 #define _ASM_CACHE_H
6271
6272+#include <linux/const.h>
6273 #include <kmalloc.h>
6274
6275 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
6276-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6277+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6278
6279 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
6280 #define SMP_CACHE_BYTES L1_CACHE_BYTES
6281diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
6282index cf3ae24..238d22f 100644
6283--- a/arch/mips/include/asm/elf.h
6284+++ b/arch/mips/include/asm/elf.h
6285@@ -372,13 +372,16 @@ extern const char *__elf_platform;
6286 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
6287 #endif
6288
6289+#ifdef CONFIG_PAX_ASLR
6290+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6291+
6292+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6293+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6294+#endif
6295+
6296 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
6297 struct linux_binprm;
6298 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
6299 int uses_interp);
6300
6301-struct mm_struct;
6302-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
6303-#define arch_randomize_brk arch_randomize_brk
6304-
6305 #endif /* _ASM_ELF_H */
6306diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
6307index c1f6afa..38cc6e9 100644
6308--- a/arch/mips/include/asm/exec.h
6309+++ b/arch/mips/include/asm/exec.h
6310@@ -12,6 +12,6 @@
6311 #ifndef _ASM_EXEC_H
6312 #define _ASM_EXEC_H
6313
6314-extern unsigned long arch_align_stack(unsigned long sp);
6315+#define arch_align_stack(x) ((x) & ~0xfUL)
6316
6317 #endif /* _ASM_EXEC_H */
6318diff --git a/arch/mips/include/asm/local.h b/arch/mips/include/asm/local.h
6319index d44622c..64990d2 100644
6320--- a/arch/mips/include/asm/local.h
6321+++ b/arch/mips/include/asm/local.h
6322@@ -12,15 +12,25 @@ typedef struct
6323 atomic_long_t a;
6324 } local_t;
6325
6326+typedef struct {
6327+ atomic_long_unchecked_t a;
6328+} local_unchecked_t;
6329+
6330 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
6331
6332 #define local_read(l) atomic_long_read(&(l)->a)
6333+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
6334 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
6335+#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
6336
6337 #define local_add(i, l) atomic_long_add((i), (&(l)->a))
6338+#define local_add_unchecked(i, l) atomic_long_add_unchecked((i), (&(l)->a))
6339 #define local_sub(i, l) atomic_long_sub((i), (&(l)->a))
6340+#define local_sub_unchecked(i, l) atomic_long_sub_unchecked((i), (&(l)->a))
6341 #define local_inc(l) atomic_long_inc(&(l)->a)
6342+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
6343 #define local_dec(l) atomic_long_dec(&(l)->a)
6344+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
6345
6346 /*
6347 * Same as above, but return the result value
6348@@ -70,6 +80,51 @@ static __inline__ long local_add_return(long i, local_t * l)
6349 return result;
6350 }
6351
6352+static __inline__ long local_add_return_unchecked(long i, local_unchecked_t * l)
6353+{
6354+ unsigned long result;
6355+
6356+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6357+ unsigned long temp;
6358+
6359+ __asm__ __volatile__(
6360+ " .set mips3 \n"
6361+ "1:" __LL "%1, %2 # local_add_return \n"
6362+ " addu %0, %1, %3 \n"
6363+ __SC "%0, %2 \n"
6364+ " beqzl %0, 1b \n"
6365+ " addu %0, %1, %3 \n"
6366+ " .set mips0 \n"
6367+ : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6368+ : "Ir" (i), "m" (l->a.counter)
6369+ : "memory");
6370+ } else if (kernel_uses_llsc) {
6371+ unsigned long temp;
6372+
6373+ __asm__ __volatile__(
6374+ " .set mips3 \n"
6375+ "1:" __LL "%1, %2 # local_add_return \n"
6376+ " addu %0, %1, %3 \n"
6377+ __SC "%0, %2 \n"
6378+ " beqz %0, 1b \n"
6379+ " addu %0, %1, %3 \n"
6380+ " .set mips0 \n"
6381+ : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6382+ : "Ir" (i), "m" (l->a.counter)
6383+ : "memory");
6384+ } else {
6385+ unsigned long flags;
6386+
6387+ local_irq_save(flags);
6388+ result = l->a.counter;
6389+ result += i;
6390+ l->a.counter = result;
6391+ local_irq_restore(flags);
6392+ }
6393+
6394+ return result;
6395+}
6396+
6397 static __inline__ long local_sub_return(long i, local_t * l)
6398 {
6399 unsigned long result;
6400@@ -117,6 +172,8 @@ static __inline__ long local_sub_return(long i, local_t * l)
6401
6402 #define local_cmpxchg(l, o, n) \
6403 ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6404+#define local_cmpxchg_unchecked(l, o, n) \
6405+ ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6406 #define local_xchg(l, n) (atomic_long_xchg((&(l)->a), (n)))
6407
6408 /**
6409diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
6410index f6be474..12ad554 100644
6411--- a/arch/mips/include/asm/page.h
6412+++ b/arch/mips/include/asm/page.h
6413@@ -95,7 +95,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
6414 #ifdef CONFIG_CPU_MIPS32
6415 typedef struct { unsigned long pte_low, pte_high; } pte_t;
6416 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
6417- #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
6418+ #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
6419 #else
6420 typedef struct { unsigned long long pte; } pte_t;
6421 #define pte_val(x) ((x).pte)
6422diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
6423index 881d18b..cea38bc 100644
6424--- a/arch/mips/include/asm/pgalloc.h
6425+++ b/arch/mips/include/asm/pgalloc.h
6426@@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6427 {
6428 set_pud(pud, __pud((unsigned long)pmd));
6429 }
6430+
6431+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6432+{
6433+ pud_populate(mm, pud, pmd);
6434+}
6435 #endif
6436
6437 /*
6438diff --git a/arch/mips/include/asm/smtc_proc.h b/arch/mips/include/asm/smtc_proc.h
6439index 25da651..ae2a259 100644
6440--- a/arch/mips/include/asm/smtc_proc.h
6441+++ b/arch/mips/include/asm/smtc_proc.h
6442@@ -18,6 +18,6 @@ extern struct smtc_cpu_proc smtc_cpu_stats[NR_CPUS];
6443
6444 /* Count of number of recoveries of "stolen" FPU access rights on 34K */
6445
6446-extern atomic_t smtc_fpu_recoveries;
6447+extern atomic_unchecked_t smtc_fpu_recoveries;
6448
6449 #endif /* __ASM_SMTC_PROC_H */
6450diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
6451index 61215a3..213ee0e 100644
6452--- a/arch/mips/include/asm/thread_info.h
6453+++ b/arch/mips/include/asm/thread_info.h
6454@@ -116,6 +116,8 @@ static inline struct thread_info *current_thread_info(void)
6455 #define TIF_32BIT_ADDR 23 /* 32-bit address space (o32/n32) */
6456 #define TIF_FPUBOUND 24 /* thread bound to FPU-full CPU set */
6457 #define TIF_LOAD_WATCH 25 /* If set, load watch registers */
6458+/* li takes a 32bit immediate */
6459+#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
6460 #define TIF_SYSCALL_TRACE 31 /* syscall trace active */
6461
6462 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
6463@@ -132,20 +134,18 @@ static inline struct thread_info *current_thread_info(void)
6464 #define _TIF_32BIT_ADDR (1<<TIF_32BIT_ADDR)
6465 #define _TIF_FPUBOUND (1<<TIF_FPUBOUND)
6466 #define _TIF_LOAD_WATCH (1<<TIF_LOAD_WATCH)
6467+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
6468
6469-#define _TIF_WORK_SYSCALL_ENTRY (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6470- _TIF_SYSCALL_AUDIT)
6471+#define _TIF_WORK_SYSCALL_ENTRY (_TIF_NOHZ | _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
6472
6473 /* work to do in syscall_trace_leave() */
6474-#define _TIF_WORK_SYSCALL_EXIT (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6475- _TIF_SYSCALL_AUDIT)
6476+#define _TIF_WORK_SYSCALL_EXIT (_TIF_NOHZ | _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
6477
6478 /* work to do on interrupt/exception return */
6479 #define _TIF_WORK_MASK \
6480 (_TIF_SIGPENDING | _TIF_NEED_RESCHED | _TIF_NOTIFY_RESUME)
6481 /* work to do on any return to u-space */
6482-#define _TIF_ALLWORK_MASK (_TIF_NOHZ | _TIF_WORK_MASK | \
6483- _TIF_WORK_SYSCALL_EXIT)
6484+#define _TIF_ALLWORK_MASK (_TIF_NOHZ | _TIF_WORK_MASK | _TIF_WORK_SYSCALL_EXIT | _TIF_GRSEC_SETXID)
6485
6486 #endif /* __KERNEL__ */
6487
6488diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
6489index 1188e00..41cf144 100644
6490--- a/arch/mips/kernel/binfmt_elfn32.c
6491+++ b/arch/mips/kernel/binfmt_elfn32.c
6492@@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
6493 #undef ELF_ET_DYN_BASE
6494 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
6495
6496+#ifdef CONFIG_PAX_ASLR
6497+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6498+
6499+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6500+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6501+#endif
6502+
6503 #include <asm/processor.h>
6504 #include <linux/module.h>
6505 #include <linux/elfcore.h>
6506diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
6507index 202e581..689ca79 100644
6508--- a/arch/mips/kernel/binfmt_elfo32.c
6509+++ b/arch/mips/kernel/binfmt_elfo32.c
6510@@ -56,6 +56,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
6511 #undef ELF_ET_DYN_BASE
6512 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
6513
6514+#ifdef CONFIG_PAX_ASLR
6515+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6516+
6517+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6518+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6519+#endif
6520+
6521 #include <asm/processor.h>
6522
6523 /*
6524diff --git a/arch/mips/kernel/irq.c b/arch/mips/kernel/irq.c
6525index d1fea7a..45602ea 100644
6526--- a/arch/mips/kernel/irq.c
6527+++ b/arch/mips/kernel/irq.c
6528@@ -77,17 +77,17 @@ void ack_bad_irq(unsigned int irq)
6529 printk("unexpected IRQ # %d\n", irq);
6530 }
6531
6532-atomic_t irq_err_count;
6533+atomic_unchecked_t irq_err_count;
6534
6535 int arch_show_interrupts(struct seq_file *p, int prec)
6536 {
6537- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
6538+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
6539 return 0;
6540 }
6541
6542 asmlinkage void spurious_interrupt(void)
6543 {
6544- atomic_inc(&irq_err_count);
6545+ atomic_inc_unchecked(&irq_err_count);
6546 }
6547
6548 void __init init_IRQ(void)
6549diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
6550index ddc7610..8c58f17 100644
6551--- a/arch/mips/kernel/process.c
6552+++ b/arch/mips/kernel/process.c
6553@@ -566,15 +566,3 @@ unsigned long get_wchan(struct task_struct *task)
6554 out:
6555 return pc;
6556 }
6557-
6558-/*
6559- * Don't forget that the stack pointer must be aligned on a 8 bytes
6560- * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
6561- */
6562-unsigned long arch_align_stack(unsigned long sp)
6563-{
6564- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
6565- sp -= get_random_int() & ~PAGE_MASK;
6566-
6567- return sp & ALMASK;
6568-}
6569diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
6570index 8ae1ebe..1bcbf47 100644
6571--- a/arch/mips/kernel/ptrace.c
6572+++ b/arch/mips/kernel/ptrace.c
6573@@ -529,6 +529,10 @@ static inline int audit_arch(void)
6574 return arch;
6575 }
6576
6577+#ifdef CONFIG_GRKERNSEC_SETXID
6578+extern void gr_delayed_cred_worker(void);
6579+#endif
6580+
6581 /*
6582 * Notification of system call entry/exit
6583 * - triggered by current->work.syscall_trace
6584@@ -540,6 +544,11 @@ asmlinkage void syscall_trace_enter(struct pt_regs *regs)
6585 /* do the secure computing check first */
6586 secure_computing_strict(regs->regs[2]);
6587
6588+#ifdef CONFIG_GRKERNSEC_SETXID
6589+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6590+ gr_delayed_cred_worker();
6591+#endif
6592+
6593 if (!(current->ptrace & PT_PTRACED))
6594 goto out;
6595
6596diff --git a/arch/mips/kernel/smtc-proc.c b/arch/mips/kernel/smtc-proc.c
6597index c10aa84..9ec2e60 100644
6598--- a/arch/mips/kernel/smtc-proc.c
6599+++ b/arch/mips/kernel/smtc-proc.c
6600@@ -31,7 +31,7 @@ unsigned long selfipis[NR_CPUS];
6601
6602 struct smtc_cpu_proc smtc_cpu_stats[NR_CPUS];
6603
6604-atomic_t smtc_fpu_recoveries;
6605+atomic_unchecked_t smtc_fpu_recoveries;
6606
6607 static int smtc_proc_show(struct seq_file *m, void *v)
6608 {
6609@@ -48,7 +48,7 @@ static int smtc_proc_show(struct seq_file *m, void *v)
6610 for(i = 0; i < NR_CPUS; i++)
6611 seq_printf(m, "%d: %ld\n", i, smtc_cpu_stats[i].selfipis);
6612 seq_printf(m, "%d Recoveries of \"stolen\" FPU\n",
6613- atomic_read(&smtc_fpu_recoveries));
6614+ atomic_read_unchecked(&smtc_fpu_recoveries));
6615 return 0;
6616 }
6617
6618@@ -73,7 +73,7 @@ void init_smtc_stats(void)
6619 smtc_cpu_stats[i].selfipis = 0;
6620 }
6621
6622- atomic_set(&smtc_fpu_recoveries, 0);
6623+ atomic_set_unchecked(&smtc_fpu_recoveries, 0);
6624
6625 proc_create("smtc", 0444, NULL, &smtc_proc_fops);
6626 }
6627diff --git a/arch/mips/kernel/smtc.c b/arch/mips/kernel/smtc.c
6628index dfc1b91..11a2c07 100644
6629--- a/arch/mips/kernel/smtc.c
6630+++ b/arch/mips/kernel/smtc.c
6631@@ -1359,7 +1359,7 @@ void smtc_soft_dump(void)
6632 }
6633 smtc_ipi_qdump();
6634 printk("%d Recoveries of \"stolen\" FPU\n",
6635- atomic_read(&smtc_fpu_recoveries));
6636+ atomic_read_unchecked(&smtc_fpu_recoveries));
6637 }
6638
6639
6640diff --git a/arch/mips/kernel/sync-r4k.c b/arch/mips/kernel/sync-r4k.c
6641index 84536bf..79caa4d 100644
6642--- a/arch/mips/kernel/sync-r4k.c
6643+++ b/arch/mips/kernel/sync-r4k.c
6644@@ -21,8 +21,8 @@
6645 #include <asm/mipsregs.h>
6646
6647 static atomic_t count_start_flag = ATOMIC_INIT(0);
6648-static atomic_t count_count_start = ATOMIC_INIT(0);
6649-static atomic_t count_count_stop = ATOMIC_INIT(0);
6650+static atomic_unchecked_t count_count_start = ATOMIC_INIT(0);
6651+static atomic_unchecked_t count_count_stop = ATOMIC_INIT(0);
6652 static atomic_t count_reference = ATOMIC_INIT(0);
6653
6654 #define COUNTON 100
6655@@ -69,13 +69,13 @@ void synchronise_count_master(int cpu)
6656
6657 for (i = 0; i < NR_LOOPS; i++) {
6658 /* slaves loop on '!= 2' */
6659- while (atomic_read(&count_count_start) != 1)
6660+ while (atomic_read_unchecked(&count_count_start) != 1)
6661 mb();
6662- atomic_set(&count_count_stop, 0);
6663+ atomic_set_unchecked(&count_count_stop, 0);
6664 smp_wmb();
6665
6666 /* this lets the slaves write their count register */
6667- atomic_inc(&count_count_start);
6668+ atomic_inc_unchecked(&count_count_start);
6669
6670 /*
6671 * Everyone initialises count in the last loop:
6672@@ -86,11 +86,11 @@ void synchronise_count_master(int cpu)
6673 /*
6674 * Wait for all slaves to leave the synchronization point:
6675 */
6676- while (atomic_read(&count_count_stop) != 1)
6677+ while (atomic_read_unchecked(&count_count_stop) != 1)
6678 mb();
6679- atomic_set(&count_count_start, 0);
6680+ atomic_set_unchecked(&count_count_start, 0);
6681 smp_wmb();
6682- atomic_inc(&count_count_stop);
6683+ atomic_inc_unchecked(&count_count_stop);
6684 }
6685 /* Arrange for an interrupt in a short while */
6686 write_c0_compare(read_c0_count() + COUNTON);
6687@@ -131,8 +131,8 @@ void synchronise_count_slave(int cpu)
6688 initcount = atomic_read(&count_reference);
6689
6690 for (i = 0; i < NR_LOOPS; i++) {
6691- atomic_inc(&count_count_start);
6692- while (atomic_read(&count_count_start) != 2)
6693+ atomic_inc_unchecked(&count_count_start);
6694+ while (atomic_read_unchecked(&count_count_start) != 2)
6695 mb();
6696
6697 /*
6698@@ -141,8 +141,8 @@ void synchronise_count_slave(int cpu)
6699 if (i == NR_LOOPS-1)
6700 write_c0_count(initcount);
6701
6702- atomic_inc(&count_count_stop);
6703- while (atomic_read(&count_count_stop) != 2)
6704+ atomic_inc_unchecked(&count_count_stop);
6705+ while (atomic_read_unchecked(&count_count_stop) != 2)
6706 mb();
6707 }
6708 /* Arrange for an interrupt in a short while */
6709diff --git a/arch/mips/kernel/traps.c b/arch/mips/kernel/traps.c
6710index 524841f..3eef41e 100644
6711--- a/arch/mips/kernel/traps.c
6712+++ b/arch/mips/kernel/traps.c
6713@@ -684,7 +684,18 @@ asmlinkage void do_ov(struct pt_regs *regs)
6714 siginfo_t info;
6715
6716 prev_state = exception_enter();
6717- die_if_kernel("Integer overflow", regs);
6718+ if (unlikely(!user_mode(regs))) {
6719+
6720+#ifdef CONFIG_PAX_REFCOUNT
6721+ if (fixup_exception(regs)) {
6722+ pax_report_refcount_overflow(regs);
6723+ exception_exit(prev_state);
6724+ return;
6725+ }
6726+#endif
6727+
6728+ die("Integer overflow", regs);
6729+ }
6730
6731 info.si_code = FPE_INTOVF;
6732 info.si_signo = SIGFPE;
6733diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
6734index becc42b..9e43d4b 100644
6735--- a/arch/mips/mm/fault.c
6736+++ b/arch/mips/mm/fault.c
6737@@ -28,6 +28,23 @@
6738 #include <asm/highmem.h> /* For VMALLOC_END */
6739 #include <linux/kdebug.h>
6740
6741+#ifdef CONFIG_PAX_PAGEEXEC
6742+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6743+{
6744+ unsigned long i;
6745+
6746+ printk(KERN_ERR "PAX: bytes at PC: ");
6747+ for (i = 0; i < 5; i++) {
6748+ unsigned int c;
6749+ if (get_user(c, (unsigned int *)pc+i))
6750+ printk(KERN_CONT "???????? ");
6751+ else
6752+ printk(KERN_CONT "%08x ", c);
6753+ }
6754+ printk("\n");
6755+}
6756+#endif
6757+
6758 /*
6759 * This routine handles page faults. It determines the address,
6760 * and the problem, and then passes it off to one of the appropriate
6761@@ -199,6 +216,14 @@ bad_area:
6762 bad_area_nosemaphore:
6763 /* User mode accesses just cause a SIGSEGV */
6764 if (user_mode(regs)) {
6765+
6766+#ifdef CONFIG_PAX_PAGEEXEC
6767+ if (cpu_has_rixi && (mm->pax_flags & MF_PAX_PAGEEXEC) && !write && address == instruction_pointer(regs)) {
6768+ pax_report_fault(regs, (void *)address, (void *)user_stack_pointer(regs));
6769+ do_group_exit(SIGKILL);
6770+ }
6771+#endif
6772+
6773 tsk->thread.cp0_badvaddr = address;
6774 tsk->thread.error_code = write;
6775 #if 0
6776diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
6777index f1baadd..8537544 100644
6778--- a/arch/mips/mm/mmap.c
6779+++ b/arch/mips/mm/mmap.c
6780@@ -59,6 +59,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
6781 struct vm_area_struct *vma;
6782 unsigned long addr = addr0;
6783 int do_color_align;
6784+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
6785 struct vm_unmapped_area_info info;
6786
6787 if (unlikely(len > TASK_SIZE))
6788@@ -84,6 +85,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
6789 do_color_align = 1;
6790
6791 /* requesting a specific address */
6792+
6793+#ifdef CONFIG_PAX_RANDMMAP
6794+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
6795+#endif
6796+
6797 if (addr) {
6798 if (do_color_align)
6799 addr = COLOUR_ALIGN(addr, pgoff);
6800@@ -91,14 +97,14 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
6801 addr = PAGE_ALIGN(addr);
6802
6803 vma = find_vma(mm, addr);
6804- if (TASK_SIZE - len >= addr &&
6805- (!vma || addr + len <= vma->vm_start))
6806+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vmm, addr, len, offset))
6807 return addr;
6808 }
6809
6810 info.length = len;
6811 info.align_mask = do_color_align ? (PAGE_MASK & shm_align_mask) : 0;
6812 info.align_offset = pgoff << PAGE_SHIFT;
6813+ info.threadstack_offset = offset;
6814
6815 if (dir == DOWN) {
6816 info.flags = VM_UNMAPPED_AREA_TOPDOWN;
6817@@ -146,6 +152,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
6818 {
6819 unsigned long random_factor = 0UL;
6820
6821+#ifdef CONFIG_PAX_RANDMMAP
6822+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
6823+#endif
6824+
6825 if (current->flags & PF_RANDOMIZE) {
6826 random_factor = get_random_int();
6827 random_factor = random_factor << PAGE_SHIFT;
6828@@ -157,40 +167,25 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
6829
6830 if (mmap_is_legacy()) {
6831 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
6832+
6833+#ifdef CONFIG_PAX_RANDMMAP
6834+ if (mm->pax_flags & MF_PAX_RANDMMAP)
6835+ mm->mmap_base += mm->delta_mmap;
6836+#endif
6837+
6838 mm->get_unmapped_area = arch_get_unmapped_area;
6839 } else {
6840 mm->mmap_base = mmap_base(random_factor);
6841+
6842+#ifdef CONFIG_PAX_RANDMMAP
6843+ if (mm->pax_flags & MF_PAX_RANDMMAP)
6844+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
6845+#endif
6846+
6847 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
6848 }
6849 }
6850
6851-static inline unsigned long brk_rnd(void)
6852-{
6853- unsigned long rnd = get_random_int();
6854-
6855- rnd = rnd << PAGE_SHIFT;
6856- /* 8MB for 32bit, 256MB for 64bit */
6857- if (TASK_IS_32BIT_ADDR)
6858- rnd = rnd & 0x7ffffful;
6859- else
6860- rnd = rnd & 0xffffffful;
6861-
6862- return rnd;
6863-}
6864-
6865-unsigned long arch_randomize_brk(struct mm_struct *mm)
6866-{
6867- unsigned long base = mm->brk;
6868- unsigned long ret;
6869-
6870- ret = PAGE_ALIGN(base + brk_rnd());
6871-
6872- if (ret < mm->brk)
6873- return mm->brk;
6874-
6875- return ret;
6876-}
6877-
6878 int __virt_addr_valid(const volatile void *kaddr)
6879 {
6880 return pfn_valid(PFN_DOWN(virt_to_phys(kaddr)));
6881diff --git a/arch/mips/sgi-ip27/ip27-nmi.c b/arch/mips/sgi-ip27/ip27-nmi.c
6882index a2358b4..7cead4f 100644
6883--- a/arch/mips/sgi-ip27/ip27-nmi.c
6884+++ b/arch/mips/sgi-ip27/ip27-nmi.c
6885@@ -187,9 +187,9 @@ void
6886 cont_nmi_dump(void)
6887 {
6888 #ifndef REAL_NMI_SIGNAL
6889- static atomic_t nmied_cpus = ATOMIC_INIT(0);
6890+ static atomic_unchecked_t nmied_cpus = ATOMIC_INIT(0);
6891
6892- atomic_inc(&nmied_cpus);
6893+ atomic_inc_unchecked(&nmied_cpus);
6894 #endif
6895 /*
6896 * Only allow 1 cpu to proceed
6897@@ -233,7 +233,7 @@ cont_nmi_dump(void)
6898 udelay(10000);
6899 }
6900 #else
6901- while (atomic_read(&nmied_cpus) != num_online_cpus());
6902+ while (atomic_read_unchecked(&nmied_cpus) != num_online_cpus());
6903 #endif
6904
6905 /*
6906diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
6907index 967d144..db12197 100644
6908--- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
6909+++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
6910@@ -11,12 +11,14 @@
6911 #ifndef _ASM_PROC_CACHE_H
6912 #define _ASM_PROC_CACHE_H
6913
6914+#include <linux/const.h>
6915+
6916 /* L1 cache */
6917
6918 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
6919 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
6920-#define L1_CACHE_BYTES 16 /* bytes per entry */
6921 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
6922+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
6923 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
6924
6925 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
6926diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
6927index bcb5df2..84fabd2 100644
6928--- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
6929+++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
6930@@ -16,13 +16,15 @@
6931 #ifndef _ASM_PROC_CACHE_H
6932 #define _ASM_PROC_CACHE_H
6933
6934+#include <linux/const.h>
6935+
6936 /*
6937 * L1 cache
6938 */
6939 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
6940 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
6941-#define L1_CACHE_BYTES 32 /* bytes per entry */
6942 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
6943+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
6944 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
6945
6946 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
6947diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
6948index 4ce7a01..449202a 100644
6949--- a/arch/openrisc/include/asm/cache.h
6950+++ b/arch/openrisc/include/asm/cache.h
6951@@ -19,11 +19,13 @@
6952 #ifndef __ASM_OPENRISC_CACHE_H
6953 #define __ASM_OPENRISC_CACHE_H
6954
6955+#include <linux/const.h>
6956+
6957 /* FIXME: How can we replace these with values from the CPU...
6958 * they shouldn't be hard-coded!
6959 */
6960
6961-#define L1_CACHE_BYTES 16
6962 #define L1_CACHE_SHIFT 4
6963+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6964
6965 #endif /* __ASM_OPENRISC_CACHE_H */
6966diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
6967index 472886c..00e7df9 100644
6968--- a/arch/parisc/include/asm/atomic.h
6969+++ b/arch/parisc/include/asm/atomic.h
6970@@ -252,6 +252,16 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
6971 return dec;
6972 }
6973
6974+#define atomic64_read_unchecked(v) atomic64_read(v)
6975+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
6976+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
6977+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
6978+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
6979+#define atomic64_inc_unchecked(v) atomic64_inc(v)
6980+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
6981+#define atomic64_dec_unchecked(v) atomic64_dec(v)
6982+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
6983+
6984 #endif /* !CONFIG_64BIT */
6985
6986
6987diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
6988index 47f11c7..3420df2 100644
6989--- a/arch/parisc/include/asm/cache.h
6990+++ b/arch/parisc/include/asm/cache.h
6991@@ -5,6 +5,7 @@
6992 #ifndef __ARCH_PARISC_CACHE_H
6993 #define __ARCH_PARISC_CACHE_H
6994
6995+#include <linux/const.h>
6996
6997 /*
6998 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
6999@@ -15,13 +16,13 @@
7000 * just ruin performance.
7001 */
7002 #ifdef CONFIG_PA20
7003-#define L1_CACHE_BYTES 64
7004 #define L1_CACHE_SHIFT 6
7005 #else
7006-#define L1_CACHE_BYTES 32
7007 #define L1_CACHE_SHIFT 5
7008 #endif
7009
7010+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7011+
7012 #ifndef __ASSEMBLY__
7013
7014 #define SMP_CACHE_BYTES L1_CACHE_BYTES
7015diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
7016index ad2b503..bdf1651 100644
7017--- a/arch/parisc/include/asm/elf.h
7018+++ b/arch/parisc/include/asm/elf.h
7019@@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
7020
7021 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
7022
7023+#ifdef CONFIG_PAX_ASLR
7024+#define PAX_ELF_ET_DYN_BASE 0x10000UL
7025+
7026+#define PAX_DELTA_MMAP_LEN 16
7027+#define PAX_DELTA_STACK_LEN 16
7028+#endif
7029+
7030 /* This yields a mask that user programs can use to figure out what
7031 instruction set this CPU supports. This could be done in user space,
7032 but it's not easy, and we've already done it here. */
7033diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
7034index fc987a1..6e068ef 100644
7035--- a/arch/parisc/include/asm/pgalloc.h
7036+++ b/arch/parisc/include/asm/pgalloc.h
7037@@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7038 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
7039 }
7040
7041+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7042+{
7043+ pgd_populate(mm, pgd, pmd);
7044+}
7045+
7046 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
7047 {
7048 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
7049@@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
7050 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
7051 #define pmd_free(mm, x) do { } while (0)
7052 #define pgd_populate(mm, pmd, pte) BUG()
7053+#define pgd_populate_kernel(mm, pmd, pte) BUG()
7054
7055 #endif
7056
7057diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
7058index 34899b5..02dd060 100644
7059--- a/arch/parisc/include/asm/pgtable.h
7060+++ b/arch/parisc/include/asm/pgtable.h
7061@@ -223,6 +223,17 @@ extern void purge_tlb_entries(struct mm_struct *, unsigned long);
7062 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
7063 #define PAGE_COPY PAGE_EXECREAD
7064 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
7065+
7066+#ifdef CONFIG_PAX_PAGEEXEC
7067+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
7068+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7069+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7070+#else
7071+# define PAGE_SHARED_NOEXEC PAGE_SHARED
7072+# define PAGE_COPY_NOEXEC PAGE_COPY
7073+# define PAGE_READONLY_NOEXEC PAGE_READONLY
7074+#endif
7075+
7076 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
7077 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
7078 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
7079diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
7080index e0a8235..ce2f1e1 100644
7081--- a/arch/parisc/include/asm/uaccess.h
7082+++ b/arch/parisc/include/asm/uaccess.h
7083@@ -245,10 +245,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
7084 const void __user *from,
7085 unsigned long n)
7086 {
7087- int sz = __compiletime_object_size(to);
7088+ size_t sz = __compiletime_object_size(to);
7089 int ret = -EFAULT;
7090
7091- if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
7092+ if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
7093 ret = __copy_from_user(to, from, n);
7094 else
7095 copy_from_user_overflow();
7096diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
7097index 2a625fb..9908930 100644
7098--- a/arch/parisc/kernel/module.c
7099+++ b/arch/parisc/kernel/module.c
7100@@ -98,16 +98,38 @@
7101
7102 /* three functions to determine where in the module core
7103 * or init pieces the location is */
7104+static inline int in_init_rx(struct module *me, void *loc)
7105+{
7106+ return (loc >= me->module_init_rx &&
7107+ loc < (me->module_init_rx + me->init_size_rx));
7108+}
7109+
7110+static inline int in_init_rw(struct module *me, void *loc)
7111+{
7112+ return (loc >= me->module_init_rw &&
7113+ loc < (me->module_init_rw + me->init_size_rw));
7114+}
7115+
7116 static inline int in_init(struct module *me, void *loc)
7117 {
7118- return (loc >= me->module_init &&
7119- loc <= (me->module_init + me->init_size));
7120+ return in_init_rx(me, loc) || in_init_rw(me, loc);
7121+}
7122+
7123+static inline int in_core_rx(struct module *me, void *loc)
7124+{
7125+ return (loc >= me->module_core_rx &&
7126+ loc < (me->module_core_rx + me->core_size_rx));
7127+}
7128+
7129+static inline int in_core_rw(struct module *me, void *loc)
7130+{
7131+ return (loc >= me->module_core_rw &&
7132+ loc < (me->module_core_rw + me->core_size_rw));
7133 }
7134
7135 static inline int in_core(struct module *me, void *loc)
7136 {
7137- return (loc >= me->module_core &&
7138- loc <= (me->module_core + me->core_size));
7139+ return in_core_rx(me, loc) || in_core_rw(me, loc);
7140 }
7141
7142 static inline int in_local(struct module *me, void *loc)
7143@@ -371,13 +393,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
7144 }
7145
7146 /* align things a bit */
7147- me->core_size = ALIGN(me->core_size, 16);
7148- me->arch.got_offset = me->core_size;
7149- me->core_size += gots * sizeof(struct got_entry);
7150+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
7151+ me->arch.got_offset = me->core_size_rw;
7152+ me->core_size_rw += gots * sizeof(struct got_entry);
7153
7154- me->core_size = ALIGN(me->core_size, 16);
7155- me->arch.fdesc_offset = me->core_size;
7156- me->core_size += fdescs * sizeof(Elf_Fdesc);
7157+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
7158+ me->arch.fdesc_offset = me->core_size_rw;
7159+ me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
7160
7161 me->arch.got_max = gots;
7162 me->arch.fdesc_max = fdescs;
7163@@ -395,7 +417,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7164
7165 BUG_ON(value == 0);
7166
7167- got = me->module_core + me->arch.got_offset;
7168+ got = me->module_core_rw + me->arch.got_offset;
7169 for (i = 0; got[i].addr; i++)
7170 if (got[i].addr == value)
7171 goto out;
7172@@ -413,7 +435,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7173 #ifdef CONFIG_64BIT
7174 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7175 {
7176- Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
7177+ Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
7178
7179 if (!value) {
7180 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
7181@@ -431,7 +453,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7182
7183 /* Create new one */
7184 fdesc->addr = value;
7185- fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7186+ fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7187 return (Elf_Addr)fdesc;
7188 }
7189 #endif /* CONFIG_64BIT */
7190@@ -843,7 +865,7 @@ register_unwind_table(struct module *me,
7191
7192 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
7193 end = table + sechdrs[me->arch.unwind_section].sh_size;
7194- gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7195+ gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7196
7197 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
7198 me->arch.unwind_section, table, end, gp);
7199diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
7200index 5dfd248..64914ac 100644
7201--- a/arch/parisc/kernel/sys_parisc.c
7202+++ b/arch/parisc/kernel/sys_parisc.c
7203@@ -33,9 +33,11 @@
7204 #include <linux/utsname.h>
7205 #include <linux/personality.h>
7206
7207-static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
7208+static unsigned long get_unshared_area(struct file *filp, unsigned long addr, unsigned long len,
7209+ unsigned long flags)
7210 {
7211 struct vm_unmapped_area_info info;
7212+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
7213
7214 info.flags = 0;
7215 info.length = len;
7216@@ -43,6 +45,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
7217 info.high_limit = TASK_SIZE;
7218 info.align_mask = 0;
7219 info.align_offset = 0;
7220+ info.threadstack_offset = offset;
7221 return vm_unmapped_area(&info);
7222 }
7223
7224@@ -61,10 +64,11 @@ static int get_offset(struct address_space *mapping)
7225 return (unsigned long) mapping >> 8;
7226 }
7227
7228-static unsigned long get_shared_area(struct address_space *mapping,
7229- unsigned long addr, unsigned long len, unsigned long pgoff)
7230+static unsigned long get_shared_area(struct file *filp, struct address_space *mapping,
7231+ unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags)
7232 {
7233 struct vm_unmapped_area_info info;
7234+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
7235
7236 info.flags = 0;
7237 info.length = len;
7238@@ -72,6 +76,7 @@ static unsigned long get_shared_area(struct address_space *mapping,
7239 info.high_limit = TASK_SIZE;
7240 info.align_mask = PAGE_MASK & (SHMLBA - 1);
7241 info.align_offset = (get_offset(mapping) + pgoff) << PAGE_SHIFT;
7242+ info.threadstack_offset = offset;
7243 return vm_unmapped_area(&info);
7244 }
7245
7246@@ -86,15 +91,22 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7247 return -EINVAL;
7248 return addr;
7249 }
7250- if (!addr)
7251+ if (!addr) {
7252 addr = TASK_UNMAPPED_BASE;
7253
7254+#ifdef CONFIG_PAX_RANDMMAP
7255+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
7256+ addr += current->mm->delta_mmap;
7257+#endif
7258+
7259+ }
7260+
7261 if (filp) {
7262- addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
7263+ addr = get_shared_area(filp, filp->f_mapping, addr, len, pgoff, flags);
7264 } else if(flags & MAP_SHARED) {
7265- addr = get_shared_area(NULL, addr, len, pgoff);
7266+ addr = get_shared_area(filp, NULL, addr, len, pgoff, flags);
7267 } else {
7268- addr = get_unshared_area(addr, len);
7269+ addr = get_unshared_area(filp, addr, len, flags);
7270 }
7271 return addr;
7272 }
7273diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
7274index 1cd1d0c..44ec918 100644
7275--- a/arch/parisc/kernel/traps.c
7276+++ b/arch/parisc/kernel/traps.c
7277@@ -722,9 +722,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
7278
7279 down_read(&current->mm->mmap_sem);
7280 vma = find_vma(current->mm,regs->iaoq[0]);
7281- if (vma && (regs->iaoq[0] >= vma->vm_start)
7282- && (vma->vm_flags & VM_EXEC)) {
7283-
7284+ if (vma && (regs->iaoq[0] >= vma->vm_start)) {
7285 fault_address = regs->iaoq[0];
7286 fault_space = regs->iasq[0];
7287
7288diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
7289index 0293588..3b229aa 100644
7290--- a/arch/parisc/mm/fault.c
7291+++ b/arch/parisc/mm/fault.c
7292@@ -15,6 +15,7 @@
7293 #include <linux/sched.h>
7294 #include <linux/interrupt.h>
7295 #include <linux/module.h>
7296+#include <linux/unistd.h>
7297
7298 #include <asm/uaccess.h>
7299 #include <asm/traps.h>
7300@@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
7301 static unsigned long
7302 parisc_acctyp(unsigned long code, unsigned int inst)
7303 {
7304- if (code == 6 || code == 16)
7305+ if (code == 6 || code == 7 || code == 16)
7306 return VM_EXEC;
7307
7308 switch (inst & 0xf0000000) {
7309@@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
7310 }
7311 #endif
7312
7313+#ifdef CONFIG_PAX_PAGEEXEC
7314+/*
7315+ * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
7316+ *
7317+ * returns 1 when task should be killed
7318+ * 2 when rt_sigreturn trampoline was detected
7319+ * 3 when unpatched PLT trampoline was detected
7320+ */
7321+static int pax_handle_fetch_fault(struct pt_regs *regs)
7322+{
7323+
7324+#ifdef CONFIG_PAX_EMUPLT
7325+ int err;
7326+
7327+ do { /* PaX: unpatched PLT emulation */
7328+ unsigned int bl, depwi;
7329+
7330+ err = get_user(bl, (unsigned int *)instruction_pointer(regs));
7331+ err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
7332+
7333+ if (err)
7334+ break;
7335+
7336+ if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
7337+ unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
7338+
7339+ err = get_user(ldw, (unsigned int *)addr);
7340+ err |= get_user(bv, (unsigned int *)(addr+4));
7341+ err |= get_user(ldw2, (unsigned int *)(addr+8));
7342+
7343+ if (err)
7344+ break;
7345+
7346+ if (ldw == 0x0E801096U &&
7347+ bv == 0xEAC0C000U &&
7348+ ldw2 == 0x0E881095U)
7349+ {
7350+ unsigned int resolver, map;
7351+
7352+ err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
7353+ err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
7354+ if (err)
7355+ break;
7356+
7357+ regs->gr[20] = instruction_pointer(regs)+8;
7358+ regs->gr[21] = map;
7359+ regs->gr[22] = resolver;
7360+ regs->iaoq[0] = resolver | 3UL;
7361+ regs->iaoq[1] = regs->iaoq[0] + 4;
7362+ return 3;
7363+ }
7364+ }
7365+ } while (0);
7366+#endif
7367+
7368+#ifdef CONFIG_PAX_EMUTRAMP
7369+
7370+#ifndef CONFIG_PAX_EMUSIGRT
7371+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
7372+ return 1;
7373+#endif
7374+
7375+ do { /* PaX: rt_sigreturn emulation */
7376+ unsigned int ldi1, ldi2, bel, nop;
7377+
7378+ err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
7379+ err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
7380+ err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
7381+ err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
7382+
7383+ if (err)
7384+ break;
7385+
7386+ if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
7387+ ldi2 == 0x3414015AU &&
7388+ bel == 0xE4008200U &&
7389+ nop == 0x08000240U)
7390+ {
7391+ regs->gr[25] = (ldi1 & 2) >> 1;
7392+ regs->gr[20] = __NR_rt_sigreturn;
7393+ regs->gr[31] = regs->iaoq[1] + 16;
7394+ regs->sr[0] = regs->iasq[1];
7395+ regs->iaoq[0] = 0x100UL;
7396+ regs->iaoq[1] = regs->iaoq[0] + 4;
7397+ regs->iasq[0] = regs->sr[2];
7398+ regs->iasq[1] = regs->sr[2];
7399+ return 2;
7400+ }
7401+ } while (0);
7402+#endif
7403+
7404+ return 1;
7405+}
7406+
7407+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7408+{
7409+ unsigned long i;
7410+
7411+ printk(KERN_ERR "PAX: bytes at PC: ");
7412+ for (i = 0; i < 5; i++) {
7413+ unsigned int c;
7414+ if (get_user(c, (unsigned int *)pc+i))
7415+ printk(KERN_CONT "???????? ");
7416+ else
7417+ printk(KERN_CONT "%08x ", c);
7418+ }
7419+ printk("\n");
7420+}
7421+#endif
7422+
7423 int fixup_exception(struct pt_regs *regs)
7424 {
7425 const struct exception_table_entry *fix;
7426@@ -204,8 +315,33 @@ retry:
7427
7428 good_area:
7429
7430- if ((vma->vm_flags & acc_type) != acc_type)
7431+ if ((vma->vm_flags & acc_type) != acc_type) {
7432+
7433+#ifdef CONFIG_PAX_PAGEEXEC
7434+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
7435+ (address & ~3UL) == instruction_pointer(regs))
7436+ {
7437+ up_read(&mm->mmap_sem);
7438+ switch (pax_handle_fetch_fault(regs)) {
7439+
7440+#ifdef CONFIG_PAX_EMUPLT
7441+ case 3:
7442+ return;
7443+#endif
7444+
7445+#ifdef CONFIG_PAX_EMUTRAMP
7446+ case 2:
7447+ return;
7448+#endif
7449+
7450+ }
7451+ pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
7452+ do_group_exit(SIGKILL);
7453+ }
7454+#endif
7455+
7456 goto bad_area;
7457+ }
7458
7459 /*
7460 * If for any reason at all we couldn't handle the fault, make
7461diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
7462index e3b1d41..8e81edf 100644
7463--- a/arch/powerpc/include/asm/atomic.h
7464+++ b/arch/powerpc/include/asm/atomic.h
7465@@ -523,6 +523,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
7466 return t1;
7467 }
7468
7469+#define atomic64_read_unchecked(v) atomic64_read(v)
7470+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7471+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7472+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7473+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7474+#define atomic64_inc_unchecked(v) atomic64_inc(v)
7475+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7476+#define atomic64_dec_unchecked(v) atomic64_dec(v)
7477+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7478+
7479 #endif /* __powerpc64__ */
7480
7481 #endif /* __KERNEL__ */
7482diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
7483index 9e495c9..b6878e5 100644
7484--- a/arch/powerpc/include/asm/cache.h
7485+++ b/arch/powerpc/include/asm/cache.h
7486@@ -3,6 +3,7 @@
7487
7488 #ifdef __KERNEL__
7489
7490+#include <linux/const.h>
7491
7492 /* bytes per L1 cache line */
7493 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
7494@@ -22,7 +23,7 @@
7495 #define L1_CACHE_SHIFT 7
7496 #endif
7497
7498-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7499+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7500
7501 #define SMP_CACHE_BYTES L1_CACHE_BYTES
7502
7503diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
7504index cc0655a..13eac2e 100644
7505--- a/arch/powerpc/include/asm/elf.h
7506+++ b/arch/powerpc/include/asm/elf.h
7507@@ -28,8 +28,19 @@
7508 the loader. We need to make sure that it is out of the way of the program
7509 that it will "exec", and that there is sufficient room for the brk. */
7510
7511-extern unsigned long randomize_et_dyn(unsigned long base);
7512-#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
7513+#define ELF_ET_DYN_BASE (0x20000000)
7514+
7515+#ifdef CONFIG_PAX_ASLR
7516+#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
7517+
7518+#ifdef __powerpc64__
7519+#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
7520+#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
7521+#else
7522+#define PAX_DELTA_MMAP_LEN 15
7523+#define PAX_DELTA_STACK_LEN 15
7524+#endif
7525+#endif
7526
7527 /*
7528 * Our registers are always unsigned longs, whether we're a 32 bit
7529@@ -123,10 +134,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
7530 (0x7ff >> (PAGE_SHIFT - 12)) : \
7531 (0x3ffff >> (PAGE_SHIFT - 12)))
7532
7533-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
7534-#define arch_randomize_brk arch_randomize_brk
7535-
7536-
7537 #ifdef CONFIG_SPU_BASE
7538 /* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
7539 #define NT_SPU 1
7540diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
7541index 8196e9c..d83a9f3 100644
7542--- a/arch/powerpc/include/asm/exec.h
7543+++ b/arch/powerpc/include/asm/exec.h
7544@@ -4,6 +4,6 @@
7545 #ifndef _ASM_POWERPC_EXEC_H
7546 #define _ASM_POWERPC_EXEC_H
7547
7548-extern unsigned long arch_align_stack(unsigned long sp);
7549+#define arch_align_stack(x) ((x) & ~0xfUL)
7550
7551 #endif /* _ASM_POWERPC_EXEC_H */
7552diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
7553index 5acabbd..7ea14fa 100644
7554--- a/arch/powerpc/include/asm/kmap_types.h
7555+++ b/arch/powerpc/include/asm/kmap_types.h
7556@@ -10,7 +10,7 @@
7557 * 2 of the License, or (at your option) any later version.
7558 */
7559
7560-#define KM_TYPE_NR 16
7561+#define KM_TYPE_NR 17
7562
7563 #endif /* __KERNEL__ */
7564 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
7565diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
7566index 8565c25..2865190 100644
7567--- a/arch/powerpc/include/asm/mman.h
7568+++ b/arch/powerpc/include/asm/mman.h
7569@@ -24,7 +24,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
7570 }
7571 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
7572
7573-static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
7574+static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
7575 {
7576 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
7577 }
7578diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
7579index b9f4262..dcf04f7 100644
7580--- a/arch/powerpc/include/asm/page.h
7581+++ b/arch/powerpc/include/asm/page.h
7582@@ -230,8 +230,9 @@ extern long long virt_phys_offset;
7583 * and needs to be executable. This means the whole heap ends
7584 * up being executable.
7585 */
7586-#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
7587- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7588+#define VM_DATA_DEFAULT_FLAGS32 \
7589+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
7590+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7591
7592 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
7593 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7594@@ -259,6 +260,9 @@ extern long long virt_phys_offset;
7595 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
7596 #endif
7597
7598+#define ktla_ktva(addr) (addr)
7599+#define ktva_ktla(addr) (addr)
7600+
7601 #ifndef CONFIG_PPC_BOOK3S_64
7602 /*
7603 * Use the top bit of the higher-level page table entries to indicate whether
7604diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
7605index 88693ce..ac6f9ab 100644
7606--- a/arch/powerpc/include/asm/page_64.h
7607+++ b/arch/powerpc/include/asm/page_64.h
7608@@ -153,15 +153,18 @@ do { \
7609 * stack by default, so in the absence of a PT_GNU_STACK program header
7610 * we turn execute permission off.
7611 */
7612-#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
7613- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7614+#define VM_STACK_DEFAULT_FLAGS32 \
7615+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
7616+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7617
7618 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
7619 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7620
7621+#ifndef CONFIG_PAX_PAGEEXEC
7622 #define VM_STACK_DEFAULT_FLAGS \
7623 (is_32bit_task() ? \
7624 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
7625+#endif
7626
7627 #include <asm-generic/getorder.h>
7628
7629diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
7630index f65e27b..23ffb5b 100644
7631--- a/arch/powerpc/include/asm/pgalloc-64.h
7632+++ b/arch/powerpc/include/asm/pgalloc-64.h
7633@@ -53,6 +53,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
7634 #ifndef CONFIG_PPC_64K_PAGES
7635
7636 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
7637+#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
7638
7639 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
7640 {
7641@@ -70,6 +71,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
7642 pud_set(pud, (unsigned long)pmd);
7643 }
7644
7645+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
7646+{
7647+ pud_populate(mm, pud, pmd);
7648+}
7649+
7650 #define pmd_populate(mm, pmd, pte_page) \
7651 pmd_populate_kernel(mm, pmd, page_address(pte_page))
7652 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
7653@@ -171,6 +177,7 @@ extern void __tlb_remove_table(void *_table);
7654 #endif
7655
7656 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
7657+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
7658
7659 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
7660 pte_t *pte)
7661diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
7662index 7d6eacf..14c0240 100644
7663--- a/arch/powerpc/include/asm/pgtable.h
7664+++ b/arch/powerpc/include/asm/pgtable.h
7665@@ -2,6 +2,7 @@
7666 #define _ASM_POWERPC_PGTABLE_H
7667 #ifdef __KERNEL__
7668
7669+#include <linux/const.h>
7670 #ifndef __ASSEMBLY__
7671 #include <asm/processor.h> /* For TASK_SIZE */
7672 #include <asm/mmu.h>
7673diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
7674index 4aad413..85d86bf 100644
7675--- a/arch/powerpc/include/asm/pte-hash32.h
7676+++ b/arch/powerpc/include/asm/pte-hash32.h
7677@@ -21,6 +21,7 @@
7678 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
7679 #define _PAGE_USER 0x004 /* usermode access allowed */
7680 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
7681+#define _PAGE_EXEC _PAGE_GUARDED
7682 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
7683 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
7684 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
7685diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
7686index 10d1ef0..8f83abc 100644
7687--- a/arch/powerpc/include/asm/reg.h
7688+++ b/arch/powerpc/include/asm/reg.h
7689@@ -234,6 +234,7 @@
7690 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
7691 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
7692 #define DSISR_NOHPTE 0x40000000 /* no translation found */
7693+#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
7694 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
7695 #define DSISR_ISSTORE 0x02000000 /* access was a store */
7696 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
7697diff --git a/arch/powerpc/include/asm/smp.h b/arch/powerpc/include/asm/smp.h
7698index 98da78e..dc68271 100644
7699--- a/arch/powerpc/include/asm/smp.h
7700+++ b/arch/powerpc/include/asm/smp.h
7701@@ -50,7 +50,7 @@ struct smp_ops_t {
7702 int (*cpu_disable)(void);
7703 void (*cpu_die)(unsigned int nr);
7704 int (*cpu_bootable)(unsigned int nr);
7705-};
7706+} __no_const;
7707
7708 extern void smp_send_debugger_break(void);
7709 extern void start_secondary_resume(void);
7710diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
7711index ba7b197..d292e26 100644
7712--- a/arch/powerpc/include/asm/thread_info.h
7713+++ b/arch/powerpc/include/asm/thread_info.h
7714@@ -93,7 +93,6 @@ static inline struct thread_info *current_thread_info(void)
7715 #define TIF_POLLING_NRFLAG 3 /* true if poll_idle() is polling
7716 TIF_NEED_RESCHED */
7717 #define TIF_32BIT 4 /* 32 bit binary */
7718-#define TIF_PERFMON_WORK 5 /* work for pfm_handle_work() */
7719 #define TIF_PERFMON_CTXSW 6 /* perfmon needs ctxsw calls */
7720 #define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
7721 #define TIF_SINGLESTEP 8 /* singlestepping active */
7722@@ -107,6 +106,9 @@ static inline struct thread_info *current_thread_info(void)
7723 #define TIF_EMULATE_STACK_STORE 16 /* Is an instruction emulation
7724 for stack store? */
7725 #define TIF_MEMDIE 17 /* is terminating due to OOM killer */
7726+#define TIF_PERFMON_WORK 18 /* work for pfm_handle_work() */
7727+/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
7728+#define TIF_GRSEC_SETXID 5 /* update credentials on syscall entry/exit */
7729
7730 /* as above, but as bit values */
7731 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
7732@@ -126,9 +128,10 @@ static inline struct thread_info *current_thread_info(void)
7733 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
7734 #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
7735 #define _TIF_NOHZ (1<<TIF_NOHZ)
7736+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
7737 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
7738 _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
7739- _TIF_NOHZ)
7740+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
7741
7742 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
7743 _TIF_NOTIFY_RESUME | _TIF_UPROBE)
7744diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
7745index 9485b43..4718d50 100644
7746--- a/arch/powerpc/include/asm/uaccess.h
7747+++ b/arch/powerpc/include/asm/uaccess.h
7748@@ -318,52 +318,6 @@ do { \
7749 extern unsigned long __copy_tofrom_user(void __user *to,
7750 const void __user *from, unsigned long size);
7751
7752-#ifndef __powerpc64__
7753-
7754-static inline unsigned long copy_from_user(void *to,
7755- const void __user *from, unsigned long n)
7756-{
7757- unsigned long over;
7758-
7759- if (access_ok(VERIFY_READ, from, n))
7760- return __copy_tofrom_user((__force void __user *)to, from, n);
7761- if ((unsigned long)from < TASK_SIZE) {
7762- over = (unsigned long)from + n - TASK_SIZE;
7763- return __copy_tofrom_user((__force void __user *)to, from,
7764- n - over) + over;
7765- }
7766- return n;
7767-}
7768-
7769-static inline unsigned long copy_to_user(void __user *to,
7770- const void *from, unsigned long n)
7771-{
7772- unsigned long over;
7773-
7774- if (access_ok(VERIFY_WRITE, to, n))
7775- return __copy_tofrom_user(to, (__force void __user *)from, n);
7776- if ((unsigned long)to < TASK_SIZE) {
7777- over = (unsigned long)to + n - TASK_SIZE;
7778- return __copy_tofrom_user(to, (__force void __user *)from,
7779- n - over) + over;
7780- }
7781- return n;
7782-}
7783-
7784-#else /* __powerpc64__ */
7785-
7786-#define __copy_in_user(to, from, size) \
7787- __copy_tofrom_user((to), (from), (size))
7788-
7789-extern unsigned long copy_from_user(void *to, const void __user *from,
7790- unsigned long n);
7791-extern unsigned long copy_to_user(void __user *to, const void *from,
7792- unsigned long n);
7793-extern unsigned long copy_in_user(void __user *to, const void __user *from,
7794- unsigned long n);
7795-
7796-#endif /* __powerpc64__ */
7797-
7798 static inline unsigned long __copy_from_user_inatomic(void *to,
7799 const void __user *from, unsigned long n)
7800 {
7801@@ -387,6 +341,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
7802 if (ret == 0)
7803 return 0;
7804 }
7805+
7806+ if (!__builtin_constant_p(n))
7807+ check_object_size(to, n, false);
7808+
7809 return __copy_tofrom_user((__force void __user *)to, from, n);
7810 }
7811
7812@@ -413,6 +371,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
7813 if (ret == 0)
7814 return 0;
7815 }
7816+
7817+ if (!__builtin_constant_p(n))
7818+ check_object_size(from, n, true);
7819+
7820 return __copy_tofrom_user(to, (__force const void __user *)from, n);
7821 }
7822
7823@@ -430,6 +392,92 @@ static inline unsigned long __copy_to_user(void __user *to,
7824 return __copy_to_user_inatomic(to, from, size);
7825 }
7826
7827+#ifndef __powerpc64__
7828+
7829+static inline unsigned long __must_check copy_from_user(void *to,
7830+ const void __user *from, unsigned long n)
7831+{
7832+ unsigned long over;
7833+
7834+ if ((long)n < 0)
7835+ return n;
7836+
7837+ if (access_ok(VERIFY_READ, from, n)) {
7838+ if (!__builtin_constant_p(n))
7839+ check_object_size(to, n, false);
7840+ return __copy_tofrom_user((__force void __user *)to, from, n);
7841+ }
7842+ if ((unsigned long)from < TASK_SIZE) {
7843+ over = (unsigned long)from + n - TASK_SIZE;
7844+ if (!__builtin_constant_p(n - over))
7845+ check_object_size(to, n - over, false);
7846+ return __copy_tofrom_user((__force void __user *)to, from,
7847+ n - over) + over;
7848+ }
7849+ return n;
7850+}
7851+
7852+static inline unsigned long __must_check copy_to_user(void __user *to,
7853+ const void *from, unsigned long n)
7854+{
7855+ unsigned long over;
7856+
7857+ if ((long)n < 0)
7858+ return n;
7859+
7860+ if (access_ok(VERIFY_WRITE, to, n)) {
7861+ if (!__builtin_constant_p(n))
7862+ check_object_size(from, n, true);
7863+ return __copy_tofrom_user(to, (__force void __user *)from, n);
7864+ }
7865+ if ((unsigned long)to < TASK_SIZE) {
7866+ over = (unsigned long)to + n - TASK_SIZE;
7867+ if (!__builtin_constant_p(n))
7868+ check_object_size(from, n - over, true);
7869+ return __copy_tofrom_user(to, (__force void __user *)from,
7870+ n - over) + over;
7871+ }
7872+ return n;
7873+}
7874+
7875+#else /* __powerpc64__ */
7876+
7877+#define __copy_in_user(to, from, size) \
7878+ __copy_tofrom_user((to), (from), (size))
7879+
7880+static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
7881+{
7882+ if ((long)n < 0 || n > INT_MAX)
7883+ return n;
7884+
7885+ if (!__builtin_constant_p(n))
7886+ check_object_size(to, n, false);
7887+
7888+ if (likely(access_ok(VERIFY_READ, from, n)))
7889+ n = __copy_from_user(to, from, n);
7890+ else
7891+ memset(to, 0, n);
7892+ return n;
7893+}
7894+
7895+static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
7896+{
7897+ if ((long)n < 0 || n > INT_MAX)
7898+ return n;
7899+
7900+ if (likely(access_ok(VERIFY_WRITE, to, n))) {
7901+ if (!__builtin_constant_p(n))
7902+ check_object_size(from, n, true);
7903+ n = __copy_to_user(to, from, n);
7904+ }
7905+ return n;
7906+}
7907+
7908+extern unsigned long copy_in_user(void __user *to, const void __user *from,
7909+ unsigned long n);
7910+
7911+#endif /* __powerpc64__ */
7912+
7913 extern unsigned long __clear_user(void __user *addr, unsigned long size);
7914
7915 static inline unsigned long clear_user(void __user *addr, unsigned long size)
7916diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
7917index 2d06704..1616f1b 100644
7918--- a/arch/powerpc/kernel/exceptions-64e.S
7919+++ b/arch/powerpc/kernel/exceptions-64e.S
7920@@ -757,6 +757,7 @@ storage_fault_common:
7921 std r14,_DAR(r1)
7922 std r15,_DSISR(r1)
7923 addi r3,r1,STACK_FRAME_OVERHEAD
7924+ bl .save_nvgprs
7925 mr r4,r14
7926 mr r5,r15
7927 ld r14,PACA_EXGEN+EX_R14(r13)
7928@@ -765,8 +766,7 @@ storage_fault_common:
7929 cmpdi r3,0
7930 bne- 1f
7931 b .ret_from_except_lite
7932-1: bl .save_nvgprs
7933- mr r5,r3
7934+1: mr r5,r3
7935 addi r3,r1,STACK_FRAME_OVERHEAD
7936 ld r4,_DAR(r1)
7937 bl .bad_page_fault
7938diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
7939index 3a9ed6a..b534681 100644
7940--- a/arch/powerpc/kernel/exceptions-64s.S
7941+++ b/arch/powerpc/kernel/exceptions-64s.S
7942@@ -1364,10 +1364,10 @@ handle_page_fault:
7943 11: ld r4,_DAR(r1)
7944 ld r5,_DSISR(r1)
7945 addi r3,r1,STACK_FRAME_OVERHEAD
7946+ bl .save_nvgprs
7947 bl .do_page_fault
7948 cmpdi r3,0
7949 beq+ 12f
7950- bl .save_nvgprs
7951 mr r5,r3
7952 addi r3,r1,STACK_FRAME_OVERHEAD
7953 lwz r4,_DAR(r1)
7954diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
7955index 2e3200c..72095ce 100644
7956--- a/arch/powerpc/kernel/module_32.c
7957+++ b/arch/powerpc/kernel/module_32.c
7958@@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
7959 me->arch.core_plt_section = i;
7960 }
7961 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
7962- printk("Module doesn't contain .plt or .init.plt sections.\n");
7963+ printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
7964 return -ENOEXEC;
7965 }
7966
7967@@ -192,11 +192,16 @@ static uint32_t do_plt_call(void *location,
7968
7969 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
7970 /* Init, or core PLT? */
7971- if (location >= mod->module_core
7972- && location < mod->module_core + mod->core_size)
7973+ if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
7974+ (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
7975 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
7976- else
7977+ else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
7978+ (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
7979 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
7980+ else {
7981+ printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
7982+ return ~0UL;
7983+ }
7984
7985 /* Find this entry, or if that fails, the next avail. entry */
7986 while (entry->jump[0]) {
7987diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
7988index 96d2fdf..f6d10c8 100644
7989--- a/arch/powerpc/kernel/process.c
7990+++ b/arch/powerpc/kernel/process.c
7991@@ -886,8 +886,8 @@ void show_regs(struct pt_regs * regs)
7992 * Lookup NIP late so we have the best change of getting the
7993 * above info out without failing
7994 */
7995- printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
7996- printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
7997+ printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
7998+ printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
7999 #endif
8000 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
8001 printk("PACATMSCRATCH [%llx]\n", get_paca()->tm_scratch);
8002@@ -1352,10 +1352,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
8003 newsp = stack[0];
8004 ip = stack[STACK_FRAME_LR_SAVE];
8005 if (!firstframe || ip != lr) {
8006- printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
8007+ printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
8008 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
8009 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
8010- printk(" (%pS)",
8011+ printk(" (%pA)",
8012 (void *)current->ret_stack[curr_frame].ret);
8013 curr_frame--;
8014 }
8015@@ -1375,7 +1375,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
8016 struct pt_regs *regs = (struct pt_regs *)
8017 (sp + STACK_FRAME_OVERHEAD);
8018 lr = regs->link;
8019- printk("--- Exception: %lx at %pS\n LR = %pS\n",
8020+ printk("--- Exception: %lx at %pA\n LR = %pA\n",
8021 regs->trap, (void *)regs->nip, (void *)lr);
8022 firstframe = 1;
8023 }
8024@@ -1411,58 +1411,3 @@ void notrace __ppc64_runlatch_off(void)
8025 mtspr(SPRN_CTRLT, ctrl);
8026 }
8027 #endif /* CONFIG_PPC64 */
8028-
8029-unsigned long arch_align_stack(unsigned long sp)
8030-{
8031- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
8032- sp -= get_random_int() & ~PAGE_MASK;
8033- return sp & ~0xf;
8034-}
8035-
8036-static inline unsigned long brk_rnd(void)
8037-{
8038- unsigned long rnd = 0;
8039-
8040- /* 8MB for 32bit, 1GB for 64bit */
8041- if (is_32bit_task())
8042- rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
8043- else
8044- rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
8045-
8046- return rnd << PAGE_SHIFT;
8047-}
8048-
8049-unsigned long arch_randomize_brk(struct mm_struct *mm)
8050-{
8051- unsigned long base = mm->brk;
8052- unsigned long ret;
8053-
8054-#ifdef CONFIG_PPC_STD_MMU_64
8055- /*
8056- * If we are using 1TB segments and we are allowed to randomise
8057- * the heap, we can put it above 1TB so it is backed by a 1TB
8058- * segment. Otherwise the heap will be in the bottom 1TB
8059- * which always uses 256MB segments and this may result in a
8060- * performance penalty.
8061- */
8062- if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
8063- base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
8064-#endif
8065-
8066- ret = PAGE_ALIGN(base + brk_rnd());
8067-
8068- if (ret < mm->brk)
8069- return mm->brk;
8070-
8071- return ret;
8072-}
8073-
8074-unsigned long randomize_et_dyn(unsigned long base)
8075-{
8076- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
8077-
8078- if (ret < base)
8079- return base;
8080-
8081- return ret;
8082-}
8083diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
8084index 9a0d24c..e7fbedf 100644
8085--- a/arch/powerpc/kernel/ptrace.c
8086+++ b/arch/powerpc/kernel/ptrace.c
8087@@ -1761,6 +1761,10 @@ long arch_ptrace(struct task_struct *child, long request,
8088 return ret;
8089 }
8090
8091+#ifdef CONFIG_GRKERNSEC_SETXID
8092+extern void gr_delayed_cred_worker(void);
8093+#endif
8094+
8095 /*
8096 * We must return the syscall number to actually look up in the table.
8097 * This can be -1L to skip running any syscall at all.
8098@@ -1773,6 +1777,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
8099
8100 secure_computing_strict(regs->gpr[0]);
8101
8102+#ifdef CONFIG_GRKERNSEC_SETXID
8103+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8104+ gr_delayed_cred_worker();
8105+#endif
8106+
8107 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
8108 tracehook_report_syscall_entry(regs))
8109 /*
8110@@ -1807,6 +1816,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
8111 {
8112 int step;
8113
8114+#ifdef CONFIG_GRKERNSEC_SETXID
8115+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8116+ gr_delayed_cred_worker();
8117+#endif
8118+
8119 audit_syscall_exit(regs);
8120
8121 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
8122diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
8123index bebdf1a..7a9e095 100644
8124--- a/arch/powerpc/kernel/signal_32.c
8125+++ b/arch/powerpc/kernel/signal_32.c
8126@@ -996,7 +996,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
8127 /* Save user registers on the stack */
8128 frame = &rt_sf->uc.uc_mcontext;
8129 addr = frame;
8130- if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
8131+ if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
8132 sigret = 0;
8133 tramp = current->mm->context.vdso_base + vdso32_rt_sigtramp;
8134 } else {
8135diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
8136index f93ec28..97e0fbb 100644
8137--- a/arch/powerpc/kernel/signal_64.c
8138+++ b/arch/powerpc/kernel/signal_64.c
8139@@ -757,7 +757,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
8140 #endif
8141
8142 /* Set up to return from userspace. */
8143- if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
8144+ if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
8145 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
8146 } else {
8147 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
8148diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
8149index f783c93..619baf1 100644
8150--- a/arch/powerpc/kernel/traps.c
8151+++ b/arch/powerpc/kernel/traps.c
8152@@ -142,6 +142,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
8153 return flags;
8154 }
8155
8156+extern void gr_handle_kernel_exploit(void);
8157+
8158 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
8159 int signr)
8160 {
8161@@ -191,6 +193,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
8162 panic("Fatal exception in interrupt");
8163 if (panic_on_oops)
8164 panic("Fatal exception");
8165+
8166+ gr_handle_kernel_exploit();
8167+
8168 do_exit(signr);
8169 }
8170
8171diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
8172index 1d9c926..25f4741 100644
8173--- a/arch/powerpc/kernel/vdso.c
8174+++ b/arch/powerpc/kernel/vdso.c
8175@@ -34,6 +34,7 @@
8176 #include <asm/firmware.h>
8177 #include <asm/vdso.h>
8178 #include <asm/vdso_datapage.h>
8179+#include <asm/mman.h>
8180
8181 #include "setup.h"
8182
8183@@ -222,7 +223,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
8184 vdso_base = VDSO32_MBASE;
8185 #endif
8186
8187- current->mm->context.vdso_base = 0;
8188+ current->mm->context.vdso_base = ~0UL;
8189
8190 /* vDSO has a problem and was disabled, just don't "enable" it for the
8191 * process
8192@@ -242,7 +243,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
8193 vdso_base = get_unmapped_area(NULL, vdso_base,
8194 (vdso_pages << PAGE_SHIFT) +
8195 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
8196- 0, 0);
8197+ 0, MAP_PRIVATE | MAP_EXECUTABLE);
8198 if (IS_ERR_VALUE(vdso_base)) {
8199 rc = vdso_base;
8200 goto fail_mmapsem;
8201diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
8202index 5eea6f3..5d10396 100644
8203--- a/arch/powerpc/lib/usercopy_64.c
8204+++ b/arch/powerpc/lib/usercopy_64.c
8205@@ -9,22 +9,6 @@
8206 #include <linux/module.h>
8207 #include <asm/uaccess.h>
8208
8209-unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
8210-{
8211- if (likely(access_ok(VERIFY_READ, from, n)))
8212- n = __copy_from_user(to, from, n);
8213- else
8214- memset(to, 0, n);
8215- return n;
8216-}
8217-
8218-unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
8219-{
8220- if (likely(access_ok(VERIFY_WRITE, to, n)))
8221- n = __copy_to_user(to, from, n);
8222- return n;
8223-}
8224-
8225 unsigned long copy_in_user(void __user *to, const void __user *from,
8226 unsigned long n)
8227 {
8228@@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
8229 return n;
8230 }
8231
8232-EXPORT_SYMBOL(copy_from_user);
8233-EXPORT_SYMBOL(copy_to_user);
8234 EXPORT_SYMBOL(copy_in_user);
8235
8236diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
8237index 51ab9e7..7d3c78b 100644
8238--- a/arch/powerpc/mm/fault.c
8239+++ b/arch/powerpc/mm/fault.c
8240@@ -33,6 +33,10 @@
8241 #include <linux/magic.h>
8242 #include <linux/ratelimit.h>
8243 #include <linux/context_tracking.h>
8244+#include <linux/slab.h>
8245+#include <linux/pagemap.h>
8246+#include <linux/compiler.h>
8247+#include <linux/unistd.h>
8248
8249 #include <asm/firmware.h>
8250 #include <asm/page.h>
8251@@ -69,6 +73,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
8252 }
8253 #endif
8254
8255+#ifdef CONFIG_PAX_PAGEEXEC
8256+/*
8257+ * PaX: decide what to do with offenders (regs->nip = fault address)
8258+ *
8259+ * returns 1 when task should be killed
8260+ */
8261+static int pax_handle_fetch_fault(struct pt_regs *regs)
8262+{
8263+ return 1;
8264+}
8265+
8266+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
8267+{
8268+ unsigned long i;
8269+
8270+ printk(KERN_ERR "PAX: bytes at PC: ");
8271+ for (i = 0; i < 5; i++) {
8272+ unsigned int c;
8273+ if (get_user(c, (unsigned int __user *)pc+i))
8274+ printk(KERN_CONT "???????? ");
8275+ else
8276+ printk(KERN_CONT "%08x ", c);
8277+ }
8278+ printk("\n");
8279+}
8280+#endif
8281+
8282 /*
8283 * Check whether the instruction at regs->nip is a store using
8284 * an update addressing form which will update r1.
8285@@ -216,7 +247,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
8286 * indicate errors in DSISR but can validly be set in SRR1.
8287 */
8288 if (trap == 0x400)
8289- error_code &= 0x48200000;
8290+ error_code &= 0x58200000;
8291 else
8292 is_write = error_code & DSISR_ISSTORE;
8293 #else
8294@@ -378,7 +409,7 @@ good_area:
8295 * "undefined". Of those that can be set, this is the only
8296 * one which seems bad.
8297 */
8298- if (error_code & 0x10000000)
8299+ if (error_code & DSISR_GUARDED)
8300 /* Guarded storage error. */
8301 goto bad_area;
8302 #endif /* CONFIG_8xx */
8303@@ -393,7 +424,7 @@ good_area:
8304 * processors use the same I/D cache coherency mechanism
8305 * as embedded.
8306 */
8307- if (error_code & DSISR_PROTFAULT)
8308+ if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
8309 goto bad_area;
8310 #endif /* CONFIG_PPC_STD_MMU */
8311
8312@@ -483,6 +514,23 @@ bad_area:
8313 bad_area_nosemaphore:
8314 /* User mode accesses cause a SIGSEGV */
8315 if (user_mode(regs)) {
8316+
8317+#ifdef CONFIG_PAX_PAGEEXEC
8318+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
8319+#ifdef CONFIG_PPC_STD_MMU
8320+ if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
8321+#else
8322+ if (is_exec && regs->nip == address) {
8323+#endif
8324+ switch (pax_handle_fetch_fault(regs)) {
8325+ }
8326+
8327+ pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
8328+ do_group_exit(SIGKILL);
8329+ }
8330+ }
8331+#endif
8332+
8333 _exception(SIGSEGV, regs, code, address);
8334 goto bail;
8335 }
8336diff --git a/arch/powerpc/mm/mmap.c b/arch/powerpc/mm/mmap.c
8337index cb8bdbe..d770680 100644
8338--- a/arch/powerpc/mm/mmap.c
8339+++ b/arch/powerpc/mm/mmap.c
8340@@ -57,6 +57,10 @@ static unsigned long mmap_rnd(void)
8341 {
8342 unsigned long rnd = 0;
8343
8344+#ifdef CONFIG_PAX_RANDMMAP
8345+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8346+#endif
8347+
8348 if (current->flags & PF_RANDOMIZE) {
8349 /* 8MB for 32bit, 1GB for 64bit */
8350 if (is_32bit_task())
8351@@ -91,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8352 */
8353 if (mmap_is_legacy()) {
8354 mm->mmap_base = TASK_UNMAPPED_BASE;
8355+
8356+#ifdef CONFIG_PAX_RANDMMAP
8357+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8358+ mm->mmap_base += mm->delta_mmap;
8359+#endif
8360+
8361 mm->get_unmapped_area = arch_get_unmapped_area;
8362 } else {
8363 mm->mmap_base = mmap_base();
8364+
8365+#ifdef CONFIG_PAX_RANDMMAP
8366+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8367+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
8368+#endif
8369+
8370 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
8371 }
8372 }
8373diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
8374index 3e99c14..f00953c 100644
8375--- a/arch/powerpc/mm/slice.c
8376+++ b/arch/powerpc/mm/slice.c
8377@@ -103,7 +103,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
8378 if ((mm->task_size - len) < addr)
8379 return 0;
8380 vma = find_vma(mm, addr);
8381- return (!vma || (addr + len) <= vma->vm_start);
8382+ return check_heap_stack_gap(vma, addr, len, 0);
8383 }
8384
8385 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
8386@@ -277,6 +277,12 @@ static unsigned long slice_find_area_bottomup(struct mm_struct *mm,
8387 info.align_offset = 0;
8388
8389 addr = TASK_UNMAPPED_BASE;
8390+
8391+#ifdef CONFIG_PAX_RANDMMAP
8392+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8393+ addr += mm->delta_mmap;
8394+#endif
8395+
8396 while (addr < TASK_SIZE) {
8397 info.low_limit = addr;
8398 if (!slice_scan_available(addr, available, 1, &addr))
8399@@ -410,6 +416,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
8400 if (fixed && addr > (mm->task_size - len))
8401 return -EINVAL;
8402
8403+#ifdef CONFIG_PAX_RANDMMAP
8404+ if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
8405+ addr = 0;
8406+#endif
8407+
8408 /* If hint, make sure it matches our alignment restrictions */
8409 if (!fixed && addr) {
8410 addr = _ALIGN_UP(addr, 1ul << pshift);
8411diff --git a/arch/powerpc/platforms/cell/spufs/file.c b/arch/powerpc/platforms/cell/spufs/file.c
8412index 9098692..3d54cd1 100644
8413--- a/arch/powerpc/platforms/cell/spufs/file.c
8414+++ b/arch/powerpc/platforms/cell/spufs/file.c
8415@@ -280,9 +280,9 @@ spufs_mem_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
8416 return VM_FAULT_NOPAGE;
8417 }
8418
8419-static int spufs_mem_mmap_access(struct vm_area_struct *vma,
8420+static ssize_t spufs_mem_mmap_access(struct vm_area_struct *vma,
8421 unsigned long address,
8422- void *buf, int len, int write)
8423+ void *buf, size_t len, int write)
8424 {
8425 struct spu_context *ctx = vma->vm_file->private_data;
8426 unsigned long offset = address - vma->vm_start;
8427diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
8428index c797832..ce575c8 100644
8429--- a/arch/s390/include/asm/atomic.h
8430+++ b/arch/s390/include/asm/atomic.h
8431@@ -326,6 +326,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
8432 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
8433 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
8434
8435+#define atomic64_read_unchecked(v) atomic64_read(v)
8436+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
8437+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
8438+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
8439+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
8440+#define atomic64_inc_unchecked(v) atomic64_inc(v)
8441+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
8442+#define atomic64_dec_unchecked(v) atomic64_dec(v)
8443+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
8444+
8445 #define smp_mb__before_atomic_dec() smp_mb()
8446 #define smp_mb__after_atomic_dec() smp_mb()
8447 #define smp_mb__before_atomic_inc() smp_mb()
8448diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
8449index 4d7ccac..d03d0ad 100644
8450--- a/arch/s390/include/asm/cache.h
8451+++ b/arch/s390/include/asm/cache.h
8452@@ -9,8 +9,10 @@
8453 #ifndef __ARCH_S390_CACHE_H
8454 #define __ARCH_S390_CACHE_H
8455
8456-#define L1_CACHE_BYTES 256
8457+#include <linux/const.h>
8458+
8459 #define L1_CACHE_SHIFT 8
8460+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8461 #define NET_SKB_PAD 32
8462
8463 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
8464diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
8465index 78f4f87..598ce39 100644
8466--- a/arch/s390/include/asm/elf.h
8467+++ b/arch/s390/include/asm/elf.h
8468@@ -162,8 +162,14 @@ extern unsigned int vdso_enabled;
8469 the loader. We need to make sure that it is out of the way of the program
8470 that it will "exec", and that there is sufficient room for the brk. */
8471
8472-extern unsigned long randomize_et_dyn(unsigned long base);
8473-#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
8474+#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
8475+
8476+#ifdef CONFIG_PAX_ASLR
8477+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
8478+
8479+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
8480+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
8481+#endif
8482
8483 /* This yields a mask that user programs can use to figure out what
8484 instruction set this CPU supports. */
8485@@ -222,9 +228,6 @@ struct linux_binprm;
8486 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
8487 int arch_setup_additional_pages(struct linux_binprm *, int);
8488
8489-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
8490-#define arch_randomize_brk arch_randomize_brk
8491-
8492 void *fill_cpu_elf_notes(void *ptr, struct save_area *sa);
8493
8494 #endif
8495diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
8496index c4a93d6..4d2a9b4 100644
8497--- a/arch/s390/include/asm/exec.h
8498+++ b/arch/s390/include/asm/exec.h
8499@@ -7,6 +7,6 @@
8500 #ifndef __ASM_EXEC_H
8501 #define __ASM_EXEC_H
8502
8503-extern unsigned long arch_align_stack(unsigned long sp);
8504+#define arch_align_stack(x) ((x) & ~0xfUL)
8505
8506 #endif /* __ASM_EXEC_H */
8507diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
8508index 9c33ed4..e40cbef 100644
8509--- a/arch/s390/include/asm/uaccess.h
8510+++ b/arch/s390/include/asm/uaccess.h
8511@@ -252,6 +252,10 @@ static inline unsigned long __must_check
8512 copy_to_user(void __user *to, const void *from, unsigned long n)
8513 {
8514 might_fault();
8515+
8516+ if ((long)n < 0)
8517+ return n;
8518+
8519 return __copy_to_user(to, from, n);
8520 }
8521
8522@@ -275,6 +279,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
8523 static inline unsigned long __must_check
8524 __copy_from_user(void *to, const void __user *from, unsigned long n)
8525 {
8526+ if ((long)n < 0)
8527+ return n;
8528+
8529 if (__builtin_constant_p(n) && (n <= 256))
8530 return uaccess.copy_from_user_small(n, from, to);
8531 else
8532@@ -306,10 +313,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
8533 static inline unsigned long __must_check
8534 copy_from_user(void *to, const void __user *from, unsigned long n)
8535 {
8536- unsigned int sz = __compiletime_object_size(to);
8537+ size_t sz = __compiletime_object_size(to);
8538
8539 might_fault();
8540- if (unlikely(sz != -1 && sz < n)) {
8541+
8542+ if ((long)n < 0)
8543+ return n;
8544+
8545+ if (unlikely(sz != (size_t)-1 && sz < n)) {
8546 copy_from_user_overflow();
8547 return n;
8548 }
8549diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
8550index 7845e15..59c4353 100644
8551--- a/arch/s390/kernel/module.c
8552+++ b/arch/s390/kernel/module.c
8553@@ -169,11 +169,11 @@ int module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
8554
8555 /* Increase core size by size of got & plt and set start
8556 offsets for got and plt. */
8557- me->core_size = ALIGN(me->core_size, 4);
8558- me->arch.got_offset = me->core_size;
8559- me->core_size += me->arch.got_size;
8560- me->arch.plt_offset = me->core_size;
8561- me->core_size += me->arch.plt_size;
8562+ me->core_size_rw = ALIGN(me->core_size_rw, 4);
8563+ me->arch.got_offset = me->core_size_rw;
8564+ me->core_size_rw += me->arch.got_size;
8565+ me->arch.plt_offset = me->core_size_rx;
8566+ me->core_size_rx += me->arch.plt_size;
8567 return 0;
8568 }
8569
8570@@ -289,7 +289,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8571 if (info->got_initialized == 0) {
8572 Elf_Addr *gotent;
8573
8574- gotent = me->module_core + me->arch.got_offset +
8575+ gotent = me->module_core_rw + me->arch.got_offset +
8576 info->got_offset;
8577 *gotent = val;
8578 info->got_initialized = 1;
8579@@ -312,7 +312,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8580 rc = apply_rela_bits(loc, val, 0, 64, 0);
8581 else if (r_type == R_390_GOTENT ||
8582 r_type == R_390_GOTPLTENT) {
8583- val += (Elf_Addr) me->module_core - loc;
8584+ val += (Elf_Addr) me->module_core_rw - loc;
8585 rc = apply_rela_bits(loc, val, 1, 32, 1);
8586 }
8587 break;
8588@@ -325,7 +325,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8589 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
8590 if (info->plt_initialized == 0) {
8591 unsigned int *ip;
8592- ip = me->module_core + me->arch.plt_offset +
8593+ ip = me->module_core_rx + me->arch.plt_offset +
8594 info->plt_offset;
8595 #ifndef CONFIG_64BIT
8596 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
8597@@ -350,7 +350,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8598 val - loc + 0xffffUL < 0x1ffffeUL) ||
8599 (r_type == R_390_PLT32DBL &&
8600 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
8601- val = (Elf_Addr) me->module_core +
8602+ val = (Elf_Addr) me->module_core_rx +
8603 me->arch.plt_offset +
8604 info->plt_offset;
8605 val += rela->r_addend - loc;
8606@@ -372,7 +372,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8607 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
8608 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
8609 val = val + rela->r_addend -
8610- ((Elf_Addr) me->module_core + me->arch.got_offset);
8611+ ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
8612 if (r_type == R_390_GOTOFF16)
8613 rc = apply_rela_bits(loc, val, 0, 16, 0);
8614 else if (r_type == R_390_GOTOFF32)
8615@@ -382,7 +382,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8616 break;
8617 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
8618 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
8619- val = (Elf_Addr) me->module_core + me->arch.got_offset +
8620+ val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
8621 rela->r_addend - loc;
8622 if (r_type == R_390_GOTPC)
8623 rc = apply_rela_bits(loc, val, 1, 32, 0);
8624diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
8625index c5dbb33..b41f4ee 100644
8626--- a/arch/s390/kernel/process.c
8627+++ b/arch/s390/kernel/process.c
8628@@ -237,39 +237,3 @@ unsigned long get_wchan(struct task_struct *p)
8629 }
8630 return 0;
8631 }
8632-
8633-unsigned long arch_align_stack(unsigned long sp)
8634-{
8635- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
8636- sp -= get_random_int() & ~PAGE_MASK;
8637- return sp & ~0xf;
8638-}
8639-
8640-static inline unsigned long brk_rnd(void)
8641-{
8642- /* 8MB for 32bit, 1GB for 64bit */
8643- if (is_32bit_task())
8644- return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
8645- else
8646- return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
8647-}
8648-
8649-unsigned long arch_randomize_brk(struct mm_struct *mm)
8650-{
8651- unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
8652-
8653- if (ret < mm->brk)
8654- return mm->brk;
8655- return ret;
8656-}
8657-
8658-unsigned long randomize_et_dyn(unsigned long base)
8659-{
8660- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
8661-
8662- if (!(current->flags & PF_RANDOMIZE))
8663- return base;
8664- if (ret < base)
8665- return base;
8666- return ret;
8667-}
8668diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
8669index 4002329..99b67cb 100644
8670--- a/arch/s390/mm/mmap.c
8671+++ b/arch/s390/mm/mmap.c
8672@@ -90,9 +90,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8673 */
8674 if (mmap_is_legacy()) {
8675 mm->mmap_base = TASK_UNMAPPED_BASE;
8676+
8677+#ifdef CONFIG_PAX_RANDMMAP
8678+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8679+ mm->mmap_base += mm->delta_mmap;
8680+#endif
8681+
8682 mm->get_unmapped_area = arch_get_unmapped_area;
8683 } else {
8684 mm->mmap_base = mmap_base();
8685+
8686+#ifdef CONFIG_PAX_RANDMMAP
8687+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8688+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
8689+#endif
8690+
8691 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
8692 }
8693 }
8694@@ -173,9 +185,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8695 */
8696 if (mmap_is_legacy()) {
8697 mm->mmap_base = TASK_UNMAPPED_BASE;
8698+
8699+#ifdef CONFIG_PAX_RANDMMAP
8700+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8701+ mm->mmap_base += mm->delta_mmap;
8702+#endif
8703+
8704 mm->get_unmapped_area = s390_get_unmapped_area;
8705 } else {
8706 mm->mmap_base = mmap_base();
8707+
8708+#ifdef CONFIG_PAX_RANDMMAP
8709+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8710+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
8711+#endif
8712+
8713 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
8714 }
8715 }
8716diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
8717index ae3d59f..f65f075 100644
8718--- a/arch/score/include/asm/cache.h
8719+++ b/arch/score/include/asm/cache.h
8720@@ -1,7 +1,9 @@
8721 #ifndef _ASM_SCORE_CACHE_H
8722 #define _ASM_SCORE_CACHE_H
8723
8724+#include <linux/const.h>
8725+
8726 #define L1_CACHE_SHIFT 4
8727-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8728+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8729
8730 #endif /* _ASM_SCORE_CACHE_H */
8731diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
8732index f9f3cd5..58ff438 100644
8733--- a/arch/score/include/asm/exec.h
8734+++ b/arch/score/include/asm/exec.h
8735@@ -1,6 +1,6 @@
8736 #ifndef _ASM_SCORE_EXEC_H
8737 #define _ASM_SCORE_EXEC_H
8738
8739-extern unsigned long arch_align_stack(unsigned long sp);
8740+#define arch_align_stack(x) (x)
8741
8742 #endif /* _ASM_SCORE_EXEC_H */
8743diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
8744index a1519ad3..e8ac1ff 100644
8745--- a/arch/score/kernel/process.c
8746+++ b/arch/score/kernel/process.c
8747@@ -116,8 +116,3 @@ unsigned long get_wchan(struct task_struct *task)
8748
8749 return task_pt_regs(task)->cp0_epc;
8750 }
8751-
8752-unsigned long arch_align_stack(unsigned long sp)
8753-{
8754- return sp;
8755-}
8756diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
8757index ef9e555..331bd29 100644
8758--- a/arch/sh/include/asm/cache.h
8759+++ b/arch/sh/include/asm/cache.h
8760@@ -9,10 +9,11 @@
8761 #define __ASM_SH_CACHE_H
8762 #ifdef __KERNEL__
8763
8764+#include <linux/const.h>
8765 #include <linux/init.h>
8766 #include <cpu/cache.h>
8767
8768-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8769+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8770
8771 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
8772
8773diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
8774index 6777177..cb5e44f 100644
8775--- a/arch/sh/mm/mmap.c
8776+++ b/arch/sh/mm/mmap.c
8777@@ -36,6 +36,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
8778 struct mm_struct *mm = current->mm;
8779 struct vm_area_struct *vma;
8780 int do_colour_align;
8781+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8782 struct vm_unmapped_area_info info;
8783
8784 if (flags & MAP_FIXED) {
8785@@ -55,6 +56,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
8786 if (filp || (flags & MAP_SHARED))
8787 do_colour_align = 1;
8788
8789+#ifdef CONFIG_PAX_RANDMMAP
8790+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8791+#endif
8792+
8793 if (addr) {
8794 if (do_colour_align)
8795 addr = COLOUR_ALIGN(addr, pgoff);
8796@@ -62,14 +67,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
8797 addr = PAGE_ALIGN(addr);
8798
8799 vma = find_vma(mm, addr);
8800- if (TASK_SIZE - len >= addr &&
8801- (!vma || addr + len <= vma->vm_start))
8802+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
8803 return addr;
8804 }
8805
8806 info.flags = 0;
8807 info.length = len;
8808- info.low_limit = TASK_UNMAPPED_BASE;
8809+ info.low_limit = mm->mmap_base;
8810 info.high_limit = TASK_SIZE;
8811 info.align_mask = do_colour_align ? (PAGE_MASK & shm_align_mask) : 0;
8812 info.align_offset = pgoff << PAGE_SHIFT;
8813@@ -85,6 +89,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8814 struct mm_struct *mm = current->mm;
8815 unsigned long addr = addr0;
8816 int do_colour_align;
8817+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8818 struct vm_unmapped_area_info info;
8819
8820 if (flags & MAP_FIXED) {
8821@@ -104,6 +109,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8822 if (filp || (flags & MAP_SHARED))
8823 do_colour_align = 1;
8824
8825+#ifdef CONFIG_PAX_RANDMMAP
8826+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8827+#endif
8828+
8829 /* requesting a specific address */
8830 if (addr) {
8831 if (do_colour_align)
8832@@ -112,8 +121,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8833 addr = PAGE_ALIGN(addr);
8834
8835 vma = find_vma(mm, addr);
8836- if (TASK_SIZE - len >= addr &&
8837- (!vma || addr + len <= vma->vm_start))
8838+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
8839 return addr;
8840 }
8841
8842@@ -135,6 +143,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8843 VM_BUG_ON(addr != -ENOMEM);
8844 info.flags = 0;
8845 info.low_limit = TASK_UNMAPPED_BASE;
8846+
8847+#ifdef CONFIG_PAX_RANDMMAP
8848+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8849+ info.low_limit += mm->delta_mmap;
8850+#endif
8851+
8852 info.high_limit = TASK_SIZE;
8853 addr = vm_unmapped_area(&info);
8854 }
8855diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
8856index be56a24..443328f 100644
8857--- a/arch/sparc/include/asm/atomic_64.h
8858+++ b/arch/sparc/include/asm/atomic_64.h
8859@@ -14,18 +14,40 @@
8860 #define ATOMIC64_INIT(i) { (i) }
8861
8862 #define atomic_read(v) (*(volatile int *)&(v)->counter)
8863+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
8864+{
8865+ return v->counter;
8866+}
8867 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
8868+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
8869+{
8870+ return v->counter;
8871+}
8872
8873 #define atomic_set(v, i) (((v)->counter) = i)
8874+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
8875+{
8876+ v->counter = i;
8877+}
8878 #define atomic64_set(v, i) (((v)->counter) = i)
8879+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
8880+{
8881+ v->counter = i;
8882+}
8883
8884 extern void atomic_add(int, atomic_t *);
8885+extern void atomic_add_unchecked(int, atomic_unchecked_t *);
8886 extern void atomic64_add(long, atomic64_t *);
8887+extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
8888 extern void atomic_sub(int, atomic_t *);
8889+extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
8890 extern void atomic64_sub(long, atomic64_t *);
8891+extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
8892
8893 extern int atomic_add_ret(int, atomic_t *);
8894+extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
8895 extern long atomic64_add_ret(long, atomic64_t *);
8896+extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
8897 extern int atomic_sub_ret(int, atomic_t *);
8898 extern long atomic64_sub_ret(long, atomic64_t *);
8899
8900@@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
8901 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
8902
8903 #define atomic_inc_return(v) atomic_add_ret(1, v)
8904+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
8905+{
8906+ return atomic_add_ret_unchecked(1, v);
8907+}
8908 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
8909+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
8910+{
8911+ return atomic64_add_ret_unchecked(1, v);
8912+}
8913
8914 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
8915 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
8916
8917 #define atomic_add_return(i, v) atomic_add_ret(i, v)
8918+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
8919+{
8920+ return atomic_add_ret_unchecked(i, v);
8921+}
8922 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
8923+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
8924+{
8925+ return atomic64_add_ret_unchecked(i, v);
8926+}
8927
8928 /*
8929 * atomic_inc_and_test - increment and test
8930@@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
8931 * other cases.
8932 */
8933 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
8934+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
8935+{
8936+ return atomic_inc_return_unchecked(v) == 0;
8937+}
8938 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
8939
8940 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
8941@@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
8942 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
8943
8944 #define atomic_inc(v) atomic_add(1, v)
8945+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
8946+{
8947+ atomic_add_unchecked(1, v);
8948+}
8949 #define atomic64_inc(v) atomic64_add(1, v)
8950+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
8951+{
8952+ atomic64_add_unchecked(1, v);
8953+}
8954
8955 #define atomic_dec(v) atomic_sub(1, v)
8956+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
8957+{
8958+ atomic_sub_unchecked(1, v);
8959+}
8960 #define atomic64_dec(v) atomic64_sub(1, v)
8961+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
8962+{
8963+ atomic64_sub_unchecked(1, v);
8964+}
8965
8966 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
8967 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
8968
8969 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
8970+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
8971+{
8972+ return cmpxchg(&v->counter, old, new);
8973+}
8974 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
8975+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
8976+{
8977+ return xchg(&v->counter, new);
8978+}
8979
8980 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
8981 {
8982- int c, old;
8983+ int c, old, new;
8984 c = atomic_read(v);
8985 for (;;) {
8986- if (unlikely(c == (u)))
8987+ if (unlikely(c == u))
8988 break;
8989- old = atomic_cmpxchg((v), c, c + (a));
8990+
8991+ asm volatile("addcc %2, %0, %0\n"
8992+
8993+#ifdef CONFIG_PAX_REFCOUNT
8994+ "tvs %%icc, 6\n"
8995+#endif
8996+
8997+ : "=r" (new)
8998+ : "0" (c), "ir" (a)
8999+ : "cc");
9000+
9001+ old = atomic_cmpxchg(v, c, new);
9002 if (likely(old == c))
9003 break;
9004 c = old;
9005@@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9006 #define atomic64_cmpxchg(v, o, n) \
9007 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
9008 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
9009+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
9010+{
9011+ return xchg(&v->counter, new);
9012+}
9013
9014 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
9015 {
9016- long c, old;
9017+ long c, old, new;
9018 c = atomic64_read(v);
9019 for (;;) {
9020- if (unlikely(c == (u)))
9021+ if (unlikely(c == u))
9022 break;
9023- old = atomic64_cmpxchg((v), c, c + (a));
9024+
9025+ asm volatile("addcc %2, %0, %0\n"
9026+
9027+#ifdef CONFIG_PAX_REFCOUNT
9028+ "tvs %%xcc, 6\n"
9029+#endif
9030+
9031+ : "=r" (new)
9032+ : "0" (c), "ir" (a)
9033+ : "cc");
9034+
9035+ old = atomic64_cmpxchg(v, c, new);
9036 if (likely(old == c))
9037 break;
9038 c = old;
9039 }
9040- return c != (u);
9041+ return c != u;
9042 }
9043
9044 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
9045diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
9046index 5bb6991..5c2132e 100644
9047--- a/arch/sparc/include/asm/cache.h
9048+++ b/arch/sparc/include/asm/cache.h
9049@@ -7,10 +7,12 @@
9050 #ifndef _SPARC_CACHE_H
9051 #define _SPARC_CACHE_H
9052
9053+#include <linux/const.h>
9054+
9055 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
9056
9057 #define L1_CACHE_SHIFT 5
9058-#define L1_CACHE_BYTES 32
9059+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9060
9061 #ifdef CONFIG_SPARC32
9062 #define SMP_CACHE_BYTES_SHIFT 5
9063diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
9064index a24e41f..47677ff 100644
9065--- a/arch/sparc/include/asm/elf_32.h
9066+++ b/arch/sparc/include/asm/elf_32.h
9067@@ -114,6 +114,13 @@ typedef struct {
9068
9069 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
9070
9071+#ifdef CONFIG_PAX_ASLR
9072+#define PAX_ELF_ET_DYN_BASE 0x10000UL
9073+
9074+#define PAX_DELTA_MMAP_LEN 16
9075+#define PAX_DELTA_STACK_LEN 16
9076+#endif
9077+
9078 /* This yields a mask that user programs can use to figure out what
9079 instruction set this cpu supports. This can NOT be done in userspace
9080 on Sparc. */
9081diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
9082index 370ca1e..d4f4a98 100644
9083--- a/arch/sparc/include/asm/elf_64.h
9084+++ b/arch/sparc/include/asm/elf_64.h
9085@@ -189,6 +189,13 @@ typedef struct {
9086 #define ELF_ET_DYN_BASE 0x0000010000000000UL
9087 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
9088
9089+#ifdef CONFIG_PAX_ASLR
9090+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
9091+
9092+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
9093+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
9094+#endif
9095+
9096 extern unsigned long sparc64_elf_hwcap;
9097 #define ELF_HWCAP sparc64_elf_hwcap
9098
9099diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
9100index 9b1c36d..209298b 100644
9101--- a/arch/sparc/include/asm/pgalloc_32.h
9102+++ b/arch/sparc/include/asm/pgalloc_32.h
9103@@ -33,6 +33,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
9104 }
9105
9106 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
9107+#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
9108
9109 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
9110 unsigned long address)
9111diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
9112index bcfe063..b333142 100644
9113--- a/arch/sparc/include/asm/pgalloc_64.h
9114+++ b/arch/sparc/include/asm/pgalloc_64.h
9115@@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
9116 }
9117
9118 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
9119+#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
9120
9121 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
9122 {
9123diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
9124index 502f632..da1917f 100644
9125--- a/arch/sparc/include/asm/pgtable_32.h
9126+++ b/arch/sparc/include/asm/pgtable_32.h
9127@@ -50,6 +50,9 @@ extern unsigned long calc_highpages(void);
9128 #define PAGE_SHARED SRMMU_PAGE_SHARED
9129 #define PAGE_COPY SRMMU_PAGE_COPY
9130 #define PAGE_READONLY SRMMU_PAGE_RDONLY
9131+#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
9132+#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
9133+#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
9134 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
9135
9136 /* Top-level page directory - dummy used by init-mm.
9137@@ -62,18 +65,18 @@ extern unsigned long ptr_in_current_pgd;
9138
9139 /* xwr */
9140 #define __P000 PAGE_NONE
9141-#define __P001 PAGE_READONLY
9142-#define __P010 PAGE_COPY
9143-#define __P011 PAGE_COPY
9144+#define __P001 PAGE_READONLY_NOEXEC
9145+#define __P010 PAGE_COPY_NOEXEC
9146+#define __P011 PAGE_COPY_NOEXEC
9147 #define __P100 PAGE_READONLY
9148 #define __P101 PAGE_READONLY
9149 #define __P110 PAGE_COPY
9150 #define __P111 PAGE_COPY
9151
9152 #define __S000 PAGE_NONE
9153-#define __S001 PAGE_READONLY
9154-#define __S010 PAGE_SHARED
9155-#define __S011 PAGE_SHARED
9156+#define __S001 PAGE_READONLY_NOEXEC
9157+#define __S010 PAGE_SHARED_NOEXEC
9158+#define __S011 PAGE_SHARED_NOEXEC
9159 #define __S100 PAGE_READONLY
9160 #define __S101 PAGE_READONLY
9161 #define __S110 PAGE_SHARED
9162diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
9163index 79da178..c2eede8 100644
9164--- a/arch/sparc/include/asm/pgtsrmmu.h
9165+++ b/arch/sparc/include/asm/pgtsrmmu.h
9166@@ -115,6 +115,11 @@
9167 SRMMU_EXEC | SRMMU_REF)
9168 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
9169 SRMMU_EXEC | SRMMU_REF)
9170+
9171+#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
9172+#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
9173+#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
9174+
9175 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
9176 SRMMU_DIRTY | SRMMU_REF)
9177
9178diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
9179index 9689176..63c18ea 100644
9180--- a/arch/sparc/include/asm/spinlock_64.h
9181+++ b/arch/sparc/include/asm/spinlock_64.h
9182@@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
9183
9184 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
9185
9186-static void inline arch_read_lock(arch_rwlock_t *lock)
9187+static inline void arch_read_lock(arch_rwlock_t *lock)
9188 {
9189 unsigned long tmp1, tmp2;
9190
9191 __asm__ __volatile__ (
9192 "1: ldsw [%2], %0\n"
9193 " brlz,pn %0, 2f\n"
9194-"4: add %0, 1, %1\n"
9195+"4: addcc %0, 1, %1\n"
9196+
9197+#ifdef CONFIG_PAX_REFCOUNT
9198+" tvs %%icc, 6\n"
9199+#endif
9200+
9201 " cas [%2], %0, %1\n"
9202 " cmp %0, %1\n"
9203 " bne,pn %%icc, 1b\n"
9204@@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
9205 " .previous"
9206 : "=&r" (tmp1), "=&r" (tmp2)
9207 : "r" (lock)
9208- : "memory");
9209+ : "memory", "cc");
9210 }
9211
9212-static int inline arch_read_trylock(arch_rwlock_t *lock)
9213+static inline int arch_read_trylock(arch_rwlock_t *lock)
9214 {
9215 int tmp1, tmp2;
9216
9217@@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
9218 "1: ldsw [%2], %0\n"
9219 " brlz,a,pn %0, 2f\n"
9220 " mov 0, %0\n"
9221-" add %0, 1, %1\n"
9222+" addcc %0, 1, %1\n"
9223+
9224+#ifdef CONFIG_PAX_REFCOUNT
9225+" tvs %%icc, 6\n"
9226+#endif
9227+
9228 " cas [%2], %0, %1\n"
9229 " cmp %0, %1\n"
9230 " bne,pn %%icc, 1b\n"
9231@@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
9232 return tmp1;
9233 }
9234
9235-static void inline arch_read_unlock(arch_rwlock_t *lock)
9236+static inline void arch_read_unlock(arch_rwlock_t *lock)
9237 {
9238 unsigned long tmp1, tmp2;
9239
9240 __asm__ __volatile__(
9241 "1: lduw [%2], %0\n"
9242-" sub %0, 1, %1\n"
9243+" subcc %0, 1, %1\n"
9244+
9245+#ifdef CONFIG_PAX_REFCOUNT
9246+" tvs %%icc, 6\n"
9247+#endif
9248+
9249 " cas [%2], %0, %1\n"
9250 " cmp %0, %1\n"
9251 " bne,pn %%xcc, 1b\n"
9252@@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
9253 : "memory");
9254 }
9255
9256-static void inline arch_write_lock(arch_rwlock_t *lock)
9257+static inline void arch_write_lock(arch_rwlock_t *lock)
9258 {
9259 unsigned long mask, tmp1, tmp2;
9260
9261@@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
9262 : "memory");
9263 }
9264
9265-static void inline arch_write_unlock(arch_rwlock_t *lock)
9266+static inline void arch_write_unlock(arch_rwlock_t *lock)
9267 {
9268 __asm__ __volatile__(
9269 " stw %%g0, [%0]"
9270@@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
9271 : "memory");
9272 }
9273
9274-static int inline arch_write_trylock(arch_rwlock_t *lock)
9275+static inline int arch_write_trylock(arch_rwlock_t *lock)
9276 {
9277 unsigned long mask, tmp1, tmp2, result;
9278
9279diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
9280index dd38075..e7cac83 100644
9281--- a/arch/sparc/include/asm/thread_info_32.h
9282+++ b/arch/sparc/include/asm/thread_info_32.h
9283@@ -49,6 +49,8 @@ struct thread_info {
9284 unsigned long w_saved;
9285
9286 struct restart_block restart_block;
9287+
9288+ unsigned long lowest_stack;
9289 };
9290
9291 /*
9292diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
9293index d5e5042..9bfee76 100644
9294--- a/arch/sparc/include/asm/thread_info_64.h
9295+++ b/arch/sparc/include/asm/thread_info_64.h
9296@@ -63,6 +63,8 @@ struct thread_info {
9297 struct pt_regs *kern_una_regs;
9298 unsigned int kern_una_insn;
9299
9300+ unsigned long lowest_stack;
9301+
9302 unsigned long fpregs[0] __attribute__ ((aligned(64)));
9303 };
9304
9305@@ -192,10 +194,11 @@ register struct thread_info *current_thread_info_reg asm("g6");
9306 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
9307 /* flag bit 6 is available */
9308 #define TIF_32BIT 7 /* 32-bit binary */
9309-/* flag bit 8 is available */
9310+#define TIF_GRSEC_SETXID 8 /* update credentials on syscall entry/exit */
9311 #define TIF_SECCOMP 9 /* secure computing */
9312 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
9313 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
9314+
9315 /* NOTE: Thread flags >= 12 should be ones we have no interest
9316 * in using in assembly, else we can't use the mask as
9317 * an immediate value in instructions such as andcc.
9318@@ -214,12 +217,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
9319 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
9320 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
9321 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
9322+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
9323
9324 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
9325 _TIF_DO_NOTIFY_RESUME_MASK | \
9326 _TIF_NEED_RESCHED)
9327 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
9328
9329+#define _TIF_WORK_SYSCALL \
9330+ (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
9331+ _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
9332+
9333+
9334 /*
9335 * Thread-synchronous status.
9336 *
9337diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
9338index 0167d26..767bb0c 100644
9339--- a/arch/sparc/include/asm/uaccess.h
9340+++ b/arch/sparc/include/asm/uaccess.h
9341@@ -1,5 +1,6 @@
9342 #ifndef ___ASM_SPARC_UACCESS_H
9343 #define ___ASM_SPARC_UACCESS_H
9344+
9345 #if defined(__sparc__) && defined(__arch64__)
9346 #include <asm/uaccess_64.h>
9347 #else
9348diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
9349index 53a28dd..50c38c3 100644
9350--- a/arch/sparc/include/asm/uaccess_32.h
9351+++ b/arch/sparc/include/asm/uaccess_32.h
9352@@ -250,27 +250,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
9353
9354 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
9355 {
9356- if (n && __access_ok((unsigned long) to, n))
9357+ if ((long)n < 0)
9358+ return n;
9359+
9360+ if (n && __access_ok((unsigned long) to, n)) {
9361+ if (!__builtin_constant_p(n))
9362+ check_object_size(from, n, true);
9363 return __copy_user(to, (__force void __user *) from, n);
9364- else
9365+ } else
9366 return n;
9367 }
9368
9369 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
9370 {
9371+ if ((long)n < 0)
9372+ return n;
9373+
9374+ if (!__builtin_constant_p(n))
9375+ check_object_size(from, n, true);
9376+
9377 return __copy_user(to, (__force void __user *) from, n);
9378 }
9379
9380 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
9381 {
9382- if (n && __access_ok((unsigned long) from, n))
9383+ if ((long)n < 0)
9384+ return n;
9385+
9386+ if (n && __access_ok((unsigned long) from, n)) {
9387+ if (!__builtin_constant_p(n))
9388+ check_object_size(to, n, false);
9389 return __copy_user((__force void __user *) to, from, n);
9390- else
9391+ } else
9392 return n;
9393 }
9394
9395 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
9396 {
9397+ if ((long)n < 0)
9398+ return n;
9399+
9400 return __copy_user((__force void __user *) to, from, n);
9401 }
9402
9403diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
9404index e562d3c..191f176 100644
9405--- a/arch/sparc/include/asm/uaccess_64.h
9406+++ b/arch/sparc/include/asm/uaccess_64.h
9407@@ -10,6 +10,7 @@
9408 #include <linux/compiler.h>
9409 #include <linux/string.h>
9410 #include <linux/thread_info.h>
9411+#include <linux/kernel.h>
9412 #include <asm/asi.h>
9413 #include <asm/spitfire.h>
9414 #include <asm-generic/uaccess-unaligned.h>
9415@@ -214,8 +215,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
9416 static inline unsigned long __must_check
9417 copy_from_user(void *to, const void __user *from, unsigned long size)
9418 {
9419- unsigned long ret = ___copy_from_user(to, from, size);
9420+ unsigned long ret;
9421
9422+ if ((long)size < 0 || size > INT_MAX)
9423+ return size;
9424+
9425+ if (!__builtin_constant_p(size))
9426+ check_object_size(to, size, false);
9427+
9428+ ret = ___copy_from_user(to, from, size);
9429 if (unlikely(ret))
9430 ret = copy_from_user_fixup(to, from, size);
9431
9432@@ -231,8 +239,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
9433 static inline unsigned long __must_check
9434 copy_to_user(void __user *to, const void *from, unsigned long size)
9435 {
9436- unsigned long ret = ___copy_to_user(to, from, size);
9437+ unsigned long ret;
9438
9439+ if ((long)size < 0 || size > INT_MAX)
9440+ return size;
9441+
9442+ if (!__builtin_constant_p(size))
9443+ check_object_size(from, size, true);
9444+
9445+ ret = ___copy_to_user(to, from, size);
9446 if (unlikely(ret))
9447 ret = copy_to_user_fixup(to, from, size);
9448 return ret;
9449diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
9450index d15cc17..d0ae796 100644
9451--- a/arch/sparc/kernel/Makefile
9452+++ b/arch/sparc/kernel/Makefile
9453@@ -4,7 +4,7 @@
9454 #
9455
9456 asflags-y := -ansi
9457-ccflags-y := -Werror
9458+#ccflags-y := -Werror
9459
9460 extra-y := head_$(BITS).o
9461
9462diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
9463index fdd819d..5af08c8 100644
9464--- a/arch/sparc/kernel/process_32.c
9465+++ b/arch/sparc/kernel/process_32.c
9466@@ -116,14 +116,14 @@ void show_regs(struct pt_regs *r)
9467
9468 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
9469 r->psr, r->pc, r->npc, r->y, print_tainted());
9470- printk("PC: <%pS>\n", (void *) r->pc);
9471+ printk("PC: <%pA>\n", (void *) r->pc);
9472 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
9473 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
9474 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
9475 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
9476 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
9477 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
9478- printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
9479+ printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
9480
9481 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
9482 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
9483@@ -160,7 +160,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
9484 rw = (struct reg_window32 *) fp;
9485 pc = rw->ins[7];
9486 printk("[%08lx : ", pc);
9487- printk("%pS ] ", (void *) pc);
9488+ printk("%pA ] ", (void *) pc);
9489 fp = rw->ins[6];
9490 } while (++count < 16);
9491 printk("\n");
9492diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
9493index baebab2..9cd13b1 100644
9494--- a/arch/sparc/kernel/process_64.c
9495+++ b/arch/sparc/kernel/process_64.c
9496@@ -158,7 +158,7 @@ static void show_regwindow(struct pt_regs *regs)
9497 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
9498 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
9499 if (regs->tstate & TSTATE_PRIV)
9500- printk("I7: <%pS>\n", (void *) rwk->ins[7]);
9501+ printk("I7: <%pA>\n", (void *) rwk->ins[7]);
9502 }
9503
9504 void show_regs(struct pt_regs *regs)
9505@@ -167,7 +167,7 @@ void show_regs(struct pt_regs *regs)
9506
9507 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
9508 regs->tpc, regs->tnpc, regs->y, print_tainted());
9509- printk("TPC: <%pS>\n", (void *) regs->tpc);
9510+ printk("TPC: <%pA>\n", (void *) regs->tpc);
9511 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
9512 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
9513 regs->u_regs[3]);
9514@@ -180,7 +180,7 @@ void show_regs(struct pt_regs *regs)
9515 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
9516 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
9517 regs->u_regs[15]);
9518- printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
9519+ printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
9520 show_regwindow(regs);
9521 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
9522 }
9523@@ -269,7 +269,7 @@ void arch_trigger_all_cpu_backtrace(void)
9524 ((tp && tp->task) ? tp->task->pid : -1));
9525
9526 if (gp->tstate & TSTATE_PRIV) {
9527- printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
9528+ printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
9529 (void *) gp->tpc,
9530 (void *) gp->o7,
9531 (void *) gp->i7,
9532diff --git a/arch/sparc/kernel/prom_common.c b/arch/sparc/kernel/prom_common.c
9533index 79cc0d1..ec62734 100644
9534--- a/arch/sparc/kernel/prom_common.c
9535+++ b/arch/sparc/kernel/prom_common.c
9536@@ -144,7 +144,7 @@ static int __init prom_common_nextprop(phandle node, char *prev, char *buf)
9537
9538 unsigned int prom_early_allocated __initdata;
9539
9540-static struct of_pdt_ops prom_sparc_ops __initdata = {
9541+static struct of_pdt_ops prom_sparc_ops __initconst = {
9542 .nextprop = prom_common_nextprop,
9543 .getproplen = prom_getproplen,
9544 .getproperty = prom_getproperty,
9545diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
9546index 773c1f2..a8bdd87 100644
9547--- a/arch/sparc/kernel/ptrace_64.c
9548+++ b/arch/sparc/kernel/ptrace_64.c
9549@@ -1059,6 +1059,10 @@ long arch_ptrace(struct task_struct *child, long request,
9550 return ret;
9551 }
9552
9553+#ifdef CONFIG_GRKERNSEC_SETXID
9554+extern void gr_delayed_cred_worker(void);
9555+#endif
9556+
9557 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
9558 {
9559 int ret = 0;
9560@@ -1066,6 +1070,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
9561 /* do the secure computing check first */
9562 secure_computing_strict(regs->u_regs[UREG_G1]);
9563
9564+#ifdef CONFIG_GRKERNSEC_SETXID
9565+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
9566+ gr_delayed_cred_worker();
9567+#endif
9568+
9569 if (test_thread_flag(TIF_SYSCALL_TRACE))
9570 ret = tracehook_report_syscall_entry(regs);
9571
9572@@ -1086,6 +1095,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
9573
9574 asmlinkage void syscall_trace_leave(struct pt_regs *regs)
9575 {
9576+#ifdef CONFIG_GRKERNSEC_SETXID
9577+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
9578+ gr_delayed_cred_worker();
9579+#endif
9580+
9581 audit_syscall_exit(regs);
9582
9583 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
9584diff --git a/arch/sparc/kernel/smp_64.c b/arch/sparc/kernel/smp_64.c
9585index e142545..fd29654 100644
9586--- a/arch/sparc/kernel/smp_64.c
9587+++ b/arch/sparc/kernel/smp_64.c
9588@@ -869,8 +869,8 @@ extern unsigned long xcall_flush_dcache_page_cheetah;
9589 extern unsigned long xcall_flush_dcache_page_spitfire;
9590
9591 #ifdef CONFIG_DEBUG_DCFLUSH
9592-extern atomic_t dcpage_flushes;
9593-extern atomic_t dcpage_flushes_xcall;
9594+extern atomic_unchecked_t dcpage_flushes;
9595+extern atomic_unchecked_t dcpage_flushes_xcall;
9596 #endif
9597
9598 static inline void __local_flush_dcache_page(struct page *page)
9599@@ -894,7 +894,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
9600 return;
9601
9602 #ifdef CONFIG_DEBUG_DCFLUSH
9603- atomic_inc(&dcpage_flushes);
9604+ atomic_inc_unchecked(&dcpage_flushes);
9605 #endif
9606
9607 this_cpu = get_cpu();
9608@@ -918,7 +918,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
9609 xcall_deliver(data0, __pa(pg_addr),
9610 (u64) pg_addr, cpumask_of(cpu));
9611 #ifdef CONFIG_DEBUG_DCFLUSH
9612- atomic_inc(&dcpage_flushes_xcall);
9613+ atomic_inc_unchecked(&dcpage_flushes_xcall);
9614 #endif
9615 }
9616 }
9617@@ -937,7 +937,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
9618 preempt_disable();
9619
9620 #ifdef CONFIG_DEBUG_DCFLUSH
9621- atomic_inc(&dcpage_flushes);
9622+ atomic_inc_unchecked(&dcpage_flushes);
9623 #endif
9624 data0 = 0;
9625 pg_addr = page_address(page);
9626@@ -954,7 +954,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
9627 xcall_deliver(data0, __pa(pg_addr),
9628 (u64) pg_addr, cpu_online_mask);
9629 #ifdef CONFIG_DEBUG_DCFLUSH
9630- atomic_inc(&dcpage_flushes_xcall);
9631+ atomic_inc_unchecked(&dcpage_flushes_xcall);
9632 #endif
9633 }
9634 __local_flush_dcache_page(page);
9635diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
9636index 3a8d184..49498a8 100644
9637--- a/arch/sparc/kernel/sys_sparc_32.c
9638+++ b/arch/sparc/kernel/sys_sparc_32.c
9639@@ -52,7 +52,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
9640 if (len > TASK_SIZE - PAGE_SIZE)
9641 return -ENOMEM;
9642 if (!addr)
9643- addr = TASK_UNMAPPED_BASE;
9644+ addr = current->mm->mmap_base;
9645
9646 info.flags = 0;
9647 info.length = len;
9648diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
9649index 51561b8..8256764 100644
9650--- a/arch/sparc/kernel/sys_sparc_64.c
9651+++ b/arch/sparc/kernel/sys_sparc_64.c
9652@@ -90,13 +90,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
9653 struct vm_area_struct * vma;
9654 unsigned long task_size = TASK_SIZE;
9655 int do_color_align;
9656+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9657 struct vm_unmapped_area_info info;
9658
9659 if (flags & MAP_FIXED) {
9660 /* We do not accept a shared mapping if it would violate
9661 * cache aliasing constraints.
9662 */
9663- if ((flags & MAP_SHARED) &&
9664+ if ((filp || (flags & MAP_SHARED)) &&
9665 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
9666 return -EINVAL;
9667 return addr;
9668@@ -111,6 +112,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
9669 if (filp || (flags & MAP_SHARED))
9670 do_color_align = 1;
9671
9672+#ifdef CONFIG_PAX_RANDMMAP
9673+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9674+#endif
9675+
9676 if (addr) {
9677 if (do_color_align)
9678 addr = COLOR_ALIGN(addr, pgoff);
9679@@ -118,22 +123,28 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
9680 addr = PAGE_ALIGN(addr);
9681
9682 vma = find_vma(mm, addr);
9683- if (task_size - len >= addr &&
9684- (!vma || addr + len <= vma->vm_start))
9685+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9686 return addr;
9687 }
9688
9689 info.flags = 0;
9690 info.length = len;
9691- info.low_limit = TASK_UNMAPPED_BASE;
9692+ info.low_limit = mm->mmap_base;
9693 info.high_limit = min(task_size, VA_EXCLUDE_START);
9694 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
9695 info.align_offset = pgoff << PAGE_SHIFT;
9696+ info.threadstack_offset = offset;
9697 addr = vm_unmapped_area(&info);
9698
9699 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
9700 VM_BUG_ON(addr != -ENOMEM);
9701 info.low_limit = VA_EXCLUDE_END;
9702+
9703+#ifdef CONFIG_PAX_RANDMMAP
9704+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9705+ info.low_limit += mm->delta_mmap;
9706+#endif
9707+
9708 info.high_limit = task_size;
9709 addr = vm_unmapped_area(&info);
9710 }
9711@@ -151,6 +162,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9712 unsigned long task_size = STACK_TOP32;
9713 unsigned long addr = addr0;
9714 int do_color_align;
9715+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9716 struct vm_unmapped_area_info info;
9717
9718 /* This should only ever run for 32-bit processes. */
9719@@ -160,7 +172,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9720 /* We do not accept a shared mapping if it would violate
9721 * cache aliasing constraints.
9722 */
9723- if ((flags & MAP_SHARED) &&
9724+ if ((filp || (flags & MAP_SHARED)) &&
9725 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
9726 return -EINVAL;
9727 return addr;
9728@@ -173,6 +185,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9729 if (filp || (flags & MAP_SHARED))
9730 do_color_align = 1;
9731
9732+#ifdef CONFIG_PAX_RANDMMAP
9733+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9734+#endif
9735+
9736 /* requesting a specific address */
9737 if (addr) {
9738 if (do_color_align)
9739@@ -181,8 +197,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9740 addr = PAGE_ALIGN(addr);
9741
9742 vma = find_vma(mm, addr);
9743- if (task_size - len >= addr &&
9744- (!vma || addr + len <= vma->vm_start))
9745+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9746 return addr;
9747 }
9748
9749@@ -192,6 +207,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9750 info.high_limit = mm->mmap_base;
9751 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
9752 info.align_offset = pgoff << PAGE_SHIFT;
9753+ info.threadstack_offset = offset;
9754 addr = vm_unmapped_area(&info);
9755
9756 /*
9757@@ -204,6 +220,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9758 VM_BUG_ON(addr != -ENOMEM);
9759 info.flags = 0;
9760 info.low_limit = TASK_UNMAPPED_BASE;
9761+
9762+#ifdef CONFIG_PAX_RANDMMAP
9763+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9764+ info.low_limit += mm->delta_mmap;
9765+#endif
9766+
9767 info.high_limit = STACK_TOP32;
9768 addr = vm_unmapped_area(&info);
9769 }
9770@@ -260,10 +282,14 @@ unsigned long get_fb_unmapped_area(struct file *filp, unsigned long orig_addr, u
9771 EXPORT_SYMBOL(get_fb_unmapped_area);
9772
9773 /* Essentially the same as PowerPC. */
9774-static unsigned long mmap_rnd(void)
9775+static unsigned long mmap_rnd(struct mm_struct *mm)
9776 {
9777 unsigned long rnd = 0UL;
9778
9779+#ifdef CONFIG_PAX_RANDMMAP
9780+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9781+#endif
9782+
9783 if (current->flags & PF_RANDOMIZE) {
9784 unsigned long val = get_random_int();
9785 if (test_thread_flag(TIF_32BIT))
9786@@ -276,7 +302,7 @@ static unsigned long mmap_rnd(void)
9787
9788 void arch_pick_mmap_layout(struct mm_struct *mm)
9789 {
9790- unsigned long random_factor = mmap_rnd();
9791+ unsigned long random_factor = mmap_rnd(mm);
9792 unsigned long gap;
9793
9794 /*
9795@@ -289,6 +315,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9796 gap == RLIM_INFINITY ||
9797 sysctl_legacy_va_layout) {
9798 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
9799+
9800+#ifdef CONFIG_PAX_RANDMMAP
9801+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9802+ mm->mmap_base += mm->delta_mmap;
9803+#endif
9804+
9805 mm->get_unmapped_area = arch_get_unmapped_area;
9806 } else {
9807 /* We know it's 32-bit */
9808@@ -300,6 +332,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9809 gap = (task_size / 6 * 5);
9810
9811 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
9812+
9813+#ifdef CONFIG_PAX_RANDMMAP
9814+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9815+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9816+#endif
9817+
9818 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
9819 }
9820 }
9821diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
9822index d950197..192f9d8 100644
9823--- a/arch/sparc/kernel/syscalls.S
9824+++ b/arch/sparc/kernel/syscalls.S
9825@@ -52,7 +52,7 @@ sys32_rt_sigreturn:
9826 #endif
9827 .align 32
9828 1: ldx [%g6 + TI_FLAGS], %l5
9829- andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
9830+ andcc %l5, _TIF_WORK_SYSCALL, %g0
9831 be,pt %icc, rtrap
9832 nop
9833 call syscall_trace_leave
9834@@ -184,7 +184,7 @@ linux_sparc_syscall32:
9835
9836 srl %i3, 0, %o3 ! IEU0
9837 srl %i2, 0, %o2 ! IEU0 Group
9838- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
9839+ andcc %l0, _TIF_WORK_SYSCALL, %g0
9840 bne,pn %icc, linux_syscall_trace32 ! CTI
9841 mov %i0, %l5 ! IEU1
9842 5: call %l7 ! CTI Group brk forced
9843@@ -207,7 +207,7 @@ linux_sparc_syscall:
9844
9845 mov %i3, %o3 ! IEU1
9846 mov %i4, %o4 ! IEU0 Group
9847- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
9848+ andcc %l0, _TIF_WORK_SYSCALL, %g0
9849 bne,pn %icc, linux_syscall_trace ! CTI Group
9850 mov %i0, %l5 ! IEU0
9851 2: call %l7 ! CTI Group brk forced
9852@@ -223,7 +223,7 @@ ret_sys_call:
9853
9854 cmp %o0, -ERESTART_RESTARTBLOCK
9855 bgeu,pn %xcc, 1f
9856- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
9857+ andcc %l0, _TIF_WORK_SYSCALL, %g0
9858 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
9859
9860 2:
9861diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
9862index 6629829..036032d 100644
9863--- a/arch/sparc/kernel/traps_32.c
9864+++ b/arch/sparc/kernel/traps_32.c
9865@@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
9866 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
9867 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
9868
9869+extern void gr_handle_kernel_exploit(void);
9870+
9871 void die_if_kernel(char *str, struct pt_regs *regs)
9872 {
9873 static int die_counter;
9874@@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
9875 count++ < 30 &&
9876 (((unsigned long) rw) >= PAGE_OFFSET) &&
9877 !(((unsigned long) rw) & 0x7)) {
9878- printk("Caller[%08lx]: %pS\n", rw->ins[7],
9879+ printk("Caller[%08lx]: %pA\n", rw->ins[7],
9880 (void *) rw->ins[7]);
9881 rw = (struct reg_window32 *)rw->ins[6];
9882 }
9883 }
9884 printk("Instruction DUMP:");
9885 instruction_dump ((unsigned long *) regs->pc);
9886- if(regs->psr & PSR_PS)
9887+ if(regs->psr & PSR_PS) {
9888+ gr_handle_kernel_exploit();
9889 do_exit(SIGKILL);
9890+ }
9891 do_exit(SIGSEGV);
9892 }
9893
9894diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
9895index b3f833a..f485f80 100644
9896--- a/arch/sparc/kernel/traps_64.c
9897+++ b/arch/sparc/kernel/traps_64.c
9898@@ -76,7 +76,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
9899 i + 1,
9900 p->trapstack[i].tstate, p->trapstack[i].tpc,
9901 p->trapstack[i].tnpc, p->trapstack[i].tt);
9902- printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
9903+ printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
9904 }
9905 }
9906
9907@@ -96,6 +96,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
9908
9909 lvl -= 0x100;
9910 if (regs->tstate & TSTATE_PRIV) {
9911+
9912+#ifdef CONFIG_PAX_REFCOUNT
9913+ if (lvl == 6)
9914+ pax_report_refcount_overflow(regs);
9915+#endif
9916+
9917 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
9918 die_if_kernel(buffer, regs);
9919 }
9920@@ -114,11 +120,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
9921 void bad_trap_tl1(struct pt_regs *regs, long lvl)
9922 {
9923 char buffer[32];
9924-
9925+
9926 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
9927 0, lvl, SIGTRAP) == NOTIFY_STOP)
9928 return;
9929
9930+#ifdef CONFIG_PAX_REFCOUNT
9931+ if (lvl == 6)
9932+ pax_report_refcount_overflow(regs);
9933+#endif
9934+
9935 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
9936
9937 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
9938@@ -1142,7 +1153,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
9939 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
9940 printk("%s" "ERROR(%d): ",
9941 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
9942- printk("TPC<%pS>\n", (void *) regs->tpc);
9943+ printk("TPC<%pA>\n", (void *) regs->tpc);
9944 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
9945 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
9946 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
9947@@ -1749,7 +1760,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
9948 smp_processor_id(),
9949 (type & 0x1) ? 'I' : 'D',
9950 regs->tpc);
9951- printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
9952+ printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
9953 panic("Irrecoverable Cheetah+ parity error.");
9954 }
9955
9956@@ -1757,7 +1768,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
9957 smp_processor_id(),
9958 (type & 0x1) ? 'I' : 'D',
9959 regs->tpc);
9960- printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
9961+ printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
9962 }
9963
9964 struct sun4v_error_entry {
9965@@ -1830,8 +1841,8 @@ struct sun4v_error_entry {
9966 /*0x38*/u64 reserved_5;
9967 };
9968
9969-static atomic_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
9970-static atomic_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
9971+static atomic_unchecked_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
9972+static atomic_unchecked_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
9973
9974 static const char *sun4v_err_type_to_str(u8 type)
9975 {
9976@@ -1923,7 +1934,7 @@ static void sun4v_report_real_raddr(const char *pfx, struct pt_regs *regs)
9977 }
9978
9979 static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
9980- int cpu, const char *pfx, atomic_t *ocnt)
9981+ int cpu, const char *pfx, atomic_unchecked_t *ocnt)
9982 {
9983 u64 *raw_ptr = (u64 *) ent;
9984 u32 attrs;
9985@@ -1981,8 +1992,8 @@ static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
9986
9987 show_regs(regs);
9988
9989- if ((cnt = atomic_read(ocnt)) != 0) {
9990- atomic_set(ocnt, 0);
9991+ if ((cnt = atomic_read_unchecked(ocnt)) != 0) {
9992+ atomic_set_unchecked(ocnt, 0);
9993 wmb();
9994 printk("%s: Queue overflowed %d times.\n",
9995 pfx, cnt);
9996@@ -2036,7 +2047,7 @@ void sun4v_resum_error(struct pt_regs *regs, unsigned long offset)
9997 */
9998 void sun4v_resum_overflow(struct pt_regs *regs)
9999 {
10000- atomic_inc(&sun4v_resum_oflow_cnt);
10001+ atomic_inc_unchecked(&sun4v_resum_oflow_cnt);
10002 }
10003
10004 /* We run with %pil set to PIL_NORMAL_MAX and PSTATE_IE enabled in %pstate.
10005@@ -2089,7 +2100,7 @@ void sun4v_nonresum_overflow(struct pt_regs *regs)
10006 /* XXX Actually even this can make not that much sense. Perhaps
10007 * XXX we should just pull the plug and panic directly from here?
10008 */
10009- atomic_inc(&sun4v_nonresum_oflow_cnt);
10010+ atomic_inc_unchecked(&sun4v_nonresum_oflow_cnt);
10011 }
10012
10013 unsigned long sun4v_err_itlb_vaddr;
10014@@ -2104,9 +2115,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
10015
10016 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
10017 regs->tpc, tl);
10018- printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
10019+ printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
10020 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
10021- printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
10022+ printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
10023 (void *) regs->u_regs[UREG_I7]);
10024 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
10025 "pte[%lx] error[%lx]\n",
10026@@ -2128,9 +2139,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
10027
10028 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
10029 regs->tpc, tl);
10030- printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
10031+ printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
10032 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
10033- printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
10034+ printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
10035 (void *) regs->u_regs[UREG_I7]);
10036 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
10037 "pte[%lx] error[%lx]\n",
10038@@ -2336,13 +2347,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
10039 fp = (unsigned long)sf->fp + STACK_BIAS;
10040 }
10041
10042- printk(" [%016lx] %pS\n", pc, (void *) pc);
10043+ printk(" [%016lx] %pA\n", pc, (void *) pc);
10044 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
10045 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
10046 int index = tsk->curr_ret_stack;
10047 if (tsk->ret_stack && index >= graph) {
10048 pc = tsk->ret_stack[index - graph].ret;
10049- printk(" [%016lx] %pS\n", pc, (void *) pc);
10050+ printk(" [%016lx] %pA\n", pc, (void *) pc);
10051 graph++;
10052 }
10053 }
10054@@ -2360,6 +2371,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
10055 return (struct reg_window *) (fp + STACK_BIAS);
10056 }
10057
10058+extern void gr_handle_kernel_exploit(void);
10059+
10060 void die_if_kernel(char *str, struct pt_regs *regs)
10061 {
10062 static int die_counter;
10063@@ -2388,7 +2401,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10064 while (rw &&
10065 count++ < 30 &&
10066 kstack_valid(tp, (unsigned long) rw)) {
10067- printk("Caller[%016lx]: %pS\n", rw->ins[7],
10068+ printk("Caller[%016lx]: %pA\n", rw->ins[7],
10069 (void *) rw->ins[7]);
10070
10071 rw = kernel_stack_up(rw);
10072@@ -2401,8 +2414,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10073 }
10074 user_instruction_dump ((unsigned int __user *) regs->tpc);
10075 }
10076- if (regs->tstate & TSTATE_PRIV)
10077+ if (regs->tstate & TSTATE_PRIV) {
10078+ gr_handle_kernel_exploit();
10079 do_exit(SIGKILL);
10080+ }
10081 do_exit(SIGSEGV);
10082 }
10083 EXPORT_SYMBOL(die_if_kernel);
10084diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
10085index 8201c25e..072a2a7 100644
10086--- a/arch/sparc/kernel/unaligned_64.c
10087+++ b/arch/sparc/kernel/unaligned_64.c
10088@@ -286,7 +286,7 @@ static void log_unaligned(struct pt_regs *regs)
10089 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
10090
10091 if (__ratelimit(&ratelimit)) {
10092- printk("Kernel unaligned access at TPC[%lx] %pS\n",
10093+ printk("Kernel unaligned access at TPC[%lx] %pA\n",
10094 regs->tpc, (void *) regs->tpc);
10095 }
10096 }
10097diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
10098index dbe119b..089c7c1 100644
10099--- a/arch/sparc/lib/Makefile
10100+++ b/arch/sparc/lib/Makefile
10101@@ -2,7 +2,7 @@
10102 #
10103
10104 asflags-y := -ansi -DST_DIV0=0x02
10105-ccflags-y := -Werror
10106+#ccflags-y := -Werror
10107
10108 lib-$(CONFIG_SPARC32) += ashrdi3.o
10109 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
10110diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
10111index 85c233d..68500e0 100644
10112--- a/arch/sparc/lib/atomic_64.S
10113+++ b/arch/sparc/lib/atomic_64.S
10114@@ -17,7 +17,12 @@
10115 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
10116 BACKOFF_SETUP(%o2)
10117 1: lduw [%o1], %g1
10118- add %g1, %o0, %g7
10119+ addcc %g1, %o0, %g7
10120+
10121+#ifdef CONFIG_PAX_REFCOUNT
10122+ tvs %icc, 6
10123+#endif
10124+
10125 cas [%o1], %g1, %g7
10126 cmp %g1, %g7
10127 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10128@@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
10129 2: BACKOFF_SPIN(%o2, %o3, 1b)
10130 ENDPROC(atomic_add)
10131
10132+ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10133+ BACKOFF_SETUP(%o2)
10134+1: lduw [%o1], %g1
10135+ add %g1, %o0, %g7
10136+ cas [%o1], %g1, %g7
10137+ cmp %g1, %g7
10138+ bne,pn %icc, 2f
10139+ nop
10140+ retl
10141+ nop
10142+2: BACKOFF_SPIN(%o2, %o3, 1b)
10143+ENDPROC(atomic_add_unchecked)
10144+
10145 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10146 BACKOFF_SETUP(%o2)
10147 1: lduw [%o1], %g1
10148- sub %g1, %o0, %g7
10149+ subcc %g1, %o0, %g7
10150+
10151+#ifdef CONFIG_PAX_REFCOUNT
10152+ tvs %icc, 6
10153+#endif
10154+
10155 cas [%o1], %g1, %g7
10156 cmp %g1, %g7
10157 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10158@@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10159 2: BACKOFF_SPIN(%o2, %o3, 1b)
10160 ENDPROC(atomic_sub)
10161
10162+ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
10163+ BACKOFF_SETUP(%o2)
10164+1: lduw [%o1], %g1
10165+ sub %g1, %o0, %g7
10166+ cas [%o1], %g1, %g7
10167+ cmp %g1, %g7
10168+ bne,pn %icc, 2f
10169+ nop
10170+ retl
10171+ nop
10172+2: BACKOFF_SPIN(%o2, %o3, 1b)
10173+ENDPROC(atomic_sub_unchecked)
10174+
10175 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10176 BACKOFF_SETUP(%o2)
10177 1: lduw [%o1], %g1
10178- add %g1, %o0, %g7
10179+ addcc %g1, %o0, %g7
10180+
10181+#ifdef CONFIG_PAX_REFCOUNT
10182+ tvs %icc, 6
10183+#endif
10184+
10185 cas [%o1], %g1, %g7
10186 cmp %g1, %g7
10187 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10188@@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10189 2: BACKOFF_SPIN(%o2, %o3, 1b)
10190 ENDPROC(atomic_add_ret)
10191
10192+ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10193+ BACKOFF_SETUP(%o2)
10194+1: lduw [%o1], %g1
10195+ addcc %g1, %o0, %g7
10196+ cas [%o1], %g1, %g7
10197+ cmp %g1, %g7
10198+ bne,pn %icc, 2f
10199+ add %g7, %o0, %g7
10200+ sra %g7, 0, %o0
10201+ retl
10202+ nop
10203+2: BACKOFF_SPIN(%o2, %o3, 1b)
10204+ENDPROC(atomic_add_ret_unchecked)
10205+
10206 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
10207 BACKOFF_SETUP(%o2)
10208 1: lduw [%o1], %g1
10209- sub %g1, %o0, %g7
10210+ subcc %g1, %o0, %g7
10211+
10212+#ifdef CONFIG_PAX_REFCOUNT
10213+ tvs %icc, 6
10214+#endif
10215+
10216 cas [%o1], %g1, %g7
10217 cmp %g1, %g7
10218 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10219@@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
10220 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
10221 BACKOFF_SETUP(%o2)
10222 1: ldx [%o1], %g1
10223- add %g1, %o0, %g7
10224+ addcc %g1, %o0, %g7
10225+
10226+#ifdef CONFIG_PAX_REFCOUNT
10227+ tvs %xcc, 6
10228+#endif
10229+
10230 casx [%o1], %g1, %g7
10231 cmp %g1, %g7
10232 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10233@@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
10234 2: BACKOFF_SPIN(%o2, %o3, 1b)
10235 ENDPROC(atomic64_add)
10236
10237+ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10238+ BACKOFF_SETUP(%o2)
10239+1: ldx [%o1], %g1
10240+ addcc %g1, %o0, %g7
10241+ casx [%o1], %g1, %g7
10242+ cmp %g1, %g7
10243+ bne,pn %xcc, 2f
10244+ nop
10245+ retl
10246+ nop
10247+2: BACKOFF_SPIN(%o2, %o3, 1b)
10248+ENDPROC(atomic64_add_unchecked)
10249+
10250 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10251 BACKOFF_SETUP(%o2)
10252 1: ldx [%o1], %g1
10253- sub %g1, %o0, %g7
10254+ subcc %g1, %o0, %g7
10255+
10256+#ifdef CONFIG_PAX_REFCOUNT
10257+ tvs %xcc, 6
10258+#endif
10259+
10260 casx [%o1], %g1, %g7
10261 cmp %g1, %g7
10262 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10263@@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10264 2: BACKOFF_SPIN(%o2, %o3, 1b)
10265 ENDPROC(atomic64_sub)
10266
10267+ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
10268+ BACKOFF_SETUP(%o2)
10269+1: ldx [%o1], %g1
10270+ subcc %g1, %o0, %g7
10271+ casx [%o1], %g1, %g7
10272+ cmp %g1, %g7
10273+ bne,pn %xcc, 2f
10274+ nop
10275+ retl
10276+ nop
10277+2: BACKOFF_SPIN(%o2, %o3, 1b)
10278+ENDPROC(atomic64_sub_unchecked)
10279+
10280 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10281 BACKOFF_SETUP(%o2)
10282 1: ldx [%o1], %g1
10283- add %g1, %o0, %g7
10284+ addcc %g1, %o0, %g7
10285+
10286+#ifdef CONFIG_PAX_REFCOUNT
10287+ tvs %xcc, 6
10288+#endif
10289+
10290 casx [%o1], %g1, %g7
10291 cmp %g1, %g7
10292 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10293@@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10294 2: BACKOFF_SPIN(%o2, %o3, 1b)
10295 ENDPROC(atomic64_add_ret)
10296
10297+ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10298+ BACKOFF_SETUP(%o2)
10299+1: ldx [%o1], %g1
10300+ addcc %g1, %o0, %g7
10301+ casx [%o1], %g1, %g7
10302+ cmp %g1, %g7
10303+ bne,pn %xcc, 2f
10304+ add %g7, %o0, %g7
10305+ mov %g7, %o0
10306+ retl
10307+ nop
10308+2: BACKOFF_SPIN(%o2, %o3, 1b)
10309+ENDPROC(atomic64_add_ret_unchecked)
10310+
10311 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
10312 BACKOFF_SETUP(%o2)
10313 1: ldx [%o1], %g1
10314- sub %g1, %o0, %g7
10315+ subcc %g1, %o0, %g7
10316+
10317+#ifdef CONFIG_PAX_REFCOUNT
10318+ tvs %xcc, 6
10319+#endif
10320+
10321 casx [%o1], %g1, %g7
10322 cmp %g1, %g7
10323 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10324diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
10325index 323335b..ed85ea2 100644
10326--- a/arch/sparc/lib/ksyms.c
10327+++ b/arch/sparc/lib/ksyms.c
10328@@ -100,12 +100,18 @@ EXPORT_SYMBOL(__clear_user);
10329
10330 /* Atomic counter implementation. */
10331 EXPORT_SYMBOL(atomic_add);
10332+EXPORT_SYMBOL(atomic_add_unchecked);
10333 EXPORT_SYMBOL(atomic_add_ret);
10334+EXPORT_SYMBOL(atomic_add_ret_unchecked);
10335 EXPORT_SYMBOL(atomic_sub);
10336+EXPORT_SYMBOL(atomic_sub_unchecked);
10337 EXPORT_SYMBOL(atomic_sub_ret);
10338 EXPORT_SYMBOL(atomic64_add);
10339+EXPORT_SYMBOL(atomic64_add_unchecked);
10340 EXPORT_SYMBOL(atomic64_add_ret);
10341+EXPORT_SYMBOL(atomic64_add_ret_unchecked);
10342 EXPORT_SYMBOL(atomic64_sub);
10343+EXPORT_SYMBOL(atomic64_sub_unchecked);
10344 EXPORT_SYMBOL(atomic64_sub_ret);
10345 EXPORT_SYMBOL(atomic64_dec_if_positive);
10346
10347diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
10348index 30c3ecc..736f015 100644
10349--- a/arch/sparc/mm/Makefile
10350+++ b/arch/sparc/mm/Makefile
10351@@ -2,7 +2,7 @@
10352 #
10353
10354 asflags-y := -ansi
10355-ccflags-y := -Werror
10356+#ccflags-y := -Werror
10357
10358 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
10359 obj-y += fault_$(BITS).o
10360diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
10361index 59dbd46..1dd7f5e 100644
10362--- a/arch/sparc/mm/fault_32.c
10363+++ b/arch/sparc/mm/fault_32.c
10364@@ -21,6 +21,9 @@
10365 #include <linux/perf_event.h>
10366 #include <linux/interrupt.h>
10367 #include <linux/kdebug.h>
10368+#include <linux/slab.h>
10369+#include <linux/pagemap.h>
10370+#include <linux/compiler.h>
10371
10372 #include <asm/page.h>
10373 #include <asm/pgtable.h>
10374@@ -159,6 +162,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
10375 return safe_compute_effective_address(regs, insn);
10376 }
10377
10378+#ifdef CONFIG_PAX_PAGEEXEC
10379+#ifdef CONFIG_PAX_DLRESOLVE
10380+static void pax_emuplt_close(struct vm_area_struct *vma)
10381+{
10382+ vma->vm_mm->call_dl_resolve = 0UL;
10383+}
10384+
10385+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
10386+{
10387+ unsigned int *kaddr;
10388+
10389+ vmf->page = alloc_page(GFP_HIGHUSER);
10390+ if (!vmf->page)
10391+ return VM_FAULT_OOM;
10392+
10393+ kaddr = kmap(vmf->page);
10394+ memset(kaddr, 0, PAGE_SIZE);
10395+ kaddr[0] = 0x9DE3BFA8U; /* save */
10396+ flush_dcache_page(vmf->page);
10397+ kunmap(vmf->page);
10398+ return VM_FAULT_MAJOR;
10399+}
10400+
10401+static const struct vm_operations_struct pax_vm_ops = {
10402+ .close = pax_emuplt_close,
10403+ .fault = pax_emuplt_fault
10404+};
10405+
10406+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
10407+{
10408+ int ret;
10409+
10410+ INIT_LIST_HEAD(&vma->anon_vma_chain);
10411+ vma->vm_mm = current->mm;
10412+ vma->vm_start = addr;
10413+ vma->vm_end = addr + PAGE_SIZE;
10414+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
10415+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
10416+ vma->vm_ops = &pax_vm_ops;
10417+
10418+ ret = insert_vm_struct(current->mm, vma);
10419+ if (ret)
10420+ return ret;
10421+
10422+ ++current->mm->total_vm;
10423+ return 0;
10424+}
10425+#endif
10426+
10427+/*
10428+ * PaX: decide what to do with offenders (regs->pc = fault address)
10429+ *
10430+ * returns 1 when task should be killed
10431+ * 2 when patched PLT trampoline was detected
10432+ * 3 when unpatched PLT trampoline was detected
10433+ */
10434+static int pax_handle_fetch_fault(struct pt_regs *regs)
10435+{
10436+
10437+#ifdef CONFIG_PAX_EMUPLT
10438+ int err;
10439+
10440+ do { /* PaX: patched PLT emulation #1 */
10441+ unsigned int sethi1, sethi2, jmpl;
10442+
10443+ err = get_user(sethi1, (unsigned int *)regs->pc);
10444+ err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
10445+ err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
10446+
10447+ if (err)
10448+ break;
10449+
10450+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
10451+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
10452+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
10453+ {
10454+ unsigned int addr;
10455+
10456+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
10457+ addr = regs->u_regs[UREG_G1];
10458+ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
10459+ regs->pc = addr;
10460+ regs->npc = addr+4;
10461+ return 2;
10462+ }
10463+ } while (0);
10464+
10465+ do { /* PaX: patched PLT emulation #2 */
10466+ unsigned int ba;
10467+
10468+ err = get_user(ba, (unsigned int *)regs->pc);
10469+
10470+ if (err)
10471+ break;
10472+
10473+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
10474+ unsigned int addr;
10475+
10476+ if ((ba & 0xFFC00000U) == 0x30800000U)
10477+ addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
10478+ else
10479+ addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
10480+ regs->pc = addr;
10481+ regs->npc = addr+4;
10482+ return 2;
10483+ }
10484+ } while (0);
10485+
10486+ do { /* PaX: patched PLT emulation #3 */
10487+ unsigned int sethi, bajmpl, nop;
10488+
10489+ err = get_user(sethi, (unsigned int *)regs->pc);
10490+ err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
10491+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
10492+
10493+ if (err)
10494+ break;
10495+
10496+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10497+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
10498+ nop == 0x01000000U)
10499+ {
10500+ unsigned int addr;
10501+
10502+ addr = (sethi & 0x003FFFFFU) << 10;
10503+ regs->u_regs[UREG_G1] = addr;
10504+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
10505+ addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
10506+ else
10507+ addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
10508+ regs->pc = addr;
10509+ regs->npc = addr+4;
10510+ return 2;
10511+ }
10512+ } while (0);
10513+
10514+ do { /* PaX: unpatched PLT emulation step 1 */
10515+ unsigned int sethi, ba, nop;
10516+
10517+ err = get_user(sethi, (unsigned int *)regs->pc);
10518+ err |= get_user(ba, (unsigned int *)(regs->pc+4));
10519+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
10520+
10521+ if (err)
10522+ break;
10523+
10524+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10525+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
10526+ nop == 0x01000000U)
10527+ {
10528+ unsigned int addr, save, call;
10529+
10530+ if ((ba & 0xFFC00000U) == 0x30800000U)
10531+ addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
10532+ else
10533+ addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
10534+
10535+ err = get_user(save, (unsigned int *)addr);
10536+ err |= get_user(call, (unsigned int *)(addr+4));
10537+ err |= get_user(nop, (unsigned int *)(addr+8));
10538+ if (err)
10539+ break;
10540+
10541+#ifdef CONFIG_PAX_DLRESOLVE
10542+ if (save == 0x9DE3BFA8U &&
10543+ (call & 0xC0000000U) == 0x40000000U &&
10544+ nop == 0x01000000U)
10545+ {
10546+ struct vm_area_struct *vma;
10547+ unsigned long call_dl_resolve;
10548+
10549+ down_read(&current->mm->mmap_sem);
10550+ call_dl_resolve = current->mm->call_dl_resolve;
10551+ up_read(&current->mm->mmap_sem);
10552+ if (likely(call_dl_resolve))
10553+ goto emulate;
10554+
10555+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
10556+
10557+ down_write(&current->mm->mmap_sem);
10558+ if (current->mm->call_dl_resolve) {
10559+ call_dl_resolve = current->mm->call_dl_resolve;
10560+ up_write(&current->mm->mmap_sem);
10561+ if (vma)
10562+ kmem_cache_free(vm_area_cachep, vma);
10563+ goto emulate;
10564+ }
10565+
10566+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
10567+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
10568+ up_write(&current->mm->mmap_sem);
10569+ if (vma)
10570+ kmem_cache_free(vm_area_cachep, vma);
10571+ return 1;
10572+ }
10573+
10574+ if (pax_insert_vma(vma, call_dl_resolve)) {
10575+ up_write(&current->mm->mmap_sem);
10576+ kmem_cache_free(vm_area_cachep, vma);
10577+ return 1;
10578+ }
10579+
10580+ current->mm->call_dl_resolve = call_dl_resolve;
10581+ up_write(&current->mm->mmap_sem);
10582+
10583+emulate:
10584+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
10585+ regs->pc = call_dl_resolve;
10586+ regs->npc = addr+4;
10587+ return 3;
10588+ }
10589+#endif
10590+
10591+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
10592+ if ((save & 0xFFC00000U) == 0x05000000U &&
10593+ (call & 0xFFFFE000U) == 0x85C0A000U &&
10594+ nop == 0x01000000U)
10595+ {
10596+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
10597+ regs->u_regs[UREG_G2] = addr + 4;
10598+ addr = (save & 0x003FFFFFU) << 10;
10599+ addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
10600+ regs->pc = addr;
10601+ regs->npc = addr+4;
10602+ return 3;
10603+ }
10604+ }
10605+ } while (0);
10606+
10607+ do { /* PaX: unpatched PLT emulation step 2 */
10608+ unsigned int save, call, nop;
10609+
10610+ err = get_user(save, (unsigned int *)(regs->pc-4));
10611+ err |= get_user(call, (unsigned int *)regs->pc);
10612+ err |= get_user(nop, (unsigned int *)(regs->pc+4));
10613+ if (err)
10614+ break;
10615+
10616+ if (save == 0x9DE3BFA8U &&
10617+ (call & 0xC0000000U) == 0x40000000U &&
10618+ nop == 0x01000000U)
10619+ {
10620+ unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
10621+
10622+ regs->u_regs[UREG_RETPC] = regs->pc;
10623+ regs->pc = dl_resolve;
10624+ regs->npc = dl_resolve+4;
10625+ return 3;
10626+ }
10627+ } while (0);
10628+#endif
10629+
10630+ return 1;
10631+}
10632+
10633+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
10634+{
10635+ unsigned long i;
10636+
10637+ printk(KERN_ERR "PAX: bytes at PC: ");
10638+ for (i = 0; i < 8; i++) {
10639+ unsigned int c;
10640+ if (get_user(c, (unsigned int *)pc+i))
10641+ printk(KERN_CONT "???????? ");
10642+ else
10643+ printk(KERN_CONT "%08x ", c);
10644+ }
10645+ printk("\n");
10646+}
10647+#endif
10648+
10649 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
10650 int text_fault)
10651 {
10652@@ -229,6 +503,24 @@ good_area:
10653 if (!(vma->vm_flags & VM_WRITE))
10654 goto bad_area;
10655 } else {
10656+
10657+#ifdef CONFIG_PAX_PAGEEXEC
10658+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
10659+ up_read(&mm->mmap_sem);
10660+ switch (pax_handle_fetch_fault(regs)) {
10661+
10662+#ifdef CONFIG_PAX_EMUPLT
10663+ case 2:
10664+ case 3:
10665+ return;
10666+#endif
10667+
10668+ }
10669+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
10670+ do_group_exit(SIGKILL);
10671+ }
10672+#endif
10673+
10674 /* Allow reads even for write-only mappings */
10675 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
10676 goto bad_area;
10677diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
10678index 2ebec26..b212598 100644
10679--- a/arch/sparc/mm/fault_64.c
10680+++ b/arch/sparc/mm/fault_64.c
10681@@ -21,6 +21,9 @@
10682 #include <linux/kprobes.h>
10683 #include <linux/kdebug.h>
10684 #include <linux/percpu.h>
10685+#include <linux/slab.h>
10686+#include <linux/pagemap.h>
10687+#include <linux/compiler.h>
10688
10689 #include <asm/page.h>
10690 #include <asm/pgtable.h>
10691@@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
10692 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
10693 regs->tpc);
10694 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
10695- printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
10696+ printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
10697 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
10698 dump_stack();
10699 unhandled_fault(regs->tpc, current, regs);
10700@@ -270,6 +273,466 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
10701 show_regs(regs);
10702 }
10703
10704+#ifdef CONFIG_PAX_PAGEEXEC
10705+#ifdef CONFIG_PAX_DLRESOLVE
10706+static void pax_emuplt_close(struct vm_area_struct *vma)
10707+{
10708+ vma->vm_mm->call_dl_resolve = 0UL;
10709+}
10710+
10711+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
10712+{
10713+ unsigned int *kaddr;
10714+
10715+ vmf->page = alloc_page(GFP_HIGHUSER);
10716+ if (!vmf->page)
10717+ return VM_FAULT_OOM;
10718+
10719+ kaddr = kmap(vmf->page);
10720+ memset(kaddr, 0, PAGE_SIZE);
10721+ kaddr[0] = 0x9DE3BFA8U; /* save */
10722+ flush_dcache_page(vmf->page);
10723+ kunmap(vmf->page);
10724+ return VM_FAULT_MAJOR;
10725+}
10726+
10727+static const struct vm_operations_struct pax_vm_ops = {
10728+ .close = pax_emuplt_close,
10729+ .fault = pax_emuplt_fault
10730+};
10731+
10732+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
10733+{
10734+ int ret;
10735+
10736+ INIT_LIST_HEAD(&vma->anon_vma_chain);
10737+ vma->vm_mm = current->mm;
10738+ vma->vm_start = addr;
10739+ vma->vm_end = addr + PAGE_SIZE;
10740+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
10741+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
10742+ vma->vm_ops = &pax_vm_ops;
10743+
10744+ ret = insert_vm_struct(current->mm, vma);
10745+ if (ret)
10746+ return ret;
10747+
10748+ ++current->mm->total_vm;
10749+ return 0;
10750+}
10751+#endif
10752+
10753+/*
10754+ * PaX: decide what to do with offenders (regs->tpc = fault address)
10755+ *
10756+ * returns 1 when task should be killed
10757+ * 2 when patched PLT trampoline was detected
10758+ * 3 when unpatched PLT trampoline was detected
10759+ */
10760+static int pax_handle_fetch_fault(struct pt_regs *regs)
10761+{
10762+
10763+#ifdef CONFIG_PAX_EMUPLT
10764+ int err;
10765+
10766+ do { /* PaX: patched PLT emulation #1 */
10767+ unsigned int sethi1, sethi2, jmpl;
10768+
10769+ err = get_user(sethi1, (unsigned int *)regs->tpc);
10770+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
10771+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
10772+
10773+ if (err)
10774+ break;
10775+
10776+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
10777+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
10778+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
10779+ {
10780+ unsigned long addr;
10781+
10782+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
10783+ addr = regs->u_regs[UREG_G1];
10784+ addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
10785+
10786+ if (test_thread_flag(TIF_32BIT))
10787+ addr &= 0xFFFFFFFFUL;
10788+
10789+ regs->tpc = addr;
10790+ regs->tnpc = addr+4;
10791+ return 2;
10792+ }
10793+ } while (0);
10794+
10795+ do { /* PaX: patched PLT emulation #2 */
10796+ unsigned int ba;
10797+
10798+ err = get_user(ba, (unsigned int *)regs->tpc);
10799+
10800+ if (err)
10801+ break;
10802+
10803+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
10804+ unsigned long addr;
10805+
10806+ if ((ba & 0xFFC00000U) == 0x30800000U)
10807+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
10808+ else
10809+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
10810+
10811+ if (test_thread_flag(TIF_32BIT))
10812+ addr &= 0xFFFFFFFFUL;
10813+
10814+ regs->tpc = addr;
10815+ regs->tnpc = addr+4;
10816+ return 2;
10817+ }
10818+ } while (0);
10819+
10820+ do { /* PaX: patched PLT emulation #3 */
10821+ unsigned int sethi, bajmpl, nop;
10822+
10823+ err = get_user(sethi, (unsigned int *)regs->tpc);
10824+ err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
10825+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
10826+
10827+ if (err)
10828+ break;
10829+
10830+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10831+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
10832+ nop == 0x01000000U)
10833+ {
10834+ unsigned long addr;
10835+
10836+ addr = (sethi & 0x003FFFFFU) << 10;
10837+ regs->u_regs[UREG_G1] = addr;
10838+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
10839+ addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
10840+ else
10841+ addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
10842+
10843+ if (test_thread_flag(TIF_32BIT))
10844+ addr &= 0xFFFFFFFFUL;
10845+
10846+ regs->tpc = addr;
10847+ regs->tnpc = addr+4;
10848+ return 2;
10849+ }
10850+ } while (0);
10851+
10852+ do { /* PaX: patched PLT emulation #4 */
10853+ unsigned int sethi, mov1, call, mov2;
10854+
10855+ err = get_user(sethi, (unsigned int *)regs->tpc);
10856+ err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
10857+ err |= get_user(call, (unsigned int *)(regs->tpc+8));
10858+ err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
10859+
10860+ if (err)
10861+ break;
10862+
10863+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10864+ mov1 == 0x8210000FU &&
10865+ (call & 0xC0000000U) == 0x40000000U &&
10866+ mov2 == 0x9E100001U)
10867+ {
10868+ unsigned long addr;
10869+
10870+ regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
10871+ addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
10872+
10873+ if (test_thread_flag(TIF_32BIT))
10874+ addr &= 0xFFFFFFFFUL;
10875+
10876+ regs->tpc = addr;
10877+ regs->tnpc = addr+4;
10878+ return 2;
10879+ }
10880+ } while (0);
10881+
10882+ do { /* PaX: patched PLT emulation #5 */
10883+ unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
10884+
10885+ err = get_user(sethi, (unsigned int *)regs->tpc);
10886+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
10887+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
10888+ err |= get_user(or1, (unsigned int *)(regs->tpc+12));
10889+ err |= get_user(or2, (unsigned int *)(regs->tpc+16));
10890+ err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
10891+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
10892+ err |= get_user(nop, (unsigned int *)(regs->tpc+28));
10893+
10894+ if (err)
10895+ break;
10896+
10897+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10898+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
10899+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
10900+ (or1 & 0xFFFFE000U) == 0x82106000U &&
10901+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
10902+ sllx == 0x83287020U &&
10903+ jmpl == 0x81C04005U &&
10904+ nop == 0x01000000U)
10905+ {
10906+ unsigned long addr;
10907+
10908+ regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
10909+ regs->u_regs[UREG_G1] <<= 32;
10910+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
10911+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
10912+ regs->tpc = addr;
10913+ regs->tnpc = addr+4;
10914+ return 2;
10915+ }
10916+ } while (0);
10917+
10918+ do { /* PaX: patched PLT emulation #6 */
10919+ unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
10920+
10921+ err = get_user(sethi, (unsigned int *)regs->tpc);
10922+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
10923+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
10924+ err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
10925+ err |= get_user(or, (unsigned int *)(regs->tpc+16));
10926+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
10927+ err |= get_user(nop, (unsigned int *)(regs->tpc+24));
10928+
10929+ if (err)
10930+ break;
10931+
10932+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10933+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
10934+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
10935+ sllx == 0x83287020U &&
10936+ (or & 0xFFFFE000U) == 0x8A116000U &&
10937+ jmpl == 0x81C04005U &&
10938+ nop == 0x01000000U)
10939+ {
10940+ unsigned long addr;
10941+
10942+ regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
10943+ regs->u_regs[UREG_G1] <<= 32;
10944+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
10945+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
10946+ regs->tpc = addr;
10947+ regs->tnpc = addr+4;
10948+ return 2;
10949+ }
10950+ } while (0);
10951+
10952+ do { /* PaX: unpatched PLT emulation step 1 */
10953+ unsigned int sethi, ba, nop;
10954+
10955+ err = get_user(sethi, (unsigned int *)regs->tpc);
10956+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
10957+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
10958+
10959+ if (err)
10960+ break;
10961+
10962+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10963+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
10964+ nop == 0x01000000U)
10965+ {
10966+ unsigned long addr;
10967+ unsigned int save, call;
10968+ unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
10969+
10970+ if ((ba & 0xFFC00000U) == 0x30800000U)
10971+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
10972+ else
10973+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
10974+
10975+ if (test_thread_flag(TIF_32BIT))
10976+ addr &= 0xFFFFFFFFUL;
10977+
10978+ err = get_user(save, (unsigned int *)addr);
10979+ err |= get_user(call, (unsigned int *)(addr+4));
10980+ err |= get_user(nop, (unsigned int *)(addr+8));
10981+ if (err)
10982+ break;
10983+
10984+#ifdef CONFIG_PAX_DLRESOLVE
10985+ if (save == 0x9DE3BFA8U &&
10986+ (call & 0xC0000000U) == 0x40000000U &&
10987+ nop == 0x01000000U)
10988+ {
10989+ struct vm_area_struct *vma;
10990+ unsigned long call_dl_resolve;
10991+
10992+ down_read(&current->mm->mmap_sem);
10993+ call_dl_resolve = current->mm->call_dl_resolve;
10994+ up_read(&current->mm->mmap_sem);
10995+ if (likely(call_dl_resolve))
10996+ goto emulate;
10997+
10998+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
10999+
11000+ down_write(&current->mm->mmap_sem);
11001+ if (current->mm->call_dl_resolve) {
11002+ call_dl_resolve = current->mm->call_dl_resolve;
11003+ up_write(&current->mm->mmap_sem);
11004+ if (vma)
11005+ kmem_cache_free(vm_area_cachep, vma);
11006+ goto emulate;
11007+ }
11008+
11009+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
11010+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
11011+ up_write(&current->mm->mmap_sem);
11012+ if (vma)
11013+ kmem_cache_free(vm_area_cachep, vma);
11014+ return 1;
11015+ }
11016+
11017+ if (pax_insert_vma(vma, call_dl_resolve)) {
11018+ up_write(&current->mm->mmap_sem);
11019+ kmem_cache_free(vm_area_cachep, vma);
11020+ return 1;
11021+ }
11022+
11023+ current->mm->call_dl_resolve = call_dl_resolve;
11024+ up_write(&current->mm->mmap_sem);
11025+
11026+emulate:
11027+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11028+ regs->tpc = call_dl_resolve;
11029+ regs->tnpc = addr+4;
11030+ return 3;
11031+ }
11032+#endif
11033+
11034+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
11035+ if ((save & 0xFFC00000U) == 0x05000000U &&
11036+ (call & 0xFFFFE000U) == 0x85C0A000U &&
11037+ nop == 0x01000000U)
11038+ {
11039+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11040+ regs->u_regs[UREG_G2] = addr + 4;
11041+ addr = (save & 0x003FFFFFU) << 10;
11042+ addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11043+
11044+ if (test_thread_flag(TIF_32BIT))
11045+ addr &= 0xFFFFFFFFUL;
11046+
11047+ regs->tpc = addr;
11048+ regs->tnpc = addr+4;
11049+ return 3;
11050+ }
11051+
11052+ /* PaX: 64-bit PLT stub */
11053+ err = get_user(sethi1, (unsigned int *)addr);
11054+ err |= get_user(sethi2, (unsigned int *)(addr+4));
11055+ err |= get_user(or1, (unsigned int *)(addr+8));
11056+ err |= get_user(or2, (unsigned int *)(addr+12));
11057+ err |= get_user(sllx, (unsigned int *)(addr+16));
11058+ err |= get_user(add, (unsigned int *)(addr+20));
11059+ err |= get_user(jmpl, (unsigned int *)(addr+24));
11060+ err |= get_user(nop, (unsigned int *)(addr+28));
11061+ if (err)
11062+ break;
11063+
11064+ if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
11065+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11066+ (or1 & 0xFFFFE000U) == 0x88112000U &&
11067+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
11068+ sllx == 0x89293020U &&
11069+ add == 0x8A010005U &&
11070+ jmpl == 0x89C14000U &&
11071+ nop == 0x01000000U)
11072+ {
11073+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11074+ regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
11075+ regs->u_regs[UREG_G4] <<= 32;
11076+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
11077+ regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
11078+ regs->u_regs[UREG_G4] = addr + 24;
11079+ addr = regs->u_regs[UREG_G5];
11080+ regs->tpc = addr;
11081+ regs->tnpc = addr+4;
11082+ return 3;
11083+ }
11084+ }
11085+ } while (0);
11086+
11087+#ifdef CONFIG_PAX_DLRESOLVE
11088+ do { /* PaX: unpatched PLT emulation step 2 */
11089+ unsigned int save, call, nop;
11090+
11091+ err = get_user(save, (unsigned int *)(regs->tpc-4));
11092+ err |= get_user(call, (unsigned int *)regs->tpc);
11093+ err |= get_user(nop, (unsigned int *)(regs->tpc+4));
11094+ if (err)
11095+ break;
11096+
11097+ if (save == 0x9DE3BFA8U &&
11098+ (call & 0xC0000000U) == 0x40000000U &&
11099+ nop == 0x01000000U)
11100+ {
11101+ unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
11102+
11103+ if (test_thread_flag(TIF_32BIT))
11104+ dl_resolve &= 0xFFFFFFFFUL;
11105+
11106+ regs->u_regs[UREG_RETPC] = regs->tpc;
11107+ regs->tpc = dl_resolve;
11108+ regs->tnpc = dl_resolve+4;
11109+ return 3;
11110+ }
11111+ } while (0);
11112+#endif
11113+
11114+ do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
11115+ unsigned int sethi, ba, nop;
11116+
11117+ err = get_user(sethi, (unsigned int *)regs->tpc);
11118+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
11119+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11120+
11121+ if (err)
11122+ break;
11123+
11124+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11125+ (ba & 0xFFF00000U) == 0x30600000U &&
11126+ nop == 0x01000000U)
11127+ {
11128+ unsigned long addr;
11129+
11130+ addr = (sethi & 0x003FFFFFU) << 10;
11131+ regs->u_regs[UREG_G1] = addr;
11132+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11133+
11134+ if (test_thread_flag(TIF_32BIT))
11135+ addr &= 0xFFFFFFFFUL;
11136+
11137+ regs->tpc = addr;
11138+ regs->tnpc = addr+4;
11139+ return 2;
11140+ }
11141+ } while (0);
11142+
11143+#endif
11144+
11145+ return 1;
11146+}
11147+
11148+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
11149+{
11150+ unsigned long i;
11151+
11152+ printk(KERN_ERR "PAX: bytes at PC: ");
11153+ for (i = 0; i < 8; i++) {
11154+ unsigned int c;
11155+ if (get_user(c, (unsigned int *)pc+i))
11156+ printk(KERN_CONT "???????? ");
11157+ else
11158+ printk(KERN_CONT "%08x ", c);
11159+ }
11160+ printk("\n");
11161+}
11162+#endif
11163+
11164 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
11165 {
11166 struct mm_struct *mm = current->mm;
11167@@ -342,6 +805,29 @@ retry:
11168 if (!vma)
11169 goto bad_area;
11170
11171+#ifdef CONFIG_PAX_PAGEEXEC
11172+ /* PaX: detect ITLB misses on non-exec pages */
11173+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
11174+ !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
11175+ {
11176+ if (address != regs->tpc)
11177+ goto good_area;
11178+
11179+ up_read(&mm->mmap_sem);
11180+ switch (pax_handle_fetch_fault(regs)) {
11181+
11182+#ifdef CONFIG_PAX_EMUPLT
11183+ case 2:
11184+ case 3:
11185+ return;
11186+#endif
11187+
11188+ }
11189+ pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
11190+ do_group_exit(SIGKILL);
11191+ }
11192+#endif
11193+
11194 /* Pure DTLB misses do not tell us whether the fault causing
11195 * load/store/atomic was a write or not, it only says that there
11196 * was no match. So in such a case we (carefully) read the
11197diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
11198index 9639964..806cd0c 100644
11199--- a/arch/sparc/mm/hugetlbpage.c
11200+++ b/arch/sparc/mm/hugetlbpage.c
11201@@ -28,7 +28,8 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
11202 unsigned long addr,
11203 unsigned long len,
11204 unsigned long pgoff,
11205- unsigned long flags)
11206+ unsigned long flags,
11207+ unsigned long offset)
11208 {
11209 unsigned long task_size = TASK_SIZE;
11210 struct vm_unmapped_area_info info;
11211@@ -38,15 +39,22 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
11212
11213 info.flags = 0;
11214 info.length = len;
11215- info.low_limit = TASK_UNMAPPED_BASE;
11216+ info.low_limit = mm->mmap_base;
11217 info.high_limit = min(task_size, VA_EXCLUDE_START);
11218 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
11219 info.align_offset = 0;
11220+ info.threadstack_offset = offset;
11221 addr = vm_unmapped_area(&info);
11222
11223 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
11224 VM_BUG_ON(addr != -ENOMEM);
11225 info.low_limit = VA_EXCLUDE_END;
11226+
11227+#ifdef CONFIG_PAX_RANDMMAP
11228+ if (mm->pax_flags & MF_PAX_RANDMMAP)
11229+ info.low_limit += mm->delta_mmap;
11230+#endif
11231+
11232 info.high_limit = task_size;
11233 addr = vm_unmapped_area(&info);
11234 }
11235@@ -58,7 +66,8 @@ static unsigned long
11236 hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11237 const unsigned long len,
11238 const unsigned long pgoff,
11239- const unsigned long flags)
11240+ const unsigned long flags,
11241+ const unsigned long offset)
11242 {
11243 struct mm_struct *mm = current->mm;
11244 unsigned long addr = addr0;
11245@@ -73,6 +82,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11246 info.high_limit = mm->mmap_base;
11247 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
11248 info.align_offset = 0;
11249+ info.threadstack_offset = offset;
11250 addr = vm_unmapped_area(&info);
11251
11252 /*
11253@@ -85,6 +95,12 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11254 VM_BUG_ON(addr != -ENOMEM);
11255 info.flags = 0;
11256 info.low_limit = TASK_UNMAPPED_BASE;
11257+
11258+#ifdef CONFIG_PAX_RANDMMAP
11259+ if (mm->pax_flags & MF_PAX_RANDMMAP)
11260+ info.low_limit += mm->delta_mmap;
11261+#endif
11262+
11263 info.high_limit = STACK_TOP32;
11264 addr = vm_unmapped_area(&info);
11265 }
11266@@ -99,6 +115,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
11267 struct mm_struct *mm = current->mm;
11268 struct vm_area_struct *vma;
11269 unsigned long task_size = TASK_SIZE;
11270+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
11271
11272 if (test_thread_flag(TIF_32BIT))
11273 task_size = STACK_TOP32;
11274@@ -114,19 +131,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
11275 return addr;
11276 }
11277
11278+#ifdef CONFIG_PAX_RANDMMAP
11279+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
11280+#endif
11281+
11282 if (addr) {
11283 addr = ALIGN(addr, HPAGE_SIZE);
11284 vma = find_vma(mm, addr);
11285- if (task_size - len >= addr &&
11286- (!vma || addr + len <= vma->vm_start))
11287+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
11288 return addr;
11289 }
11290 if (mm->get_unmapped_area == arch_get_unmapped_area)
11291 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
11292- pgoff, flags);
11293+ pgoff, flags, offset);
11294 else
11295 return hugetlb_get_unmapped_area_topdown(file, addr, len,
11296- pgoff, flags);
11297+ pgoff, flags, offset);
11298 }
11299
11300 pte_t *huge_pte_alloc(struct mm_struct *mm,
11301diff --git a/arch/sparc/mm/init_64.c b/arch/sparc/mm/init_64.c
11302index ed82eda..0d80e77 100644
11303--- a/arch/sparc/mm/init_64.c
11304+++ b/arch/sparc/mm/init_64.c
11305@@ -188,9 +188,9 @@ unsigned long sparc64_kern_sec_context __read_mostly;
11306 int num_kernel_image_mappings;
11307
11308 #ifdef CONFIG_DEBUG_DCFLUSH
11309-atomic_t dcpage_flushes = ATOMIC_INIT(0);
11310+atomic_unchecked_t dcpage_flushes = ATOMIC_INIT(0);
11311 #ifdef CONFIG_SMP
11312-atomic_t dcpage_flushes_xcall = ATOMIC_INIT(0);
11313+atomic_unchecked_t dcpage_flushes_xcall = ATOMIC_INIT(0);
11314 #endif
11315 #endif
11316
11317@@ -198,7 +198,7 @@ inline void flush_dcache_page_impl(struct page *page)
11318 {
11319 BUG_ON(tlb_type == hypervisor);
11320 #ifdef CONFIG_DEBUG_DCFLUSH
11321- atomic_inc(&dcpage_flushes);
11322+ atomic_inc_unchecked(&dcpage_flushes);
11323 #endif
11324
11325 #ifdef DCACHE_ALIASING_POSSIBLE
11326@@ -466,10 +466,10 @@ void mmu_info(struct seq_file *m)
11327
11328 #ifdef CONFIG_DEBUG_DCFLUSH
11329 seq_printf(m, "DCPageFlushes\t: %d\n",
11330- atomic_read(&dcpage_flushes));
11331+ atomic_read_unchecked(&dcpage_flushes));
11332 #ifdef CONFIG_SMP
11333 seq_printf(m, "DCPageFlushesXC\t: %d\n",
11334- atomic_read(&dcpage_flushes_xcall));
11335+ atomic_read_unchecked(&dcpage_flushes_xcall));
11336 #endif /* CONFIG_SMP */
11337 #endif /* CONFIG_DEBUG_DCFLUSH */
11338 }
11339diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
11340index ad220ee..2f537b3 100644
11341--- a/arch/tile/include/asm/atomic_64.h
11342+++ b/arch/tile/include/asm/atomic_64.h
11343@@ -105,6 +105,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
11344
11345 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
11346
11347+#define atomic64_read_unchecked(v) atomic64_read(v)
11348+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
11349+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
11350+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
11351+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
11352+#define atomic64_inc_unchecked(v) atomic64_inc(v)
11353+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
11354+#define atomic64_dec_unchecked(v) atomic64_dec(v)
11355+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
11356+
11357 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
11358 #define smp_mb__before_atomic_dec() smp_mb()
11359 #define smp_mb__after_atomic_dec() smp_mb()
11360diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
11361index 6160761..00cac88 100644
11362--- a/arch/tile/include/asm/cache.h
11363+++ b/arch/tile/include/asm/cache.h
11364@@ -15,11 +15,12 @@
11365 #ifndef _ASM_TILE_CACHE_H
11366 #define _ASM_TILE_CACHE_H
11367
11368+#include <linux/const.h>
11369 #include <arch/chip.h>
11370
11371 /* bytes per L1 data cache line */
11372 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
11373-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
11374+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
11375
11376 /* bytes per L2 cache line */
11377 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
11378diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
11379index b6cde32..c0cb736 100644
11380--- a/arch/tile/include/asm/uaccess.h
11381+++ b/arch/tile/include/asm/uaccess.h
11382@@ -414,9 +414,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
11383 const void __user *from,
11384 unsigned long n)
11385 {
11386- int sz = __compiletime_object_size(to);
11387+ size_t sz = __compiletime_object_size(to);
11388
11389- if (likely(sz == -1 || sz >= n))
11390+ if (likely(sz == (size_t)-1 || sz >= n))
11391 n = _copy_from_user(to, from, n);
11392 else
11393 copy_from_user_overflow();
11394diff --git a/arch/tile/mm/hugetlbpage.c b/arch/tile/mm/hugetlbpage.c
11395index 0cb3bba..7338b2d 100644
11396--- a/arch/tile/mm/hugetlbpage.c
11397+++ b/arch/tile/mm/hugetlbpage.c
11398@@ -212,6 +212,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
11399 info.high_limit = TASK_SIZE;
11400 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
11401 info.align_offset = 0;
11402+ info.threadstack_offset = 0;
11403 return vm_unmapped_area(&info);
11404 }
11405
11406@@ -229,6 +230,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
11407 info.high_limit = current->mm->mmap_base;
11408 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
11409 info.align_offset = 0;
11410+ info.threadstack_offset = 0;
11411 addr = vm_unmapped_area(&info);
11412
11413 /*
11414diff --git a/arch/um/Makefile b/arch/um/Makefile
11415index 133f7de..1d6f2f1 100644
11416--- a/arch/um/Makefile
11417+++ b/arch/um/Makefile
11418@@ -62,6 +62,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
11419 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
11420 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
11421
11422+ifdef CONSTIFY_PLUGIN
11423+USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
11424+endif
11425+
11426 #This will adjust *FLAGS accordingly to the platform.
11427 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
11428
11429diff --git a/arch/um/defconfig b/arch/um/defconfig
11430index 2665e6b..3e3822b 100644
11431--- a/arch/um/defconfig
11432+++ b/arch/um/defconfig
11433@@ -51,7 +51,6 @@ CONFIG_X86_CMPXCHG=y
11434 CONFIG_X86_L1_CACHE_SHIFT=5
11435 CONFIG_X86_XADD=y
11436 CONFIG_X86_PPRO_FENCE=y
11437-CONFIG_X86_WP_WORKS_OK=y
11438 CONFIG_X86_INVLPG=y
11439 CONFIG_X86_BSWAP=y
11440 CONFIG_X86_POPAD_OK=y
11441diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
11442index 19e1bdd..3665b77 100644
11443--- a/arch/um/include/asm/cache.h
11444+++ b/arch/um/include/asm/cache.h
11445@@ -1,6 +1,7 @@
11446 #ifndef __UM_CACHE_H
11447 #define __UM_CACHE_H
11448
11449+#include <linux/const.h>
11450
11451 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
11452 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
11453@@ -12,6 +13,6 @@
11454 # define L1_CACHE_SHIFT 5
11455 #endif
11456
11457-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
11458+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
11459
11460 #endif
11461diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
11462index 2e0a6b1..a64d0f5 100644
11463--- a/arch/um/include/asm/kmap_types.h
11464+++ b/arch/um/include/asm/kmap_types.h
11465@@ -8,6 +8,6 @@
11466
11467 /* No more #include "asm/arch/kmap_types.h" ! */
11468
11469-#define KM_TYPE_NR 14
11470+#define KM_TYPE_NR 15
11471
11472 #endif
11473diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
11474index 5ff53d9..5850cdf 100644
11475--- a/arch/um/include/asm/page.h
11476+++ b/arch/um/include/asm/page.h
11477@@ -14,6 +14,9 @@
11478 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
11479 #define PAGE_MASK (~(PAGE_SIZE-1))
11480
11481+#define ktla_ktva(addr) (addr)
11482+#define ktva_ktla(addr) (addr)
11483+
11484 #ifndef __ASSEMBLY__
11485
11486 struct page;
11487diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
11488index 0032f92..cd151e0 100644
11489--- a/arch/um/include/asm/pgtable-3level.h
11490+++ b/arch/um/include/asm/pgtable-3level.h
11491@@ -58,6 +58,7 @@
11492 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
11493 #define pud_populate(mm, pud, pmd) \
11494 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
11495+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
11496
11497 #ifdef CONFIG_64BIT
11498 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
11499diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
11500index bbcef52..6a2a483 100644
11501--- a/arch/um/kernel/process.c
11502+++ b/arch/um/kernel/process.c
11503@@ -367,22 +367,6 @@ int singlestepping(void * t)
11504 return 2;
11505 }
11506
11507-/*
11508- * Only x86 and x86_64 have an arch_align_stack().
11509- * All other arches have "#define arch_align_stack(x) (x)"
11510- * in their asm/system.h
11511- * As this is included in UML from asm-um/system-generic.h,
11512- * we can use it to behave as the subarch does.
11513- */
11514-#ifndef arch_align_stack
11515-unsigned long arch_align_stack(unsigned long sp)
11516-{
11517- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
11518- sp -= get_random_int() % 8192;
11519- return sp & ~0xf;
11520-}
11521-#endif
11522-
11523 unsigned long get_wchan(struct task_struct *p)
11524 {
11525 unsigned long stack_page, sp, ip;
11526diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
11527index ad8f795..2c7eec6 100644
11528--- a/arch/unicore32/include/asm/cache.h
11529+++ b/arch/unicore32/include/asm/cache.h
11530@@ -12,8 +12,10 @@
11531 #ifndef __UNICORE_CACHE_H__
11532 #define __UNICORE_CACHE_H__
11533
11534-#define L1_CACHE_SHIFT (5)
11535-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
11536+#include <linux/const.h>
11537+
11538+#define L1_CACHE_SHIFT 5
11539+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
11540
11541 /*
11542 * Memory returned by kmalloc() may be used for DMA, so we must make
11543diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
11544index f67e839..419b5f7 100644
11545--- a/arch/x86/Kconfig
11546+++ b/arch/x86/Kconfig
11547@@ -247,7 +247,7 @@ config X86_HT
11548
11549 config X86_32_LAZY_GS
11550 def_bool y
11551- depends on X86_32 && !CC_STACKPROTECTOR
11552+ depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
11553
11554 config ARCH_HWEIGHT_CFLAGS
11555 string
11556@@ -1099,6 +1099,7 @@ config MICROCODE_EARLY
11557
11558 config X86_MSR
11559 tristate "/dev/cpu/*/msr - Model-specific register support"
11560+ depends on !GRKERNSEC_KMEM
11561 ---help---
11562 This device gives privileged processes access to the x86
11563 Model-Specific Registers (MSRs). It is a character device with
11564@@ -1122,7 +1123,7 @@ choice
11565
11566 config NOHIGHMEM
11567 bool "off"
11568- depends on !X86_NUMAQ
11569+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
11570 ---help---
11571 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
11572 However, the address space of 32-bit x86 processors is only 4
11573@@ -1159,7 +1160,7 @@ config NOHIGHMEM
11574
11575 config HIGHMEM4G
11576 bool "4GB"
11577- depends on !X86_NUMAQ
11578+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
11579 ---help---
11580 Select this if you have a 32-bit processor and between 1 and 4
11581 gigabytes of physical RAM.
11582@@ -1212,7 +1213,7 @@ config PAGE_OFFSET
11583 hex
11584 default 0xB0000000 if VMSPLIT_3G_OPT
11585 default 0x80000000 if VMSPLIT_2G
11586- default 0x78000000 if VMSPLIT_2G_OPT
11587+ default 0x70000000 if VMSPLIT_2G_OPT
11588 default 0x40000000 if VMSPLIT_1G
11589 default 0xC0000000
11590 depends on X86_32
11591@@ -1614,6 +1615,7 @@ config SECCOMP
11592
11593 config CC_STACKPROTECTOR
11594 bool "Enable -fstack-protector buffer overflow detection"
11595+ depends on X86_64 || !PAX_MEMORY_UDEREF
11596 ---help---
11597 This option turns on the -fstack-protector GCC feature. This
11598 feature puts, at the beginning of functions, a canary value on
11599@@ -1733,6 +1735,8 @@ config X86_NEED_RELOCS
11600 config PHYSICAL_ALIGN
11601 hex "Alignment value to which kernel should be aligned"
11602 default "0x1000000"
11603+ range 0x200000 0x1000000 if PAX_KERNEXEC && X86_PAE
11604+ range 0x400000 0x1000000 if PAX_KERNEXEC && !X86_PAE
11605 range 0x2000 0x1000000 if X86_32
11606 range 0x200000 0x1000000 if X86_64
11607 ---help---
11608@@ -1812,9 +1816,10 @@ config DEBUG_HOTPLUG_CPU0
11609 If unsure, say N.
11610
11611 config COMPAT_VDSO
11612- def_bool y
11613+ def_bool n
11614 prompt "Compat VDSO support"
11615 depends on X86_32 || IA32_EMULATION
11616+ depends on !PAX_PAGEEXEC && !PAX_SEGMEXEC && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
11617 ---help---
11618 Map the 32-bit VDSO to the predictable old-style address too.
11619
11620diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
11621index c026cca..14657ae 100644
11622--- a/arch/x86/Kconfig.cpu
11623+++ b/arch/x86/Kconfig.cpu
11624@@ -319,7 +319,7 @@ config X86_PPRO_FENCE
11625
11626 config X86_F00F_BUG
11627 def_bool y
11628- depends on M586MMX || M586TSC || M586 || M486
11629+ depends on (M586MMX || M586TSC || M586 || M486) && !PAX_KERNEXEC
11630
11631 config X86_INVD_BUG
11632 def_bool y
11633@@ -327,7 +327,7 @@ config X86_INVD_BUG
11634
11635 config X86_ALIGNMENT_16
11636 def_bool y
11637- depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
11638+ depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
11639
11640 config X86_INTEL_USERCOPY
11641 def_bool y
11642@@ -373,7 +373,7 @@ config X86_CMPXCHG64
11643 # generates cmov.
11644 config X86_CMOV
11645 def_bool y
11646- depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
11647+ depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
11648
11649 config X86_MINIMUM_CPU_FAMILY
11650 int
11651diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
11652index 78d91af..8ceb94b 100644
11653--- a/arch/x86/Kconfig.debug
11654+++ b/arch/x86/Kconfig.debug
11655@@ -74,7 +74,7 @@ config X86_PTDUMP
11656 config DEBUG_RODATA
11657 bool "Write protect kernel read-only data structures"
11658 default y
11659- depends on DEBUG_KERNEL
11660+ depends on DEBUG_KERNEL && BROKEN
11661 ---help---
11662 Mark the kernel read-only data as write-protected in the pagetables,
11663 in order to catch accidental (and incorrect) writes to such const
11664@@ -92,7 +92,7 @@ config DEBUG_RODATA_TEST
11665
11666 config DEBUG_SET_MODULE_RONX
11667 bool "Set loadable kernel module data as NX and text as RO"
11668- depends on MODULES
11669+ depends on MODULES && BROKEN
11670 ---help---
11671 This option helps catch unintended modifications to loadable
11672 kernel module's text and read-only data. It also prevents execution
11673diff --git a/arch/x86/Makefile b/arch/x86/Makefile
11674index 41250fb..863762e 100644
11675--- a/arch/x86/Makefile
11676+++ b/arch/x86/Makefile
11677@@ -46,14 +46,12 @@ ifeq ($(CONFIG_X86_32),y)
11678 # CPU-specific tuning. Anything which can be shared with UML should go here.
11679 include $(srctree)/arch/x86/Makefile_32.cpu
11680 KBUILD_CFLAGS += $(cflags-y)
11681-
11682- # temporary until string.h is fixed
11683- KBUILD_CFLAGS += -ffreestanding
11684 else
11685 BITS := 64
11686 UTS_MACHINE := x86_64
11687 CHECKFLAGS += -D__x86_64__ -m64
11688
11689+ biarch := $(call cc-option,-m64)
11690 KBUILD_AFLAGS += -m64
11691 KBUILD_CFLAGS += -m64
11692
11693@@ -83,6 +81,9 @@ else
11694 KBUILD_CFLAGS += -maccumulate-outgoing-args
11695 endif
11696
11697+# temporary until string.h is fixed
11698+KBUILD_CFLAGS += -ffreestanding
11699+
11700 ifdef CONFIG_CC_STACKPROTECTOR
11701 cc_has_sp := $(srctree)/scripts/gcc-x86_$(BITS)-has-stack-protector.sh
11702 ifeq ($(shell $(CONFIG_SHELL) $(cc_has_sp) $(CC) $(KBUILD_CPPFLAGS) $(biarch)),y)
11703@@ -241,3 +242,12 @@ define archhelp
11704 echo ' FDINITRD=file initrd for the booted kernel'
11705 echo ' kvmconfig - Enable additional options for guest kernel support'
11706 endef
11707+
11708+define OLD_LD
11709+
11710+*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
11711+*** Please upgrade your binutils to 2.18 or newer
11712+endef
11713+
11714+archprepare:
11715+ $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
11716diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
11717index 379814b..add62ce 100644
11718--- a/arch/x86/boot/Makefile
11719+++ b/arch/x86/boot/Makefile
11720@@ -65,6 +65,9 @@ KBUILD_CFLAGS := $(USERINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
11721 $(call cc-option, -fno-stack-protector) \
11722 $(call cc-option, -mpreferred-stack-boundary=2)
11723 KBUILD_CFLAGS += $(call cc-option, -m32)
11724+ifdef CONSTIFY_PLUGIN
11725+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
11726+endif
11727 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
11728 GCOV_PROFILE := n
11729
11730diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
11731index 878e4b9..20537ab 100644
11732--- a/arch/x86/boot/bitops.h
11733+++ b/arch/x86/boot/bitops.h
11734@@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
11735 u8 v;
11736 const u32 *p = (const u32 *)addr;
11737
11738- asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
11739+ asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
11740 return v;
11741 }
11742
11743@@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
11744
11745 static inline void set_bit(int nr, void *addr)
11746 {
11747- asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
11748+ asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
11749 }
11750
11751 #endif /* BOOT_BITOPS_H */
11752diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
11753index ef72bae..353a184 100644
11754--- a/arch/x86/boot/boot.h
11755+++ b/arch/x86/boot/boot.h
11756@@ -85,7 +85,7 @@ static inline void io_delay(void)
11757 static inline u16 ds(void)
11758 {
11759 u16 seg;
11760- asm("movw %%ds,%0" : "=rm" (seg));
11761+ asm volatile("movw %%ds,%0" : "=rm" (seg));
11762 return seg;
11763 }
11764
11765@@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
11766 static inline int memcmp(const void *s1, const void *s2, size_t len)
11767 {
11768 u8 diff;
11769- asm("repe; cmpsb; setnz %0"
11770+ asm volatile("repe; cmpsb; setnz %0"
11771 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
11772 return diff;
11773 }
11774diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
11775index dcd90df..c830d7d 100644
11776--- a/arch/x86/boot/compressed/Makefile
11777+++ b/arch/x86/boot/compressed/Makefile
11778@@ -15,6 +15,9 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small
11779 KBUILD_CFLAGS += $(cflags-y)
11780 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
11781 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
11782+ifdef CONSTIFY_PLUGIN
11783+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
11784+endif
11785
11786 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
11787 GCOV_PROFILE := n
11788diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
11789index b7388a4..03844ec 100644
11790--- a/arch/x86/boot/compressed/eboot.c
11791+++ b/arch/x86/boot/compressed/eboot.c
11792@@ -150,7 +150,6 @@ again:
11793 *addr = max_addr;
11794 }
11795
11796-free_pool:
11797 efi_call_phys1(sys_table->boottime->free_pool, map);
11798
11799 fail:
11800@@ -214,7 +213,6 @@ static efi_status_t low_alloc(unsigned long size, unsigned long align,
11801 if (i == map_size / desc_size)
11802 status = EFI_NOT_FOUND;
11803
11804-free_pool:
11805 efi_call_phys1(sys_table->boottime->free_pool, map);
11806 fail:
11807 return status;
11808diff --git a/arch/x86/boot/compressed/efi_stub_32.S b/arch/x86/boot/compressed/efi_stub_32.S
11809index a53440e..c3dbf1e 100644
11810--- a/arch/x86/boot/compressed/efi_stub_32.S
11811+++ b/arch/x86/boot/compressed/efi_stub_32.S
11812@@ -46,16 +46,13 @@ ENTRY(efi_call_phys)
11813 * parameter 2, ..., param n. To make things easy, we save the return
11814 * address of efi_call_phys in a global variable.
11815 */
11816- popl %ecx
11817- movl %ecx, saved_return_addr(%edx)
11818- /* get the function pointer into ECX*/
11819- popl %ecx
11820- movl %ecx, efi_rt_function_ptr(%edx)
11821+ popl saved_return_addr(%edx)
11822+ popl efi_rt_function_ptr(%edx)
11823
11824 /*
11825 * 3. Call the physical function.
11826 */
11827- call *%ecx
11828+ call *efi_rt_function_ptr(%edx)
11829
11830 /*
11831 * 4. Balance the stack. And because EAX contain the return value,
11832@@ -67,15 +64,12 @@ ENTRY(efi_call_phys)
11833 1: popl %edx
11834 subl $1b, %edx
11835
11836- movl efi_rt_function_ptr(%edx), %ecx
11837- pushl %ecx
11838+ pushl efi_rt_function_ptr(%edx)
11839
11840 /*
11841 * 10. Push the saved return address onto the stack and return.
11842 */
11843- movl saved_return_addr(%edx), %ecx
11844- pushl %ecx
11845- ret
11846+ jmpl *saved_return_addr(%edx)
11847 ENDPROC(efi_call_phys)
11848 .previous
11849
11850diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
11851index 5d6f689..9d06730 100644
11852--- a/arch/x86/boot/compressed/head_32.S
11853+++ b/arch/x86/boot/compressed/head_32.S
11854@@ -118,7 +118,7 @@ preferred_addr:
11855 notl %eax
11856 andl %eax, %ebx
11857 #else
11858- movl $LOAD_PHYSICAL_ADDR, %ebx
11859+ movl $____LOAD_PHYSICAL_ADDR, %ebx
11860 #endif
11861
11862 /* Target address to relocate to for decompression */
11863diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
11864index c337422..2c5be72 100644
11865--- a/arch/x86/boot/compressed/head_64.S
11866+++ b/arch/x86/boot/compressed/head_64.S
11867@@ -95,7 +95,7 @@ ENTRY(startup_32)
11868 notl %eax
11869 andl %eax, %ebx
11870 #else
11871- movl $LOAD_PHYSICAL_ADDR, %ebx
11872+ movl $____LOAD_PHYSICAL_ADDR, %ebx
11873 #endif
11874
11875 /* Target address to relocate to for decompression */
11876@@ -270,7 +270,7 @@ preferred_addr:
11877 notq %rax
11878 andq %rax, %rbp
11879 #else
11880- movq $LOAD_PHYSICAL_ADDR, %rbp
11881+ movq $____LOAD_PHYSICAL_ADDR, %rbp
11882 #endif
11883
11884 /* Target address to relocate to for decompression */
11885@@ -362,8 +362,8 @@ gdt:
11886 .long gdt
11887 .word 0
11888 .quad 0x0000000000000000 /* NULL descriptor */
11889- .quad 0x00af9a000000ffff /* __KERNEL_CS */
11890- .quad 0x00cf92000000ffff /* __KERNEL_DS */
11891+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
11892+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
11893 .quad 0x0080890000000000 /* TS descriptor */
11894 .quad 0x0000000000000000 /* TS continued */
11895 gdt_end:
11896diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
11897index 434f077..b6b4b38 100644
11898--- a/arch/x86/boot/compressed/misc.c
11899+++ b/arch/x86/boot/compressed/misc.c
11900@@ -283,7 +283,7 @@ static void handle_relocations(void *output, unsigned long output_len)
11901 * Calculate the delta between where vmlinux was linked to load
11902 * and where it was actually loaded.
11903 */
11904- delta = min_addr - LOAD_PHYSICAL_ADDR;
11905+ delta = min_addr - ____LOAD_PHYSICAL_ADDR;
11906 if (!delta) {
11907 debug_putstr("No relocation needed... ");
11908 return;
11909@@ -380,7 +380,7 @@ static void parse_elf(void *output)
11910 case PT_LOAD:
11911 #ifdef CONFIG_RELOCATABLE
11912 dest = output;
11913- dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
11914+ dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
11915 #else
11916 dest = (void *)(phdr->p_paddr);
11917 #endif
11918@@ -432,7 +432,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
11919 error("Destination address too large");
11920 #endif
11921 #ifndef CONFIG_RELOCATABLE
11922- if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
11923+ if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
11924 error("Wrong destination address");
11925 #endif
11926
11927diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
11928index 4d3ff03..e4972ff 100644
11929--- a/arch/x86/boot/cpucheck.c
11930+++ b/arch/x86/boot/cpucheck.c
11931@@ -74,7 +74,7 @@ static int has_fpu(void)
11932 u16 fcw = -1, fsw = -1;
11933 u32 cr0;
11934
11935- asm("movl %%cr0,%0" : "=r" (cr0));
11936+ asm volatile("movl %%cr0,%0" : "=r" (cr0));
11937 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
11938 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
11939 asm volatile("movl %0,%%cr0" : : "r" (cr0));
11940@@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
11941 {
11942 u32 f0, f1;
11943
11944- asm("pushfl ; "
11945+ asm volatile("pushfl ; "
11946 "pushfl ; "
11947 "popl %0 ; "
11948 "movl %0,%1 ; "
11949@@ -115,7 +115,7 @@ static void get_flags(void)
11950 set_bit(X86_FEATURE_FPU, cpu.flags);
11951
11952 if (has_eflag(X86_EFLAGS_ID)) {
11953- asm("cpuid"
11954+ asm volatile("cpuid"
11955 : "=a" (max_intel_level),
11956 "=b" (cpu_vendor[0]),
11957 "=d" (cpu_vendor[1]),
11958@@ -124,7 +124,7 @@ static void get_flags(void)
11959
11960 if (max_intel_level >= 0x00000001 &&
11961 max_intel_level <= 0x0000ffff) {
11962- asm("cpuid"
11963+ asm volatile("cpuid"
11964 : "=a" (tfms),
11965 "=c" (cpu.flags[4]),
11966 "=d" (cpu.flags[0])
11967@@ -136,7 +136,7 @@ static void get_flags(void)
11968 cpu.model += ((tfms >> 16) & 0xf) << 4;
11969 }
11970
11971- asm("cpuid"
11972+ asm volatile("cpuid"
11973 : "=a" (max_amd_level)
11974 : "a" (0x80000000)
11975 : "ebx", "ecx", "edx");
11976@@ -144,7 +144,7 @@ static void get_flags(void)
11977 if (max_amd_level >= 0x80000001 &&
11978 max_amd_level <= 0x8000ffff) {
11979 u32 eax = 0x80000001;
11980- asm("cpuid"
11981+ asm volatile("cpuid"
11982 : "+a" (eax),
11983 "=c" (cpu.flags[6]),
11984 "=d" (cpu.flags[1])
11985@@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
11986 u32 ecx = MSR_K7_HWCR;
11987 u32 eax, edx;
11988
11989- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
11990+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
11991 eax &= ~(1 << 15);
11992- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
11993+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
11994
11995 get_flags(); /* Make sure it really did something */
11996 err = check_flags();
11997@@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
11998 u32 ecx = MSR_VIA_FCR;
11999 u32 eax, edx;
12000
12001- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12002+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12003 eax |= (1<<1)|(1<<7);
12004- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12005+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12006
12007 set_bit(X86_FEATURE_CX8, cpu.flags);
12008 err = check_flags();
12009@@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12010 u32 eax, edx;
12011 u32 level = 1;
12012
12013- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12014- asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
12015- asm("cpuid"
12016+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12017+ asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
12018+ asm volatile("cpuid"
12019 : "+a" (level), "=d" (cpu.flags[0])
12020 : : "ecx", "ebx");
12021- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12022+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12023
12024 err = check_flags();
12025 }
12026diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
12027index 9ec06a1..2c25e79 100644
12028--- a/arch/x86/boot/header.S
12029+++ b/arch/x86/boot/header.S
12030@@ -409,10 +409,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
12031 # single linked list of
12032 # struct setup_data
12033
12034-pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
12035+pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
12036
12037 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
12038+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
12039+#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
12040+#else
12041 #define VO_INIT_SIZE (VO__end - VO__text)
12042+#endif
12043 #if ZO_INIT_SIZE > VO_INIT_SIZE
12044 #define INIT_SIZE ZO_INIT_SIZE
12045 #else
12046diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
12047index db75d07..8e6d0af 100644
12048--- a/arch/x86/boot/memory.c
12049+++ b/arch/x86/boot/memory.c
12050@@ -19,7 +19,7 @@
12051
12052 static int detect_memory_e820(void)
12053 {
12054- int count = 0;
12055+ unsigned int count = 0;
12056 struct biosregs ireg, oreg;
12057 struct e820entry *desc = boot_params.e820_map;
12058 static struct e820entry buf; /* static so it is zeroed */
12059diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
12060index 11e8c6e..fdbb1ed 100644
12061--- a/arch/x86/boot/video-vesa.c
12062+++ b/arch/x86/boot/video-vesa.c
12063@@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
12064
12065 boot_params.screen_info.vesapm_seg = oreg.es;
12066 boot_params.screen_info.vesapm_off = oreg.di;
12067+ boot_params.screen_info.vesapm_size = oreg.cx;
12068 }
12069
12070 /*
12071diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
12072index 43eda28..5ab5fdb 100644
12073--- a/arch/x86/boot/video.c
12074+++ b/arch/x86/boot/video.c
12075@@ -96,7 +96,7 @@ static void store_mode_params(void)
12076 static unsigned int get_entry(void)
12077 {
12078 char entry_buf[4];
12079- int i, len = 0;
12080+ unsigned int i, len = 0;
12081 int key;
12082 unsigned int v;
12083
12084diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
12085index 9105655..5e37f27 100644
12086--- a/arch/x86/crypto/aes-x86_64-asm_64.S
12087+++ b/arch/x86/crypto/aes-x86_64-asm_64.S
12088@@ -8,6 +8,8 @@
12089 * including this sentence is retained in full.
12090 */
12091
12092+#include <asm/alternative-asm.h>
12093+
12094 .extern crypto_ft_tab
12095 .extern crypto_it_tab
12096 .extern crypto_fl_tab
12097@@ -70,6 +72,8 @@
12098 je B192; \
12099 leaq 32(r9),r9;
12100
12101+#define ret pax_force_retaddr 0, 1; ret
12102+
12103 #define epilogue(FUNC,r1,r2,r3,r4,r5,r6,r7,r8,r9) \
12104 movq r1,r2; \
12105 movq r3,r4; \
12106diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
12107index 477e9d7..3ab339f 100644
12108--- a/arch/x86/crypto/aesni-intel_asm.S
12109+++ b/arch/x86/crypto/aesni-intel_asm.S
12110@@ -31,6 +31,7 @@
12111
12112 #include <linux/linkage.h>
12113 #include <asm/inst.h>
12114+#include <asm/alternative-asm.h>
12115
12116 #ifdef __x86_64__
12117 .data
12118@@ -1441,6 +1442,7 @@ _return_T_done_decrypt:
12119 pop %r14
12120 pop %r13
12121 pop %r12
12122+ pax_force_retaddr 0, 1
12123 ret
12124 ENDPROC(aesni_gcm_dec)
12125
12126@@ -1705,6 +1707,7 @@ _return_T_done_encrypt:
12127 pop %r14
12128 pop %r13
12129 pop %r12
12130+ pax_force_retaddr 0, 1
12131 ret
12132 ENDPROC(aesni_gcm_enc)
12133
12134@@ -1722,6 +1725,7 @@ _key_expansion_256a:
12135 pxor %xmm1, %xmm0
12136 movaps %xmm0, (TKEYP)
12137 add $0x10, TKEYP
12138+ pax_force_retaddr_bts
12139 ret
12140 ENDPROC(_key_expansion_128)
12141 ENDPROC(_key_expansion_256a)
12142@@ -1748,6 +1752,7 @@ _key_expansion_192a:
12143 shufps $0b01001110, %xmm2, %xmm1
12144 movaps %xmm1, 0x10(TKEYP)
12145 add $0x20, TKEYP
12146+ pax_force_retaddr_bts
12147 ret
12148 ENDPROC(_key_expansion_192a)
12149
12150@@ -1768,6 +1773,7 @@ _key_expansion_192b:
12151
12152 movaps %xmm0, (TKEYP)
12153 add $0x10, TKEYP
12154+ pax_force_retaddr_bts
12155 ret
12156 ENDPROC(_key_expansion_192b)
12157
12158@@ -1781,6 +1787,7 @@ _key_expansion_256b:
12159 pxor %xmm1, %xmm2
12160 movaps %xmm2, (TKEYP)
12161 add $0x10, TKEYP
12162+ pax_force_retaddr_bts
12163 ret
12164 ENDPROC(_key_expansion_256b)
12165
12166@@ -1894,6 +1901,7 @@ ENTRY(aesni_set_key)
12167 #ifndef __x86_64__
12168 popl KEYP
12169 #endif
12170+ pax_force_retaddr 0, 1
12171 ret
12172 ENDPROC(aesni_set_key)
12173
12174@@ -1916,6 +1924,7 @@ ENTRY(aesni_enc)
12175 popl KLEN
12176 popl KEYP
12177 #endif
12178+ pax_force_retaddr 0, 1
12179 ret
12180 ENDPROC(aesni_enc)
12181
12182@@ -1974,6 +1983,7 @@ _aesni_enc1:
12183 AESENC KEY STATE
12184 movaps 0x70(TKEYP), KEY
12185 AESENCLAST KEY STATE
12186+ pax_force_retaddr_bts
12187 ret
12188 ENDPROC(_aesni_enc1)
12189
12190@@ -2083,6 +2093,7 @@ _aesni_enc4:
12191 AESENCLAST KEY STATE2
12192 AESENCLAST KEY STATE3
12193 AESENCLAST KEY STATE4
12194+ pax_force_retaddr_bts
12195 ret
12196 ENDPROC(_aesni_enc4)
12197
12198@@ -2106,6 +2117,7 @@ ENTRY(aesni_dec)
12199 popl KLEN
12200 popl KEYP
12201 #endif
12202+ pax_force_retaddr 0, 1
12203 ret
12204 ENDPROC(aesni_dec)
12205
12206@@ -2164,6 +2176,7 @@ _aesni_dec1:
12207 AESDEC KEY STATE
12208 movaps 0x70(TKEYP), KEY
12209 AESDECLAST KEY STATE
12210+ pax_force_retaddr_bts
12211 ret
12212 ENDPROC(_aesni_dec1)
12213
12214@@ -2273,6 +2286,7 @@ _aesni_dec4:
12215 AESDECLAST KEY STATE2
12216 AESDECLAST KEY STATE3
12217 AESDECLAST KEY STATE4
12218+ pax_force_retaddr_bts
12219 ret
12220 ENDPROC(_aesni_dec4)
12221
12222@@ -2331,6 +2345,7 @@ ENTRY(aesni_ecb_enc)
12223 popl KEYP
12224 popl LEN
12225 #endif
12226+ pax_force_retaddr 0, 1
12227 ret
12228 ENDPROC(aesni_ecb_enc)
12229
12230@@ -2390,6 +2405,7 @@ ENTRY(aesni_ecb_dec)
12231 popl KEYP
12232 popl LEN
12233 #endif
12234+ pax_force_retaddr 0, 1
12235 ret
12236 ENDPROC(aesni_ecb_dec)
12237
12238@@ -2432,6 +2448,7 @@ ENTRY(aesni_cbc_enc)
12239 popl LEN
12240 popl IVP
12241 #endif
12242+ pax_force_retaddr 0, 1
12243 ret
12244 ENDPROC(aesni_cbc_enc)
12245
12246@@ -2523,6 +2540,7 @@ ENTRY(aesni_cbc_dec)
12247 popl LEN
12248 popl IVP
12249 #endif
12250+ pax_force_retaddr 0, 1
12251 ret
12252 ENDPROC(aesni_cbc_dec)
12253
12254@@ -2550,6 +2568,7 @@ _aesni_inc_init:
12255 mov $1, TCTR_LOW
12256 MOVQ_R64_XMM TCTR_LOW INC
12257 MOVQ_R64_XMM CTR TCTR_LOW
12258+ pax_force_retaddr_bts
12259 ret
12260 ENDPROC(_aesni_inc_init)
12261
12262@@ -2579,6 +2598,7 @@ _aesni_inc:
12263 .Linc_low:
12264 movaps CTR, IV
12265 PSHUFB_XMM BSWAP_MASK IV
12266+ pax_force_retaddr_bts
12267 ret
12268 ENDPROC(_aesni_inc)
12269
12270@@ -2640,6 +2660,7 @@ ENTRY(aesni_ctr_enc)
12271 .Lctr_enc_ret:
12272 movups IV, (IVP)
12273 .Lctr_enc_just_ret:
12274+ pax_force_retaddr 0, 1
12275 ret
12276 ENDPROC(aesni_ctr_enc)
12277
12278@@ -2766,6 +2787,7 @@ ENTRY(aesni_xts_crypt8)
12279 pxor INC, STATE4
12280 movdqu STATE4, 0x70(OUTP)
12281
12282+ pax_force_retaddr 0, 1
12283 ret
12284 ENDPROC(aesni_xts_crypt8)
12285
12286diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
12287index 246c670..4d1ed00 100644
12288--- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
12289+++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
12290@@ -21,6 +21,7 @@
12291 */
12292
12293 #include <linux/linkage.h>
12294+#include <asm/alternative-asm.h>
12295
12296 .file "blowfish-x86_64-asm.S"
12297 .text
12298@@ -149,9 +150,11 @@ ENTRY(__blowfish_enc_blk)
12299 jnz .L__enc_xor;
12300
12301 write_block();
12302+ pax_force_retaddr 0, 1
12303 ret;
12304 .L__enc_xor:
12305 xor_block();
12306+ pax_force_retaddr 0, 1
12307 ret;
12308 ENDPROC(__blowfish_enc_blk)
12309
12310@@ -183,6 +186,7 @@ ENTRY(blowfish_dec_blk)
12311
12312 movq %r11, %rbp;
12313
12314+ pax_force_retaddr 0, 1
12315 ret;
12316 ENDPROC(blowfish_dec_blk)
12317
12318@@ -334,6 +338,7 @@ ENTRY(__blowfish_enc_blk_4way)
12319
12320 popq %rbx;
12321 popq %rbp;
12322+ pax_force_retaddr 0, 1
12323 ret;
12324
12325 .L__enc_xor4:
12326@@ -341,6 +346,7 @@ ENTRY(__blowfish_enc_blk_4way)
12327
12328 popq %rbx;
12329 popq %rbp;
12330+ pax_force_retaddr 0, 1
12331 ret;
12332 ENDPROC(__blowfish_enc_blk_4way)
12333
12334@@ -375,5 +381,6 @@ ENTRY(blowfish_dec_blk_4way)
12335 popq %rbx;
12336 popq %rbp;
12337
12338+ pax_force_retaddr 0, 1
12339 ret;
12340 ENDPROC(blowfish_dec_blk_4way)
12341diff --git a/arch/x86/crypto/camellia-aesni-avx-asm_64.S b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
12342index ce71f92..2dd5b1e 100644
12343--- a/arch/x86/crypto/camellia-aesni-avx-asm_64.S
12344+++ b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
12345@@ -16,6 +16,7 @@
12346 */
12347
12348 #include <linux/linkage.h>
12349+#include <asm/alternative-asm.h>
12350
12351 #define CAMELLIA_TABLE_BYTE_LEN 272
12352
12353@@ -191,6 +192,7 @@ roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
12354 roundsm16(%xmm0, %xmm1, %xmm2, %xmm3, %xmm4, %xmm5, %xmm6, %xmm7,
12355 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14, %xmm15,
12356 %rcx, (%r9));
12357+ pax_force_retaddr_bts
12358 ret;
12359 ENDPROC(roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
12360
12361@@ -199,6 +201,7 @@ roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
12362 roundsm16(%xmm4, %xmm5, %xmm6, %xmm7, %xmm0, %xmm1, %xmm2, %xmm3,
12363 %xmm12, %xmm13, %xmm14, %xmm15, %xmm8, %xmm9, %xmm10, %xmm11,
12364 %rax, (%r9));
12365+ pax_force_retaddr_bts
12366 ret;
12367 ENDPROC(roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
12368
12369@@ -780,6 +783,7 @@ __camellia_enc_blk16:
12370 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
12371 %xmm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 16(%rax));
12372
12373+ pax_force_retaddr_bts
12374 ret;
12375
12376 .align 8
12377@@ -865,6 +869,7 @@ __camellia_dec_blk16:
12378 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
12379 %xmm15, (key_table)(CTX), (%rax), 1 * 16(%rax));
12380
12381+ pax_force_retaddr_bts
12382 ret;
12383
12384 .align 8
12385@@ -904,6 +909,7 @@ ENTRY(camellia_ecb_enc_16way)
12386 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
12387 %xmm8, %rsi);
12388
12389+ pax_force_retaddr 0, 1
12390 ret;
12391 ENDPROC(camellia_ecb_enc_16way)
12392
12393@@ -932,6 +938,7 @@ ENTRY(camellia_ecb_dec_16way)
12394 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
12395 %xmm8, %rsi);
12396
12397+ pax_force_retaddr 0, 1
12398 ret;
12399 ENDPROC(camellia_ecb_dec_16way)
12400
12401@@ -981,6 +988,7 @@ ENTRY(camellia_cbc_dec_16way)
12402 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
12403 %xmm8, %rsi);
12404
12405+ pax_force_retaddr 0, 1
12406 ret;
12407 ENDPROC(camellia_cbc_dec_16way)
12408
12409@@ -1092,6 +1100,7 @@ ENTRY(camellia_ctr_16way)
12410 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
12411 %xmm8, %rsi);
12412
12413+ pax_force_retaddr 0, 1
12414 ret;
12415 ENDPROC(camellia_ctr_16way)
12416
12417@@ -1234,6 +1243,7 @@ camellia_xts_crypt_16way:
12418 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
12419 %xmm8, %rsi);
12420
12421+ pax_force_retaddr 0, 1
12422 ret;
12423 ENDPROC(camellia_xts_crypt_16way)
12424
12425diff --git a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
12426index 0e0b886..8fc756a 100644
12427--- a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
12428+++ b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
12429@@ -11,6 +11,7 @@
12430 */
12431
12432 #include <linux/linkage.h>
12433+#include <asm/alternative-asm.h>
12434
12435 #define CAMELLIA_TABLE_BYTE_LEN 272
12436
12437@@ -230,6 +231,7 @@ roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
12438 roundsm32(%ymm0, %ymm1, %ymm2, %ymm3, %ymm4, %ymm5, %ymm6, %ymm7,
12439 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14, %ymm15,
12440 %rcx, (%r9));
12441+ pax_force_retaddr_bts
12442 ret;
12443 ENDPROC(roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
12444
12445@@ -238,6 +240,7 @@ roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
12446 roundsm32(%ymm4, %ymm5, %ymm6, %ymm7, %ymm0, %ymm1, %ymm2, %ymm3,
12447 %ymm12, %ymm13, %ymm14, %ymm15, %ymm8, %ymm9, %ymm10, %ymm11,
12448 %rax, (%r9));
12449+ pax_force_retaddr_bts
12450 ret;
12451 ENDPROC(roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
12452
12453@@ -820,6 +823,7 @@ __camellia_enc_blk32:
12454 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
12455 %ymm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 32(%rax));
12456
12457+ pax_force_retaddr_bts
12458 ret;
12459
12460 .align 8
12461@@ -905,6 +909,7 @@ __camellia_dec_blk32:
12462 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
12463 %ymm15, (key_table)(CTX), (%rax), 1 * 32(%rax));
12464
12465+ pax_force_retaddr_bts
12466 ret;
12467
12468 .align 8
12469@@ -948,6 +953,7 @@ ENTRY(camellia_ecb_enc_32way)
12470
12471 vzeroupper;
12472
12473+ pax_force_retaddr 0, 1
12474 ret;
12475 ENDPROC(camellia_ecb_enc_32way)
12476
12477@@ -980,6 +986,7 @@ ENTRY(camellia_ecb_dec_32way)
12478
12479 vzeroupper;
12480
12481+ pax_force_retaddr 0, 1
12482 ret;
12483 ENDPROC(camellia_ecb_dec_32way)
12484
12485@@ -1046,6 +1053,7 @@ ENTRY(camellia_cbc_dec_32way)
12486
12487 vzeroupper;
12488
12489+ pax_force_retaddr 0, 1
12490 ret;
12491 ENDPROC(camellia_cbc_dec_32way)
12492
12493@@ -1184,6 +1192,7 @@ ENTRY(camellia_ctr_32way)
12494
12495 vzeroupper;
12496
12497+ pax_force_retaddr 0, 1
12498 ret;
12499 ENDPROC(camellia_ctr_32way)
12500
12501@@ -1349,6 +1358,7 @@ camellia_xts_crypt_32way:
12502
12503 vzeroupper;
12504
12505+ pax_force_retaddr 0, 1
12506 ret;
12507 ENDPROC(camellia_xts_crypt_32way)
12508
12509diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
12510index 310319c..ce174a4 100644
12511--- a/arch/x86/crypto/camellia-x86_64-asm_64.S
12512+++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
12513@@ -21,6 +21,7 @@
12514 */
12515
12516 #include <linux/linkage.h>
12517+#include <asm/alternative-asm.h>
12518
12519 .file "camellia-x86_64-asm_64.S"
12520 .text
12521@@ -228,12 +229,14 @@ ENTRY(__camellia_enc_blk)
12522 enc_outunpack(mov, RT1);
12523
12524 movq RRBP, %rbp;
12525+ pax_force_retaddr 0, 1
12526 ret;
12527
12528 .L__enc_xor:
12529 enc_outunpack(xor, RT1);
12530
12531 movq RRBP, %rbp;
12532+ pax_force_retaddr 0, 1
12533 ret;
12534 ENDPROC(__camellia_enc_blk)
12535
12536@@ -272,6 +275,7 @@ ENTRY(camellia_dec_blk)
12537 dec_outunpack();
12538
12539 movq RRBP, %rbp;
12540+ pax_force_retaddr 0, 1
12541 ret;
12542 ENDPROC(camellia_dec_blk)
12543
12544@@ -463,6 +467,7 @@ ENTRY(__camellia_enc_blk_2way)
12545
12546 movq RRBP, %rbp;
12547 popq %rbx;
12548+ pax_force_retaddr 0, 1
12549 ret;
12550
12551 .L__enc2_xor:
12552@@ -470,6 +475,7 @@ ENTRY(__camellia_enc_blk_2way)
12553
12554 movq RRBP, %rbp;
12555 popq %rbx;
12556+ pax_force_retaddr 0, 1
12557 ret;
12558 ENDPROC(__camellia_enc_blk_2way)
12559
12560@@ -510,5 +516,6 @@ ENTRY(camellia_dec_blk_2way)
12561
12562 movq RRBP, %rbp;
12563 movq RXOR, %rbx;
12564+ pax_force_retaddr 0, 1
12565 ret;
12566 ENDPROC(camellia_dec_blk_2way)
12567diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
12568index c35fd5d..c1ee236 100644
12569--- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
12570+++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
12571@@ -24,6 +24,7 @@
12572 */
12573
12574 #include <linux/linkage.h>
12575+#include <asm/alternative-asm.h>
12576
12577 .file "cast5-avx-x86_64-asm_64.S"
12578
12579@@ -281,6 +282,7 @@ __cast5_enc_blk16:
12580 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
12581 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
12582
12583+ pax_force_retaddr 0, 1
12584 ret;
12585 ENDPROC(__cast5_enc_blk16)
12586
12587@@ -352,6 +354,7 @@ __cast5_dec_blk16:
12588 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
12589 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
12590
12591+ pax_force_retaddr 0, 1
12592 ret;
12593
12594 .L__skip_dec:
12595@@ -388,6 +391,7 @@ ENTRY(cast5_ecb_enc_16way)
12596 vmovdqu RR4, (6*4*4)(%r11);
12597 vmovdqu RL4, (7*4*4)(%r11);
12598
12599+ pax_force_retaddr
12600 ret;
12601 ENDPROC(cast5_ecb_enc_16way)
12602
12603@@ -420,6 +424,7 @@ ENTRY(cast5_ecb_dec_16way)
12604 vmovdqu RR4, (6*4*4)(%r11);
12605 vmovdqu RL4, (7*4*4)(%r11);
12606
12607+ pax_force_retaddr
12608 ret;
12609 ENDPROC(cast5_ecb_dec_16way)
12610
12611@@ -469,6 +474,7 @@ ENTRY(cast5_cbc_dec_16way)
12612
12613 popq %r12;
12614
12615+ pax_force_retaddr
12616 ret;
12617 ENDPROC(cast5_cbc_dec_16way)
12618
12619@@ -542,5 +548,6 @@ ENTRY(cast5_ctr_16way)
12620
12621 popq %r12;
12622
12623+ pax_force_retaddr
12624 ret;
12625 ENDPROC(cast5_ctr_16way)
12626diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
12627index e3531f8..18ded3a 100644
12628--- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
12629+++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
12630@@ -24,6 +24,7 @@
12631 */
12632
12633 #include <linux/linkage.h>
12634+#include <asm/alternative-asm.h>
12635 #include "glue_helper-asm-avx.S"
12636
12637 .file "cast6-avx-x86_64-asm_64.S"
12638@@ -295,6 +296,7 @@ __cast6_enc_blk8:
12639 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
12640 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
12641
12642+ pax_force_retaddr 0, 1
12643 ret;
12644 ENDPROC(__cast6_enc_blk8)
12645
12646@@ -340,6 +342,7 @@ __cast6_dec_blk8:
12647 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
12648 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
12649
12650+ pax_force_retaddr 0, 1
12651 ret;
12652 ENDPROC(__cast6_dec_blk8)
12653
12654@@ -358,6 +361,7 @@ ENTRY(cast6_ecb_enc_8way)
12655
12656 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
12657
12658+ pax_force_retaddr
12659 ret;
12660 ENDPROC(cast6_ecb_enc_8way)
12661
12662@@ -376,6 +380,7 @@ ENTRY(cast6_ecb_dec_8way)
12663
12664 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
12665
12666+ pax_force_retaddr
12667 ret;
12668 ENDPROC(cast6_ecb_dec_8way)
12669
12670@@ -399,6 +404,7 @@ ENTRY(cast6_cbc_dec_8way)
12671
12672 popq %r12;
12673
12674+ pax_force_retaddr
12675 ret;
12676 ENDPROC(cast6_cbc_dec_8way)
12677
12678@@ -424,6 +430,7 @@ ENTRY(cast6_ctr_8way)
12679
12680 popq %r12;
12681
12682+ pax_force_retaddr
12683 ret;
12684 ENDPROC(cast6_ctr_8way)
12685
12686@@ -446,6 +453,7 @@ ENTRY(cast6_xts_enc_8way)
12687 /* dst <= regs xor IVs(in dst) */
12688 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
12689
12690+ pax_force_retaddr
12691 ret;
12692 ENDPROC(cast6_xts_enc_8way)
12693
12694@@ -468,5 +476,6 @@ ENTRY(cast6_xts_dec_8way)
12695 /* dst <= regs xor IVs(in dst) */
12696 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
12697
12698+ pax_force_retaddr
12699 ret;
12700 ENDPROC(cast6_xts_dec_8way)
12701diff --git a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
12702index dbc4339..3d868c5 100644
12703--- a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
12704+++ b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
12705@@ -45,6 +45,7 @@
12706
12707 #include <asm/inst.h>
12708 #include <linux/linkage.h>
12709+#include <asm/alternative-asm.h>
12710
12711 ## ISCSI CRC 32 Implementation with crc32 and pclmulqdq Instruction
12712
12713@@ -312,6 +313,7 @@ do_return:
12714 popq %rsi
12715 popq %rdi
12716 popq %rbx
12717+ pax_force_retaddr 0, 1
12718 ret
12719
12720 ################################################################
12721diff --git a/arch/x86/crypto/ghash-clmulni-intel_asm.S b/arch/x86/crypto/ghash-clmulni-intel_asm.S
12722index 586f41a..d02851e 100644
12723--- a/arch/x86/crypto/ghash-clmulni-intel_asm.S
12724+++ b/arch/x86/crypto/ghash-clmulni-intel_asm.S
12725@@ -18,6 +18,7 @@
12726
12727 #include <linux/linkage.h>
12728 #include <asm/inst.h>
12729+#include <asm/alternative-asm.h>
12730
12731 .data
12732
12733@@ -93,6 +94,7 @@ __clmul_gf128mul_ble:
12734 psrlq $1, T2
12735 pxor T2, T1
12736 pxor T1, DATA
12737+ pax_force_retaddr
12738 ret
12739 ENDPROC(__clmul_gf128mul_ble)
12740
12741@@ -105,6 +107,7 @@ ENTRY(clmul_ghash_mul)
12742 call __clmul_gf128mul_ble
12743 PSHUFB_XMM BSWAP DATA
12744 movups DATA, (%rdi)
12745+ pax_force_retaddr
12746 ret
12747 ENDPROC(clmul_ghash_mul)
12748
12749@@ -132,6 +135,7 @@ ENTRY(clmul_ghash_update)
12750 PSHUFB_XMM BSWAP DATA
12751 movups DATA, (%rdi)
12752 .Lupdate_just_ret:
12753+ pax_force_retaddr
12754 ret
12755 ENDPROC(clmul_ghash_update)
12756
12757@@ -157,5 +161,6 @@ ENTRY(clmul_ghash_setkey)
12758 pand .Lpoly, %xmm1
12759 pxor %xmm1, %xmm0
12760 movups %xmm0, (%rdi)
12761+ pax_force_retaddr
12762 ret
12763 ENDPROC(clmul_ghash_setkey)
12764diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
12765index 9279e0b..9270820 100644
12766--- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
12767+++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
12768@@ -1,4 +1,5 @@
12769 #include <linux/linkage.h>
12770+#include <asm/alternative-asm.h>
12771
12772 # enter salsa20_encrypt_bytes
12773 ENTRY(salsa20_encrypt_bytes)
12774@@ -789,6 +790,7 @@ ENTRY(salsa20_encrypt_bytes)
12775 add %r11,%rsp
12776 mov %rdi,%rax
12777 mov %rsi,%rdx
12778+ pax_force_retaddr 0, 1
12779 ret
12780 # bytesatleast65:
12781 ._bytesatleast65:
12782@@ -889,6 +891,7 @@ ENTRY(salsa20_keysetup)
12783 add %r11,%rsp
12784 mov %rdi,%rax
12785 mov %rsi,%rdx
12786+ pax_force_retaddr
12787 ret
12788 ENDPROC(salsa20_keysetup)
12789
12790@@ -914,5 +917,6 @@ ENTRY(salsa20_ivsetup)
12791 add %r11,%rsp
12792 mov %rdi,%rax
12793 mov %rsi,%rdx
12794+ pax_force_retaddr
12795 ret
12796 ENDPROC(salsa20_ivsetup)
12797diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
12798index 2f202f4..d9164d6 100644
12799--- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
12800+++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
12801@@ -24,6 +24,7 @@
12802 */
12803
12804 #include <linux/linkage.h>
12805+#include <asm/alternative-asm.h>
12806 #include "glue_helper-asm-avx.S"
12807
12808 .file "serpent-avx-x86_64-asm_64.S"
12809@@ -618,6 +619,7 @@ __serpent_enc_blk8_avx:
12810 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
12811 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
12812
12813+ pax_force_retaddr
12814 ret;
12815 ENDPROC(__serpent_enc_blk8_avx)
12816
12817@@ -672,6 +674,7 @@ __serpent_dec_blk8_avx:
12818 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
12819 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
12820
12821+ pax_force_retaddr
12822 ret;
12823 ENDPROC(__serpent_dec_blk8_avx)
12824
12825@@ -688,6 +691,7 @@ ENTRY(serpent_ecb_enc_8way_avx)
12826
12827 store_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
12828
12829+ pax_force_retaddr
12830 ret;
12831 ENDPROC(serpent_ecb_enc_8way_avx)
12832
12833@@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_8way_avx)
12834
12835 store_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
12836
12837+ pax_force_retaddr
12838 ret;
12839 ENDPROC(serpent_ecb_dec_8way_avx)
12840
12841@@ -720,6 +725,7 @@ ENTRY(serpent_cbc_dec_8way_avx)
12842
12843 store_cbc_8way(%rdx, %rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
12844
12845+ pax_force_retaddr
12846 ret;
12847 ENDPROC(serpent_cbc_dec_8way_avx)
12848
12849@@ -738,6 +744,7 @@ ENTRY(serpent_ctr_8way_avx)
12850
12851 store_ctr_8way(%rdx, %rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
12852
12853+ pax_force_retaddr
12854 ret;
12855 ENDPROC(serpent_ctr_8way_avx)
12856
12857@@ -758,6 +765,7 @@ ENTRY(serpent_xts_enc_8way_avx)
12858 /* dst <= regs xor IVs(in dst) */
12859 store_xts_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
12860
12861+ pax_force_retaddr
12862 ret;
12863 ENDPROC(serpent_xts_enc_8way_avx)
12864
12865@@ -778,5 +786,6 @@ ENTRY(serpent_xts_dec_8way_avx)
12866 /* dst <= regs xor IVs(in dst) */
12867 store_xts_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
12868
12869+ pax_force_retaddr
12870 ret;
12871 ENDPROC(serpent_xts_dec_8way_avx)
12872diff --git a/arch/x86/crypto/serpent-avx2-asm_64.S b/arch/x86/crypto/serpent-avx2-asm_64.S
12873index b222085..abd483c 100644
12874--- a/arch/x86/crypto/serpent-avx2-asm_64.S
12875+++ b/arch/x86/crypto/serpent-avx2-asm_64.S
12876@@ -15,6 +15,7 @@
12877 */
12878
12879 #include <linux/linkage.h>
12880+#include <asm/alternative-asm.h>
12881 #include "glue_helper-asm-avx2.S"
12882
12883 .file "serpent-avx2-asm_64.S"
12884@@ -610,6 +611,7 @@ __serpent_enc_blk16:
12885 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
12886 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
12887
12888+ pax_force_retaddr
12889 ret;
12890 ENDPROC(__serpent_enc_blk16)
12891
12892@@ -664,6 +666,7 @@ __serpent_dec_blk16:
12893 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
12894 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
12895
12896+ pax_force_retaddr
12897 ret;
12898 ENDPROC(__serpent_dec_blk16)
12899
12900@@ -684,6 +687,7 @@ ENTRY(serpent_ecb_enc_16way)
12901
12902 vzeroupper;
12903
12904+ pax_force_retaddr
12905 ret;
12906 ENDPROC(serpent_ecb_enc_16way)
12907
12908@@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_16way)
12909
12910 vzeroupper;
12911
12912+ pax_force_retaddr
12913 ret;
12914 ENDPROC(serpent_ecb_dec_16way)
12915
12916@@ -725,6 +730,7 @@ ENTRY(serpent_cbc_dec_16way)
12917
12918 vzeroupper;
12919
12920+ pax_force_retaddr
12921 ret;
12922 ENDPROC(serpent_cbc_dec_16way)
12923
12924@@ -748,6 +754,7 @@ ENTRY(serpent_ctr_16way)
12925
12926 vzeroupper;
12927
12928+ pax_force_retaddr
12929 ret;
12930 ENDPROC(serpent_ctr_16way)
12931
12932@@ -772,6 +779,7 @@ ENTRY(serpent_xts_enc_16way)
12933
12934 vzeroupper;
12935
12936+ pax_force_retaddr
12937 ret;
12938 ENDPROC(serpent_xts_enc_16way)
12939
12940@@ -796,5 +804,6 @@ ENTRY(serpent_xts_dec_16way)
12941
12942 vzeroupper;
12943
12944+ pax_force_retaddr
12945 ret;
12946 ENDPROC(serpent_xts_dec_16way)
12947diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
12948index acc066c..1559cc4 100644
12949--- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
12950+++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
12951@@ -25,6 +25,7 @@
12952 */
12953
12954 #include <linux/linkage.h>
12955+#include <asm/alternative-asm.h>
12956
12957 .file "serpent-sse2-x86_64-asm_64.S"
12958 .text
12959@@ -690,12 +691,14 @@ ENTRY(__serpent_enc_blk_8way)
12960 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
12961 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
12962
12963+ pax_force_retaddr
12964 ret;
12965
12966 .L__enc_xor8:
12967 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
12968 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
12969
12970+ pax_force_retaddr
12971 ret;
12972 ENDPROC(__serpent_enc_blk_8way)
12973
12974@@ -750,5 +753,6 @@ ENTRY(serpent_dec_blk_8way)
12975 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
12976 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
12977
12978+ pax_force_retaddr
12979 ret;
12980 ENDPROC(serpent_dec_blk_8way)
12981diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
12982index a410950..3356d42 100644
12983--- a/arch/x86/crypto/sha1_ssse3_asm.S
12984+++ b/arch/x86/crypto/sha1_ssse3_asm.S
12985@@ -29,6 +29,7 @@
12986 */
12987
12988 #include <linux/linkage.h>
12989+#include <asm/alternative-asm.h>
12990
12991 #define CTX %rdi // arg1
12992 #define BUF %rsi // arg2
12993@@ -104,6 +105,7 @@
12994 pop %r12
12995 pop %rbp
12996 pop %rbx
12997+ pax_force_retaddr 0, 1
12998 ret
12999
13000 ENDPROC(\name)
13001diff --git a/arch/x86/crypto/sha256-avx-asm.S b/arch/x86/crypto/sha256-avx-asm.S
13002index 642f156..4ab07b9 100644
13003--- a/arch/x86/crypto/sha256-avx-asm.S
13004+++ b/arch/x86/crypto/sha256-avx-asm.S
13005@@ -49,6 +49,7 @@
13006
13007 #ifdef CONFIG_AS_AVX
13008 #include <linux/linkage.h>
13009+#include <asm/alternative-asm.h>
13010
13011 ## assume buffers not aligned
13012 #define VMOVDQ vmovdqu
13013@@ -460,6 +461,7 @@ done_hash:
13014 popq %r13
13015 popq %rbp
13016 popq %rbx
13017+ pax_force_retaddr 0, 1
13018 ret
13019 ENDPROC(sha256_transform_avx)
13020
13021diff --git a/arch/x86/crypto/sha256-avx2-asm.S b/arch/x86/crypto/sha256-avx2-asm.S
13022index 9e86944..2e7f95a 100644
13023--- a/arch/x86/crypto/sha256-avx2-asm.S
13024+++ b/arch/x86/crypto/sha256-avx2-asm.S
13025@@ -50,6 +50,7 @@
13026
13027 #ifdef CONFIG_AS_AVX2
13028 #include <linux/linkage.h>
13029+#include <asm/alternative-asm.h>
13030
13031 ## assume buffers not aligned
13032 #define VMOVDQ vmovdqu
13033@@ -720,6 +721,7 @@ done_hash:
13034 popq %r12
13035 popq %rbp
13036 popq %rbx
13037+ pax_force_retaddr 0, 1
13038 ret
13039 ENDPROC(sha256_transform_rorx)
13040
13041diff --git a/arch/x86/crypto/sha256-ssse3-asm.S b/arch/x86/crypto/sha256-ssse3-asm.S
13042index f833b74..c36ed14 100644
13043--- a/arch/x86/crypto/sha256-ssse3-asm.S
13044+++ b/arch/x86/crypto/sha256-ssse3-asm.S
13045@@ -47,6 +47,7 @@
13046 ########################################################################
13047
13048 #include <linux/linkage.h>
13049+#include <asm/alternative-asm.h>
13050
13051 ## assume buffers not aligned
13052 #define MOVDQ movdqu
13053@@ -471,6 +472,7 @@ done_hash:
13054 popq %rbp
13055 popq %rbx
13056
13057+ pax_force_retaddr 0, 1
13058 ret
13059 ENDPROC(sha256_transform_ssse3)
13060
13061diff --git a/arch/x86/crypto/sha512-avx-asm.S b/arch/x86/crypto/sha512-avx-asm.S
13062index 974dde9..4533d34 100644
13063--- a/arch/x86/crypto/sha512-avx-asm.S
13064+++ b/arch/x86/crypto/sha512-avx-asm.S
13065@@ -49,6 +49,7 @@
13066
13067 #ifdef CONFIG_AS_AVX
13068 #include <linux/linkage.h>
13069+#include <asm/alternative-asm.h>
13070
13071 .text
13072
13073@@ -364,6 +365,7 @@ updateblock:
13074 mov frame_RSPSAVE(%rsp), %rsp
13075
13076 nowork:
13077+ pax_force_retaddr 0, 1
13078 ret
13079 ENDPROC(sha512_transform_avx)
13080
13081diff --git a/arch/x86/crypto/sha512-avx2-asm.S b/arch/x86/crypto/sha512-avx2-asm.S
13082index 568b961..061ef1d 100644
13083--- a/arch/x86/crypto/sha512-avx2-asm.S
13084+++ b/arch/x86/crypto/sha512-avx2-asm.S
13085@@ -51,6 +51,7 @@
13086
13087 #ifdef CONFIG_AS_AVX2
13088 #include <linux/linkage.h>
13089+#include <asm/alternative-asm.h>
13090
13091 .text
13092
13093@@ -678,6 +679,7 @@ done_hash:
13094
13095 # Restore Stack Pointer
13096 mov frame_RSPSAVE(%rsp), %rsp
13097+ pax_force_retaddr 0, 1
13098 ret
13099 ENDPROC(sha512_transform_rorx)
13100
13101diff --git a/arch/x86/crypto/sha512-ssse3-asm.S b/arch/x86/crypto/sha512-ssse3-asm.S
13102index fb56855..e23914f 100644
13103--- a/arch/x86/crypto/sha512-ssse3-asm.S
13104+++ b/arch/x86/crypto/sha512-ssse3-asm.S
13105@@ -48,6 +48,7 @@
13106 ########################################################################
13107
13108 #include <linux/linkage.h>
13109+#include <asm/alternative-asm.h>
13110
13111 .text
13112
13113@@ -363,6 +364,7 @@ updateblock:
13114 mov frame_RSPSAVE(%rsp), %rsp
13115
13116 nowork:
13117+ pax_force_retaddr 0, 1
13118 ret
13119 ENDPROC(sha512_transform_ssse3)
13120
13121diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
13122index 0505813..63b1d00 100644
13123--- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
13124+++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
13125@@ -24,6 +24,7 @@
13126 */
13127
13128 #include <linux/linkage.h>
13129+#include <asm/alternative-asm.h>
13130 #include "glue_helper-asm-avx.S"
13131
13132 .file "twofish-avx-x86_64-asm_64.S"
13133@@ -284,6 +285,7 @@ __twofish_enc_blk8:
13134 outunpack_blocks(RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
13135 outunpack_blocks(RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
13136
13137+ pax_force_retaddr 0, 1
13138 ret;
13139 ENDPROC(__twofish_enc_blk8)
13140
13141@@ -324,6 +326,7 @@ __twofish_dec_blk8:
13142 outunpack_blocks(RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
13143 outunpack_blocks(RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
13144
13145+ pax_force_retaddr 0, 1
13146 ret;
13147 ENDPROC(__twofish_dec_blk8)
13148
13149@@ -342,6 +345,7 @@ ENTRY(twofish_ecb_enc_8way)
13150
13151 store_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
13152
13153+ pax_force_retaddr 0, 1
13154 ret;
13155 ENDPROC(twofish_ecb_enc_8way)
13156
13157@@ -360,6 +364,7 @@ ENTRY(twofish_ecb_dec_8way)
13158
13159 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13160
13161+ pax_force_retaddr 0, 1
13162 ret;
13163 ENDPROC(twofish_ecb_dec_8way)
13164
13165@@ -383,6 +388,7 @@ ENTRY(twofish_cbc_dec_8way)
13166
13167 popq %r12;
13168
13169+ pax_force_retaddr 0, 1
13170 ret;
13171 ENDPROC(twofish_cbc_dec_8way)
13172
13173@@ -408,6 +414,7 @@ ENTRY(twofish_ctr_8way)
13174
13175 popq %r12;
13176
13177+ pax_force_retaddr 0, 1
13178 ret;
13179 ENDPROC(twofish_ctr_8way)
13180
13181@@ -430,6 +437,7 @@ ENTRY(twofish_xts_enc_8way)
13182 /* dst <= regs xor IVs(in dst) */
13183 store_xts_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
13184
13185+ pax_force_retaddr 0, 1
13186 ret;
13187 ENDPROC(twofish_xts_enc_8way)
13188
13189@@ -452,5 +460,6 @@ ENTRY(twofish_xts_dec_8way)
13190 /* dst <= regs xor IVs(in dst) */
13191 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13192
13193+ pax_force_retaddr 0, 1
13194 ret;
13195 ENDPROC(twofish_xts_dec_8way)
13196diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
13197index 1c3b7ce..b365c5e 100644
13198--- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
13199+++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
13200@@ -21,6 +21,7 @@
13201 */
13202
13203 #include <linux/linkage.h>
13204+#include <asm/alternative-asm.h>
13205
13206 .file "twofish-x86_64-asm-3way.S"
13207 .text
13208@@ -258,6 +259,7 @@ ENTRY(__twofish_enc_blk_3way)
13209 popq %r13;
13210 popq %r14;
13211 popq %r15;
13212+ pax_force_retaddr 0, 1
13213 ret;
13214
13215 .L__enc_xor3:
13216@@ -269,6 +271,7 @@ ENTRY(__twofish_enc_blk_3way)
13217 popq %r13;
13218 popq %r14;
13219 popq %r15;
13220+ pax_force_retaddr 0, 1
13221 ret;
13222 ENDPROC(__twofish_enc_blk_3way)
13223
13224@@ -308,5 +311,6 @@ ENTRY(twofish_dec_blk_3way)
13225 popq %r13;
13226 popq %r14;
13227 popq %r15;
13228+ pax_force_retaddr 0, 1
13229 ret;
13230 ENDPROC(twofish_dec_blk_3way)
13231diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
13232index a039d21..29e7615 100644
13233--- a/arch/x86/crypto/twofish-x86_64-asm_64.S
13234+++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
13235@@ -22,6 +22,7 @@
13236
13237 #include <linux/linkage.h>
13238 #include <asm/asm-offsets.h>
13239+#include <asm/alternative-asm.h>
13240
13241 #define a_offset 0
13242 #define b_offset 4
13243@@ -265,6 +266,7 @@ ENTRY(twofish_enc_blk)
13244
13245 popq R1
13246 movq $1,%rax
13247+ pax_force_retaddr 0, 1
13248 ret
13249 ENDPROC(twofish_enc_blk)
13250
13251@@ -317,5 +319,6 @@ ENTRY(twofish_dec_blk)
13252
13253 popq R1
13254 movq $1,%rax
13255+ pax_force_retaddr 0, 1
13256 ret
13257 ENDPROC(twofish_dec_blk)
13258diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
13259index bae3aba..c1788c1 100644
13260--- a/arch/x86/ia32/ia32_aout.c
13261+++ b/arch/x86/ia32/ia32_aout.c
13262@@ -159,6 +159,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file,
13263 unsigned long dump_start, dump_size;
13264 struct user32 dump;
13265
13266+ memset(&dump, 0, sizeof(dump));
13267+
13268 fs = get_fs();
13269 set_fs(KERNEL_DS);
13270 has_dumped = 1;
13271diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
13272index 665a730..8e7a67a 100644
13273--- a/arch/x86/ia32/ia32_signal.c
13274+++ b/arch/x86/ia32/ia32_signal.c
13275@@ -338,7 +338,7 @@ static void __user *get_sigframe(struct ksignal *ksig, struct pt_regs *regs,
13276 sp -= frame_size;
13277 /* Align the stack pointer according to the i386 ABI,
13278 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
13279- sp = ((sp + 4) & -16ul) - 4;
13280+ sp = ((sp - 12) & -16ul) - 4;
13281 return (void __user *) sp;
13282 }
13283
13284@@ -396,7 +396,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
13285 * These are actually not used anymore, but left because some
13286 * gdb versions depend on them as a marker.
13287 */
13288- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
13289+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
13290 } put_user_catch(err);
13291
13292 if (err)
13293@@ -438,7 +438,7 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
13294 0xb8,
13295 __NR_ia32_rt_sigreturn,
13296 0x80cd,
13297- 0,
13298+ 0
13299 };
13300
13301 frame = get_sigframe(ksig, regs, sizeof(*frame), &fpstate);
13302@@ -461,16 +461,18 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
13303
13304 if (ksig->ka.sa.sa_flags & SA_RESTORER)
13305 restorer = ksig->ka.sa.sa_restorer;
13306+ else if (current->mm->context.vdso)
13307+ /* Return stub is in 32bit vsyscall page */
13308+ restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
13309 else
13310- restorer = VDSO32_SYMBOL(current->mm->context.vdso,
13311- rt_sigreturn);
13312+ restorer = &frame->retcode;
13313 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
13314
13315 /*
13316 * Not actually used anymore, but left because some gdb
13317 * versions need it.
13318 */
13319- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
13320+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
13321 } put_user_catch(err);
13322
13323 err |= copy_siginfo_to_user32(&frame->info, &ksig->info);
13324diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
13325index 4299eb0..904b82a 100644
13326--- a/arch/x86/ia32/ia32entry.S
13327+++ b/arch/x86/ia32/ia32entry.S
13328@@ -15,8 +15,10 @@
13329 #include <asm/irqflags.h>
13330 #include <asm/asm.h>
13331 #include <asm/smap.h>
13332+#include <asm/pgtable.h>
13333 #include <linux/linkage.h>
13334 #include <linux/err.h>
13335+#include <asm/alternative-asm.h>
13336
13337 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
13338 #include <linux/elf-em.h>
13339@@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
13340 ENDPROC(native_irq_enable_sysexit)
13341 #endif
13342
13343+ .macro pax_enter_kernel_user
13344+ pax_set_fptr_mask
13345+#ifdef CONFIG_PAX_MEMORY_UDEREF
13346+ call pax_enter_kernel_user
13347+#endif
13348+ .endm
13349+
13350+ .macro pax_exit_kernel_user
13351+#ifdef CONFIG_PAX_MEMORY_UDEREF
13352+ call pax_exit_kernel_user
13353+#endif
13354+#ifdef CONFIG_PAX_RANDKSTACK
13355+ pushq %rax
13356+ pushq %r11
13357+ call pax_randomize_kstack
13358+ popq %r11
13359+ popq %rax
13360+#endif
13361+ .endm
13362+
13363+ .macro pax_erase_kstack
13364+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
13365+ call pax_erase_kstack
13366+#endif
13367+ .endm
13368+
13369 /*
13370 * 32bit SYSENTER instruction entry.
13371 *
13372@@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
13373 CFI_REGISTER rsp,rbp
13374 SWAPGS_UNSAFE_STACK
13375 movq PER_CPU_VAR(kernel_stack), %rsp
13376- addq $(KERNEL_STACK_OFFSET),%rsp
13377- /*
13378- * No need to follow this irqs on/off section: the syscall
13379- * disabled irqs, here we enable it straight after entry:
13380- */
13381- ENABLE_INTERRUPTS(CLBR_NONE)
13382 movl %ebp,%ebp /* zero extension */
13383 pushq_cfi $__USER32_DS
13384 /*CFI_REL_OFFSET ss,0*/
13385@@ -135,24 +157,49 @@ ENTRY(ia32_sysenter_target)
13386 CFI_REL_OFFSET rsp,0
13387 pushfq_cfi
13388 /*CFI_REL_OFFSET rflags,0*/
13389- movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
13390- CFI_REGISTER rip,r10
13391+ orl $X86_EFLAGS_IF,(%rsp)
13392+ GET_THREAD_INFO(%r11)
13393+ movl TI_sysenter_return(%r11), %r11d
13394+ CFI_REGISTER rip,r11
13395 pushq_cfi $__USER32_CS
13396 /*CFI_REL_OFFSET cs,0*/
13397 movl %eax, %eax
13398- pushq_cfi %r10
13399+ pushq_cfi %r11
13400 CFI_REL_OFFSET rip,0
13401 pushq_cfi %rax
13402 cld
13403 SAVE_ARGS 0,1,0
13404+ pax_enter_kernel_user
13405+
13406+#ifdef CONFIG_PAX_RANDKSTACK
13407+ pax_erase_kstack
13408+#endif
13409+
13410+ /*
13411+ * No need to follow this irqs on/off section: the syscall
13412+ * disabled irqs, here we enable it straight after entry:
13413+ */
13414+ ENABLE_INTERRUPTS(CLBR_NONE)
13415 /* no need to do an access_ok check here because rbp has been
13416 32bit zero extended */
13417+
13418+#ifdef CONFIG_PAX_MEMORY_UDEREF
13419+ addq pax_user_shadow_base,%rbp
13420+ ASM_PAX_OPEN_USERLAND
13421+#endif
13422+
13423 ASM_STAC
13424 1: movl (%rbp),%ebp
13425 _ASM_EXTABLE(1b,ia32_badarg)
13426 ASM_CLAC
13427- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13428- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13429+
13430+#ifdef CONFIG_PAX_MEMORY_UDEREF
13431+ ASM_PAX_CLOSE_USERLAND
13432+#endif
13433+
13434+ GET_THREAD_INFO(%r11)
13435+ orl $TS_COMPAT,TI_status(%r11)
13436+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
13437 CFI_REMEMBER_STATE
13438 jnz sysenter_tracesys
13439 cmpq $(IA32_NR_syscalls-1),%rax
13440@@ -162,12 +209,15 @@ sysenter_do_call:
13441 sysenter_dispatch:
13442 call *ia32_sys_call_table(,%rax,8)
13443 movq %rax,RAX-ARGOFFSET(%rsp)
13444+ GET_THREAD_INFO(%r11)
13445 DISABLE_INTERRUPTS(CLBR_NONE)
13446 TRACE_IRQS_OFF
13447- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13448+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
13449 jnz sysexit_audit
13450 sysexit_from_sys_call:
13451- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13452+ pax_exit_kernel_user
13453+ pax_erase_kstack
13454+ andl $~TS_COMPAT,TI_status(%r11)
13455 /* clear IF, that popfq doesn't enable interrupts early */
13456 andl $~0x200,EFLAGS-R11(%rsp)
13457 movl RIP-R11(%rsp),%edx /* User %eip */
13458@@ -193,6 +243,9 @@ sysexit_from_sys_call:
13459 movl %eax,%esi /* 2nd arg: syscall number */
13460 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
13461 call __audit_syscall_entry
13462+
13463+ pax_erase_kstack
13464+
13465 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
13466 cmpq $(IA32_NR_syscalls-1),%rax
13467 ja ia32_badsys
13468@@ -204,7 +257,7 @@ sysexit_from_sys_call:
13469 .endm
13470
13471 .macro auditsys_exit exit
13472- testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13473+ testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
13474 jnz ia32_ret_from_sys_call
13475 TRACE_IRQS_ON
13476 ENABLE_INTERRUPTS(CLBR_NONE)
13477@@ -215,11 +268,12 @@ sysexit_from_sys_call:
13478 1: setbe %al /* 1 if error, 0 if not */
13479 movzbl %al,%edi /* zero-extend that into %edi */
13480 call __audit_syscall_exit
13481+ GET_THREAD_INFO(%r11)
13482 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
13483 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
13484 DISABLE_INTERRUPTS(CLBR_NONE)
13485 TRACE_IRQS_OFF
13486- testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13487+ testl %edi,TI_flags(%r11)
13488 jz \exit
13489 CLEAR_RREGS -ARGOFFSET
13490 jmp int_with_check
13491@@ -237,7 +291,7 @@ sysexit_audit:
13492
13493 sysenter_tracesys:
13494 #ifdef CONFIG_AUDITSYSCALL
13495- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13496+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
13497 jz sysenter_auditsys
13498 #endif
13499 SAVE_REST
13500@@ -249,6 +303,9 @@ sysenter_tracesys:
13501 RESTORE_REST
13502 cmpq $(IA32_NR_syscalls-1),%rax
13503 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
13504+
13505+ pax_erase_kstack
13506+
13507 jmp sysenter_do_call
13508 CFI_ENDPROC
13509 ENDPROC(ia32_sysenter_target)
13510@@ -276,19 +333,25 @@ ENDPROC(ia32_sysenter_target)
13511 ENTRY(ia32_cstar_target)
13512 CFI_STARTPROC32 simple
13513 CFI_SIGNAL_FRAME
13514- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
13515+ CFI_DEF_CFA rsp,0
13516 CFI_REGISTER rip,rcx
13517 /*CFI_REGISTER rflags,r11*/
13518 SWAPGS_UNSAFE_STACK
13519 movl %esp,%r8d
13520 CFI_REGISTER rsp,r8
13521 movq PER_CPU_VAR(kernel_stack),%rsp
13522+ SAVE_ARGS 8*6,0,0
13523+ pax_enter_kernel_user
13524+
13525+#ifdef CONFIG_PAX_RANDKSTACK
13526+ pax_erase_kstack
13527+#endif
13528+
13529 /*
13530 * No need to follow this irqs on/off section: the syscall
13531 * disabled irqs and here we enable it straight after entry:
13532 */
13533 ENABLE_INTERRUPTS(CLBR_NONE)
13534- SAVE_ARGS 8,0,0
13535 movl %eax,%eax /* zero extension */
13536 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
13537 movq %rcx,RIP-ARGOFFSET(%rsp)
13538@@ -304,12 +367,25 @@ ENTRY(ia32_cstar_target)
13539 /* no need to do an access_ok check here because r8 has been
13540 32bit zero extended */
13541 /* hardware stack frame is complete now */
13542+
13543+#ifdef CONFIG_PAX_MEMORY_UDEREF
13544+ ASM_PAX_OPEN_USERLAND
13545+ movq pax_user_shadow_base,%r8
13546+ addq RSP-ARGOFFSET(%rsp),%r8
13547+#endif
13548+
13549 ASM_STAC
13550 1: movl (%r8),%r9d
13551 _ASM_EXTABLE(1b,ia32_badarg)
13552 ASM_CLAC
13553- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13554- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13555+
13556+#ifdef CONFIG_PAX_MEMORY_UDEREF
13557+ ASM_PAX_CLOSE_USERLAND
13558+#endif
13559+
13560+ GET_THREAD_INFO(%r11)
13561+ orl $TS_COMPAT,TI_status(%r11)
13562+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
13563 CFI_REMEMBER_STATE
13564 jnz cstar_tracesys
13565 cmpq $IA32_NR_syscalls-1,%rax
13566@@ -319,12 +395,15 @@ cstar_do_call:
13567 cstar_dispatch:
13568 call *ia32_sys_call_table(,%rax,8)
13569 movq %rax,RAX-ARGOFFSET(%rsp)
13570+ GET_THREAD_INFO(%r11)
13571 DISABLE_INTERRUPTS(CLBR_NONE)
13572 TRACE_IRQS_OFF
13573- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13574+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
13575 jnz sysretl_audit
13576 sysretl_from_sys_call:
13577- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13578+ pax_exit_kernel_user
13579+ pax_erase_kstack
13580+ andl $~TS_COMPAT,TI_status(%r11)
13581 RESTORE_ARGS 0,-ARG_SKIP,0,0,0
13582 movl RIP-ARGOFFSET(%rsp),%ecx
13583 CFI_REGISTER rip,rcx
13584@@ -352,7 +431,7 @@ sysretl_audit:
13585
13586 cstar_tracesys:
13587 #ifdef CONFIG_AUDITSYSCALL
13588- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13589+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
13590 jz cstar_auditsys
13591 #endif
13592 xchgl %r9d,%ebp
13593@@ -366,11 +445,19 @@ cstar_tracesys:
13594 xchgl %ebp,%r9d
13595 cmpq $(IA32_NR_syscalls-1),%rax
13596 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
13597+
13598+ pax_erase_kstack
13599+
13600 jmp cstar_do_call
13601 END(ia32_cstar_target)
13602
13603 ia32_badarg:
13604 ASM_CLAC
13605+
13606+#ifdef CONFIG_PAX_MEMORY_UDEREF
13607+ ASM_PAX_CLOSE_USERLAND
13608+#endif
13609+
13610 movq $-EFAULT,%rax
13611 jmp ia32_sysret
13612 CFI_ENDPROC
13613@@ -407,19 +494,26 @@ ENTRY(ia32_syscall)
13614 CFI_REL_OFFSET rip,RIP-RIP
13615 PARAVIRT_ADJUST_EXCEPTION_FRAME
13616 SWAPGS
13617- /*
13618- * No need to follow this irqs on/off section: the syscall
13619- * disabled irqs and here we enable it straight after entry:
13620- */
13621- ENABLE_INTERRUPTS(CLBR_NONE)
13622 movl %eax,%eax
13623 pushq_cfi %rax
13624 cld
13625 /* note the registers are not zero extended to the sf.
13626 this could be a problem. */
13627 SAVE_ARGS 0,1,0
13628- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13629- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13630+ pax_enter_kernel_user
13631+
13632+#ifdef CONFIG_PAX_RANDKSTACK
13633+ pax_erase_kstack
13634+#endif
13635+
13636+ /*
13637+ * No need to follow this irqs on/off section: the syscall
13638+ * disabled irqs and here we enable it straight after entry:
13639+ */
13640+ ENABLE_INTERRUPTS(CLBR_NONE)
13641+ GET_THREAD_INFO(%r11)
13642+ orl $TS_COMPAT,TI_status(%r11)
13643+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
13644 jnz ia32_tracesys
13645 cmpq $(IA32_NR_syscalls-1),%rax
13646 ja ia32_badsys
13647@@ -442,6 +536,9 @@ ia32_tracesys:
13648 RESTORE_REST
13649 cmpq $(IA32_NR_syscalls-1),%rax
13650 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
13651+
13652+ pax_erase_kstack
13653+
13654 jmp ia32_do_call
13655 END(ia32_syscall)
13656
13657diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
13658index 8e0ceec..af13504 100644
13659--- a/arch/x86/ia32/sys_ia32.c
13660+++ b/arch/x86/ia32/sys_ia32.c
13661@@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
13662 */
13663 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
13664 {
13665- typeof(ubuf->st_uid) uid = 0;
13666- typeof(ubuf->st_gid) gid = 0;
13667+ typeof(((struct stat64 *)0)->st_uid) uid = 0;
13668+ typeof(((struct stat64 *)0)->st_gid) gid = 0;
13669 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
13670 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
13671 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
13672diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
13673index 372231c..a5aa1a1 100644
13674--- a/arch/x86/include/asm/alternative-asm.h
13675+++ b/arch/x86/include/asm/alternative-asm.h
13676@@ -18,6 +18,45 @@
13677 .endm
13678 #endif
13679
13680+#ifdef KERNEXEC_PLUGIN
13681+ .macro pax_force_retaddr_bts rip=0
13682+ btsq $63,\rip(%rsp)
13683+ .endm
13684+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
13685+ .macro pax_force_retaddr rip=0, reload=0
13686+ btsq $63,\rip(%rsp)
13687+ .endm
13688+ .macro pax_force_fptr ptr
13689+ btsq $63,\ptr
13690+ .endm
13691+ .macro pax_set_fptr_mask
13692+ .endm
13693+#endif
13694+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
13695+ .macro pax_force_retaddr rip=0, reload=0
13696+ .if \reload
13697+ pax_set_fptr_mask
13698+ .endif
13699+ orq %r10,\rip(%rsp)
13700+ .endm
13701+ .macro pax_force_fptr ptr
13702+ orq %r10,\ptr
13703+ .endm
13704+ .macro pax_set_fptr_mask
13705+ movabs $0x8000000000000000,%r10
13706+ .endm
13707+#endif
13708+#else
13709+ .macro pax_force_retaddr rip=0, reload=0
13710+ .endm
13711+ .macro pax_force_fptr ptr
13712+ .endm
13713+ .macro pax_force_retaddr_bts rip=0
13714+ .endm
13715+ .macro pax_set_fptr_mask
13716+ .endm
13717+#endif
13718+
13719 .macro altinstruction_entry orig alt feature orig_len alt_len
13720 .long \orig - .
13721 .long \alt - .
13722diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
13723index 0a3f9c9..c9d081d 100644
13724--- a/arch/x86/include/asm/alternative.h
13725+++ b/arch/x86/include/asm/alternative.h
13726@@ -106,7 +106,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
13727 ".pushsection .discard,\"aw\",@progbits\n" \
13728 DISCARD_ENTRY(1) \
13729 ".popsection\n" \
13730- ".pushsection .altinstr_replacement, \"ax\"\n" \
13731+ ".pushsection .altinstr_replacement, \"a\"\n" \
13732 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
13733 ".popsection"
13734
13735@@ -120,7 +120,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
13736 DISCARD_ENTRY(1) \
13737 DISCARD_ENTRY(2) \
13738 ".popsection\n" \
13739- ".pushsection .altinstr_replacement, \"ax\"\n" \
13740+ ".pushsection .altinstr_replacement, \"a\"\n" \
13741 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
13742 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
13743 ".popsection"
13744diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
13745index 1d2091a..f5074c1 100644
13746--- a/arch/x86/include/asm/apic.h
13747+++ b/arch/x86/include/asm/apic.h
13748@@ -45,7 +45,7 @@ static inline void generic_apic_probe(void)
13749
13750 #ifdef CONFIG_X86_LOCAL_APIC
13751
13752-extern unsigned int apic_verbosity;
13753+extern int apic_verbosity;
13754 extern int local_apic_timer_c2_ok;
13755
13756 extern int disable_apic;
13757diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
13758index 20370c6..a2eb9b0 100644
13759--- a/arch/x86/include/asm/apm.h
13760+++ b/arch/x86/include/asm/apm.h
13761@@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
13762 __asm__ __volatile__(APM_DO_ZERO_SEGS
13763 "pushl %%edi\n\t"
13764 "pushl %%ebp\n\t"
13765- "lcall *%%cs:apm_bios_entry\n\t"
13766+ "lcall *%%ss:apm_bios_entry\n\t"
13767 "setc %%al\n\t"
13768 "popl %%ebp\n\t"
13769 "popl %%edi\n\t"
13770@@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
13771 __asm__ __volatile__(APM_DO_ZERO_SEGS
13772 "pushl %%edi\n\t"
13773 "pushl %%ebp\n\t"
13774- "lcall *%%cs:apm_bios_entry\n\t"
13775+ "lcall *%%ss:apm_bios_entry\n\t"
13776 "setc %%bl\n\t"
13777 "popl %%ebp\n\t"
13778 "popl %%edi\n\t"
13779diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
13780index 722aa3b..3a0bb27 100644
13781--- a/arch/x86/include/asm/atomic.h
13782+++ b/arch/x86/include/asm/atomic.h
13783@@ -22,7 +22,18 @@
13784 */
13785 static inline int atomic_read(const atomic_t *v)
13786 {
13787- return (*(volatile int *)&(v)->counter);
13788+ return (*(volatile const int *)&(v)->counter);
13789+}
13790+
13791+/**
13792+ * atomic_read_unchecked - read atomic variable
13793+ * @v: pointer of type atomic_unchecked_t
13794+ *
13795+ * Atomically reads the value of @v.
13796+ */
13797+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
13798+{
13799+ return (*(volatile const int *)&(v)->counter);
13800 }
13801
13802 /**
13803@@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *v, int i)
13804 }
13805
13806 /**
13807+ * atomic_set_unchecked - set atomic variable
13808+ * @v: pointer of type atomic_unchecked_t
13809+ * @i: required value
13810+ *
13811+ * Atomically sets the value of @v to @i.
13812+ */
13813+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
13814+{
13815+ v->counter = i;
13816+}
13817+
13818+/**
13819 * atomic_add - add integer to atomic variable
13820 * @i: integer value to add
13821 * @v: pointer of type atomic_t
13822@@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *v, int i)
13823 */
13824 static inline void atomic_add(int i, atomic_t *v)
13825 {
13826- asm volatile(LOCK_PREFIX "addl %1,%0"
13827+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
13828+
13829+#ifdef CONFIG_PAX_REFCOUNT
13830+ "jno 0f\n"
13831+ LOCK_PREFIX "subl %1,%0\n"
13832+ "int $4\n0:\n"
13833+ _ASM_EXTABLE(0b, 0b)
13834+#endif
13835+
13836+ : "+m" (v->counter)
13837+ : "ir" (i));
13838+}
13839+
13840+/**
13841+ * atomic_add_unchecked - add integer to atomic variable
13842+ * @i: integer value to add
13843+ * @v: pointer of type atomic_unchecked_t
13844+ *
13845+ * Atomically adds @i to @v.
13846+ */
13847+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
13848+{
13849+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
13850 : "+m" (v->counter)
13851 : "ir" (i));
13852 }
13853@@ -60,7 +105,29 @@ static inline void atomic_add(int i, atomic_t *v)
13854 */
13855 static inline void atomic_sub(int i, atomic_t *v)
13856 {
13857- asm volatile(LOCK_PREFIX "subl %1,%0"
13858+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
13859+
13860+#ifdef CONFIG_PAX_REFCOUNT
13861+ "jno 0f\n"
13862+ LOCK_PREFIX "addl %1,%0\n"
13863+ "int $4\n0:\n"
13864+ _ASM_EXTABLE(0b, 0b)
13865+#endif
13866+
13867+ : "+m" (v->counter)
13868+ : "ir" (i));
13869+}
13870+
13871+/**
13872+ * atomic_sub_unchecked - subtract integer from atomic variable
13873+ * @i: integer value to subtract
13874+ * @v: pointer of type atomic_unchecked_t
13875+ *
13876+ * Atomically subtracts @i from @v.
13877+ */
13878+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
13879+{
13880+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
13881 : "+m" (v->counter)
13882 : "ir" (i));
13883 }
13884@@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
13885 {
13886 unsigned char c;
13887
13888- asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
13889+ asm volatile(LOCK_PREFIX "subl %2,%0\n"
13890+
13891+#ifdef CONFIG_PAX_REFCOUNT
13892+ "jno 0f\n"
13893+ LOCK_PREFIX "addl %2,%0\n"
13894+ "int $4\n0:\n"
13895+ _ASM_EXTABLE(0b, 0b)
13896+#endif
13897+
13898+ "sete %1\n"
13899 : "+m" (v->counter), "=qm" (c)
13900 : "ir" (i) : "memory");
13901 return c;
13902@@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
13903 */
13904 static inline void atomic_inc(atomic_t *v)
13905 {
13906- asm volatile(LOCK_PREFIX "incl %0"
13907+ asm volatile(LOCK_PREFIX "incl %0\n"
13908+
13909+#ifdef CONFIG_PAX_REFCOUNT
13910+ "jno 0f\n"
13911+ LOCK_PREFIX "decl %0\n"
13912+ "int $4\n0:\n"
13913+ _ASM_EXTABLE(0b, 0b)
13914+#endif
13915+
13916+ : "+m" (v->counter));
13917+}
13918+
13919+/**
13920+ * atomic_inc_unchecked - increment atomic variable
13921+ * @v: pointer of type atomic_unchecked_t
13922+ *
13923+ * Atomically increments @v by 1.
13924+ */
13925+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
13926+{
13927+ asm volatile(LOCK_PREFIX "incl %0\n"
13928 : "+m" (v->counter));
13929 }
13930
13931@@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *v)
13932 */
13933 static inline void atomic_dec(atomic_t *v)
13934 {
13935- asm volatile(LOCK_PREFIX "decl %0"
13936+ asm volatile(LOCK_PREFIX "decl %0\n"
13937+
13938+#ifdef CONFIG_PAX_REFCOUNT
13939+ "jno 0f\n"
13940+ LOCK_PREFIX "incl %0\n"
13941+ "int $4\n0:\n"
13942+ _ASM_EXTABLE(0b, 0b)
13943+#endif
13944+
13945+ : "+m" (v->counter));
13946+}
13947+
13948+/**
13949+ * atomic_dec_unchecked - decrement atomic variable
13950+ * @v: pointer of type atomic_unchecked_t
13951+ *
13952+ * Atomically decrements @v by 1.
13953+ */
13954+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
13955+{
13956+ asm volatile(LOCK_PREFIX "decl %0\n"
13957 : "+m" (v->counter));
13958 }
13959
13960@@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
13961 {
13962 unsigned char c;
13963
13964- asm volatile(LOCK_PREFIX "decl %0; sete %1"
13965+ asm volatile(LOCK_PREFIX "decl %0\n"
13966+
13967+#ifdef CONFIG_PAX_REFCOUNT
13968+ "jno 0f\n"
13969+ LOCK_PREFIX "incl %0\n"
13970+ "int $4\n0:\n"
13971+ _ASM_EXTABLE(0b, 0b)
13972+#endif
13973+
13974+ "sete %1\n"
13975 : "+m" (v->counter), "=qm" (c)
13976 : : "memory");
13977 return c != 0;
13978@@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
13979 {
13980 unsigned char c;
13981
13982- asm volatile(LOCK_PREFIX "incl %0; sete %1"
13983+ asm volatile(LOCK_PREFIX "incl %0\n"
13984+
13985+#ifdef CONFIG_PAX_REFCOUNT
13986+ "jno 0f\n"
13987+ LOCK_PREFIX "decl %0\n"
13988+ "int $4\n0:\n"
13989+ _ASM_EXTABLE(0b, 0b)
13990+#endif
13991+
13992+ "sete %1\n"
13993+ : "+m" (v->counter), "=qm" (c)
13994+ : : "memory");
13995+ return c != 0;
13996+}
13997+
13998+/**
13999+ * atomic_inc_and_test_unchecked - increment and test
14000+ * @v: pointer of type atomic_unchecked_t
14001+ *
14002+ * Atomically increments @v by 1
14003+ * and returns true if the result is zero, or false for all
14004+ * other cases.
14005+ */
14006+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
14007+{
14008+ unsigned char c;
14009+
14010+ asm volatile(LOCK_PREFIX "incl %0\n"
14011+ "sete %1\n"
14012 : "+m" (v->counter), "=qm" (c)
14013 : : "memory");
14014 return c != 0;
14015@@ -157,7 +310,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
14016 {
14017 unsigned char c;
14018
14019- asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
14020+ asm volatile(LOCK_PREFIX "addl %2,%0\n"
14021+
14022+#ifdef CONFIG_PAX_REFCOUNT
14023+ "jno 0f\n"
14024+ LOCK_PREFIX "subl %2,%0\n"
14025+ "int $4\n0:\n"
14026+ _ASM_EXTABLE(0b, 0b)
14027+#endif
14028+
14029+ "sets %1\n"
14030 : "+m" (v->counter), "=qm" (c)
14031 : "ir" (i) : "memory");
14032 return c;
14033@@ -172,6 +334,18 @@ static inline int atomic_add_negative(int i, atomic_t *v)
14034 */
14035 static inline int atomic_add_return(int i, atomic_t *v)
14036 {
14037+ return i + xadd_check_overflow(&v->counter, i);
14038+}
14039+
14040+/**
14041+ * atomic_add_return_unchecked - add integer and return
14042+ * @i: integer value to add
14043+ * @v: pointer of type atomic_unchecked_t
14044+ *
14045+ * Atomically adds @i to @v and returns @i + @v
14046+ */
14047+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
14048+{
14049 return i + xadd(&v->counter, i);
14050 }
14051
14052@@ -188,6 +362,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
14053 }
14054
14055 #define atomic_inc_return(v) (atomic_add_return(1, v))
14056+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
14057+{
14058+ return atomic_add_return_unchecked(1, v);
14059+}
14060 #define atomic_dec_return(v) (atomic_sub_return(1, v))
14061
14062 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
14063@@ -195,11 +373,21 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
14064 return cmpxchg(&v->counter, old, new);
14065 }
14066
14067+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
14068+{
14069+ return cmpxchg(&v->counter, old, new);
14070+}
14071+
14072 static inline int atomic_xchg(atomic_t *v, int new)
14073 {
14074 return xchg(&v->counter, new);
14075 }
14076
14077+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
14078+{
14079+ return xchg(&v->counter, new);
14080+}
14081+
14082 /**
14083 * __atomic_add_unless - add unless the number is already a given value
14084 * @v: pointer of type atomic_t
14085@@ -211,12 +399,25 @@ static inline int atomic_xchg(atomic_t *v, int new)
14086 */
14087 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
14088 {
14089- int c, old;
14090+ int c, old, new;
14091 c = atomic_read(v);
14092 for (;;) {
14093- if (unlikely(c == (u)))
14094+ if (unlikely(c == u))
14095 break;
14096- old = atomic_cmpxchg((v), c, c + (a));
14097+
14098+ asm volatile("addl %2,%0\n"
14099+
14100+#ifdef CONFIG_PAX_REFCOUNT
14101+ "jno 0f\n"
14102+ "subl %2,%0\n"
14103+ "int $4\n0:\n"
14104+ _ASM_EXTABLE(0b, 0b)
14105+#endif
14106+
14107+ : "=r" (new)
14108+ : "0" (c), "ir" (a));
14109+
14110+ old = atomic_cmpxchg(v, c, new);
14111 if (likely(old == c))
14112 break;
14113 c = old;
14114@@ -225,6 +426,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
14115 }
14116
14117 /**
14118+ * atomic_inc_not_zero_hint - increment if not null
14119+ * @v: pointer of type atomic_t
14120+ * @hint: probable value of the atomic before the increment
14121+ *
14122+ * This version of atomic_inc_not_zero() gives a hint of probable
14123+ * value of the atomic. This helps processor to not read the memory
14124+ * before doing the atomic read/modify/write cycle, lowering
14125+ * number of bus transactions on some arches.
14126+ *
14127+ * Returns: 0 if increment was not done, 1 otherwise.
14128+ */
14129+#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
14130+static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
14131+{
14132+ int val, c = hint, new;
14133+
14134+ /* sanity test, should be removed by compiler if hint is a constant */
14135+ if (!hint)
14136+ return __atomic_add_unless(v, 1, 0);
14137+
14138+ do {
14139+ asm volatile("incl %0\n"
14140+
14141+#ifdef CONFIG_PAX_REFCOUNT
14142+ "jno 0f\n"
14143+ "decl %0\n"
14144+ "int $4\n0:\n"
14145+ _ASM_EXTABLE(0b, 0b)
14146+#endif
14147+
14148+ : "=r" (new)
14149+ : "0" (c));
14150+
14151+ val = atomic_cmpxchg(v, c, new);
14152+ if (val == c)
14153+ return 1;
14154+ c = val;
14155+ } while (c);
14156+
14157+ return 0;
14158+}
14159+
14160+/**
14161 * atomic_inc_short - increment of a short integer
14162 * @v: pointer to type int
14163 *
14164@@ -253,14 +497,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
14165 #endif
14166
14167 /* These are x86-specific, used by some header files */
14168-#define atomic_clear_mask(mask, addr) \
14169- asm volatile(LOCK_PREFIX "andl %0,%1" \
14170- : : "r" (~(mask)), "m" (*(addr)) : "memory")
14171+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
14172+{
14173+ asm volatile(LOCK_PREFIX "andl %1,%0"
14174+ : "+m" (v->counter)
14175+ : "r" (~(mask))
14176+ : "memory");
14177+}
14178
14179-#define atomic_set_mask(mask, addr) \
14180- asm volatile(LOCK_PREFIX "orl %0,%1" \
14181- : : "r" ((unsigned)(mask)), "m" (*(addr)) \
14182- : "memory")
14183+static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
14184+{
14185+ asm volatile(LOCK_PREFIX "andl %1,%0"
14186+ : "+m" (v->counter)
14187+ : "r" (~(mask))
14188+ : "memory");
14189+}
14190+
14191+static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
14192+{
14193+ asm volatile(LOCK_PREFIX "orl %1,%0"
14194+ : "+m" (v->counter)
14195+ : "r" (mask)
14196+ : "memory");
14197+}
14198+
14199+static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
14200+{
14201+ asm volatile(LOCK_PREFIX "orl %1,%0"
14202+ : "+m" (v->counter)
14203+ : "r" (mask)
14204+ : "memory");
14205+}
14206
14207 /* Atomic operations are already serializing on x86 */
14208 #define smp_mb__before_atomic_dec() barrier()
14209diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
14210index b154de7..aadebd8 100644
14211--- a/arch/x86/include/asm/atomic64_32.h
14212+++ b/arch/x86/include/asm/atomic64_32.h
14213@@ -12,6 +12,14 @@ typedef struct {
14214 u64 __aligned(8) counter;
14215 } atomic64_t;
14216
14217+#ifdef CONFIG_PAX_REFCOUNT
14218+typedef struct {
14219+ u64 __aligned(8) counter;
14220+} atomic64_unchecked_t;
14221+#else
14222+typedef atomic64_t atomic64_unchecked_t;
14223+#endif
14224+
14225 #define ATOMIC64_INIT(val) { (val) }
14226
14227 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
14228@@ -37,21 +45,31 @@ typedef struct {
14229 ATOMIC64_DECL_ONE(sym##_386)
14230
14231 ATOMIC64_DECL_ONE(add_386);
14232+ATOMIC64_DECL_ONE(add_unchecked_386);
14233 ATOMIC64_DECL_ONE(sub_386);
14234+ATOMIC64_DECL_ONE(sub_unchecked_386);
14235 ATOMIC64_DECL_ONE(inc_386);
14236+ATOMIC64_DECL_ONE(inc_unchecked_386);
14237 ATOMIC64_DECL_ONE(dec_386);
14238+ATOMIC64_DECL_ONE(dec_unchecked_386);
14239 #endif
14240
14241 #define alternative_atomic64(f, out, in...) \
14242 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
14243
14244 ATOMIC64_DECL(read);
14245+ATOMIC64_DECL(read_unchecked);
14246 ATOMIC64_DECL(set);
14247+ATOMIC64_DECL(set_unchecked);
14248 ATOMIC64_DECL(xchg);
14249 ATOMIC64_DECL(add_return);
14250+ATOMIC64_DECL(add_return_unchecked);
14251 ATOMIC64_DECL(sub_return);
14252+ATOMIC64_DECL(sub_return_unchecked);
14253 ATOMIC64_DECL(inc_return);
14254+ATOMIC64_DECL(inc_return_unchecked);
14255 ATOMIC64_DECL(dec_return);
14256+ATOMIC64_DECL(dec_return_unchecked);
14257 ATOMIC64_DECL(dec_if_positive);
14258 ATOMIC64_DECL(inc_not_zero);
14259 ATOMIC64_DECL(add_unless);
14260@@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
14261 }
14262
14263 /**
14264+ * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
14265+ * @p: pointer to type atomic64_unchecked_t
14266+ * @o: expected value
14267+ * @n: new value
14268+ *
14269+ * Atomically sets @v to @n if it was equal to @o and returns
14270+ * the old value.
14271+ */
14272+
14273+static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
14274+{
14275+ return cmpxchg64(&v->counter, o, n);
14276+}
14277+
14278+/**
14279 * atomic64_xchg - xchg atomic64 variable
14280 * @v: pointer to type atomic64_t
14281 * @n: value to assign
14282@@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
14283 }
14284
14285 /**
14286+ * atomic64_set_unchecked - set atomic64 variable
14287+ * @v: pointer to type atomic64_unchecked_t
14288+ * @n: value to assign
14289+ *
14290+ * Atomically sets the value of @v to @n.
14291+ */
14292+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
14293+{
14294+ unsigned high = (unsigned)(i >> 32);
14295+ unsigned low = (unsigned)i;
14296+ alternative_atomic64(set, /* no output */,
14297+ "S" (v), "b" (low), "c" (high)
14298+ : "eax", "edx", "memory");
14299+}
14300+
14301+/**
14302 * atomic64_read - read atomic64 variable
14303 * @v: pointer to type atomic64_t
14304 *
14305@@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
14306 }
14307
14308 /**
14309+ * atomic64_read_unchecked - read atomic64 variable
14310+ * @v: pointer to type atomic64_unchecked_t
14311+ *
14312+ * Atomically reads the value of @v and returns it.
14313+ */
14314+static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
14315+{
14316+ long long r;
14317+ alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
14318+ return r;
14319+ }
14320+
14321+/**
14322 * atomic64_add_return - add and return
14323 * @i: integer value to add
14324 * @v: pointer to type atomic64_t
14325@@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
14326 return i;
14327 }
14328
14329+/**
14330+ * atomic64_add_return_unchecked - add and return
14331+ * @i: integer value to add
14332+ * @v: pointer to type atomic64_unchecked_t
14333+ *
14334+ * Atomically adds @i to @v and returns @i + *@v
14335+ */
14336+static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
14337+{
14338+ alternative_atomic64(add_return_unchecked,
14339+ ASM_OUTPUT2("+A" (i), "+c" (v)),
14340+ ASM_NO_INPUT_CLOBBER("memory"));
14341+ return i;
14342+}
14343+
14344 /*
14345 * Other variants with different arithmetic operators:
14346 */
14347@@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
14348 return a;
14349 }
14350
14351+static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
14352+{
14353+ long long a;
14354+ alternative_atomic64(inc_return_unchecked, "=&A" (a),
14355+ "S" (v) : "memory", "ecx");
14356+ return a;
14357+}
14358+
14359 static inline long long atomic64_dec_return(atomic64_t *v)
14360 {
14361 long long a;
14362@@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
14363 }
14364
14365 /**
14366+ * atomic64_add_unchecked - add integer to atomic64 variable
14367+ * @i: integer value to add
14368+ * @v: pointer to type atomic64_unchecked_t
14369+ *
14370+ * Atomically adds @i to @v.
14371+ */
14372+static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
14373+{
14374+ __alternative_atomic64(add_unchecked, add_return_unchecked,
14375+ ASM_OUTPUT2("+A" (i), "+c" (v)),
14376+ ASM_NO_INPUT_CLOBBER("memory"));
14377+ return i;
14378+}
14379+
14380+/**
14381 * atomic64_sub - subtract the atomic64 variable
14382 * @i: integer value to subtract
14383 * @v: pointer to type atomic64_t
14384diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
14385index 0e1cbfc..5623683 100644
14386--- a/arch/x86/include/asm/atomic64_64.h
14387+++ b/arch/x86/include/asm/atomic64_64.h
14388@@ -18,7 +18,19 @@
14389 */
14390 static inline long atomic64_read(const atomic64_t *v)
14391 {
14392- return (*(volatile long *)&(v)->counter);
14393+ return (*(volatile const long *)&(v)->counter);
14394+}
14395+
14396+/**
14397+ * atomic64_read_unchecked - read atomic64 variable
14398+ * @v: pointer of type atomic64_unchecked_t
14399+ *
14400+ * Atomically reads the value of @v.
14401+ * Doesn't imply a read memory barrier.
14402+ */
14403+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
14404+{
14405+ return (*(volatile const long *)&(v)->counter);
14406 }
14407
14408 /**
14409@@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
14410 }
14411
14412 /**
14413+ * atomic64_set_unchecked - set atomic64 variable
14414+ * @v: pointer to type atomic64_unchecked_t
14415+ * @i: required value
14416+ *
14417+ * Atomically sets the value of @v to @i.
14418+ */
14419+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
14420+{
14421+ v->counter = i;
14422+}
14423+
14424+/**
14425 * atomic64_add - add integer to atomic64 variable
14426 * @i: integer value to add
14427 * @v: pointer to type atomic64_t
14428@@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
14429 */
14430 static inline void atomic64_add(long i, atomic64_t *v)
14431 {
14432+ asm volatile(LOCK_PREFIX "addq %1,%0\n"
14433+
14434+#ifdef CONFIG_PAX_REFCOUNT
14435+ "jno 0f\n"
14436+ LOCK_PREFIX "subq %1,%0\n"
14437+ "int $4\n0:\n"
14438+ _ASM_EXTABLE(0b, 0b)
14439+#endif
14440+
14441+ : "=m" (v->counter)
14442+ : "er" (i), "m" (v->counter));
14443+}
14444+
14445+/**
14446+ * atomic64_add_unchecked - add integer to atomic64 variable
14447+ * @i: integer value to add
14448+ * @v: pointer to type atomic64_unchecked_t
14449+ *
14450+ * Atomically adds @i to @v.
14451+ */
14452+static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
14453+{
14454 asm volatile(LOCK_PREFIX "addq %1,%0"
14455 : "=m" (v->counter)
14456 : "er" (i), "m" (v->counter));
14457@@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
14458 */
14459 static inline void atomic64_sub(long i, atomic64_t *v)
14460 {
14461- asm volatile(LOCK_PREFIX "subq %1,%0"
14462+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
14463+
14464+#ifdef CONFIG_PAX_REFCOUNT
14465+ "jno 0f\n"
14466+ LOCK_PREFIX "addq %1,%0\n"
14467+ "int $4\n0:\n"
14468+ _ASM_EXTABLE(0b, 0b)
14469+#endif
14470+
14471+ : "=m" (v->counter)
14472+ : "er" (i), "m" (v->counter));
14473+}
14474+
14475+/**
14476+ * atomic64_sub_unchecked - subtract the atomic64 variable
14477+ * @i: integer value to subtract
14478+ * @v: pointer to type atomic64_unchecked_t
14479+ *
14480+ * Atomically subtracts @i from @v.
14481+ */
14482+static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
14483+{
14484+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
14485 : "=m" (v->counter)
14486 : "er" (i), "m" (v->counter));
14487 }
14488@@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
14489 {
14490 unsigned char c;
14491
14492- asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
14493+ asm volatile(LOCK_PREFIX "subq %2,%0\n"
14494+
14495+#ifdef CONFIG_PAX_REFCOUNT
14496+ "jno 0f\n"
14497+ LOCK_PREFIX "addq %2,%0\n"
14498+ "int $4\n0:\n"
14499+ _ASM_EXTABLE(0b, 0b)
14500+#endif
14501+
14502+ "sete %1\n"
14503 : "=m" (v->counter), "=qm" (c)
14504 : "er" (i), "m" (v->counter) : "memory");
14505 return c;
14506@@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
14507 */
14508 static inline void atomic64_inc(atomic64_t *v)
14509 {
14510+ asm volatile(LOCK_PREFIX "incq %0\n"
14511+
14512+#ifdef CONFIG_PAX_REFCOUNT
14513+ "jno 0f\n"
14514+ LOCK_PREFIX "decq %0\n"
14515+ "int $4\n0:\n"
14516+ _ASM_EXTABLE(0b, 0b)
14517+#endif
14518+
14519+ : "=m" (v->counter)
14520+ : "m" (v->counter));
14521+}
14522+
14523+/**
14524+ * atomic64_inc_unchecked - increment atomic64 variable
14525+ * @v: pointer to type atomic64_unchecked_t
14526+ *
14527+ * Atomically increments @v by 1.
14528+ */
14529+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
14530+{
14531 asm volatile(LOCK_PREFIX "incq %0"
14532 : "=m" (v->counter)
14533 : "m" (v->counter));
14534@@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64_t *v)
14535 */
14536 static inline void atomic64_dec(atomic64_t *v)
14537 {
14538- asm volatile(LOCK_PREFIX "decq %0"
14539+ asm volatile(LOCK_PREFIX "decq %0\n"
14540+
14541+#ifdef CONFIG_PAX_REFCOUNT
14542+ "jno 0f\n"
14543+ LOCK_PREFIX "incq %0\n"
14544+ "int $4\n0:\n"
14545+ _ASM_EXTABLE(0b, 0b)
14546+#endif
14547+
14548+ : "=m" (v->counter)
14549+ : "m" (v->counter));
14550+}
14551+
14552+/**
14553+ * atomic64_dec_unchecked - decrement atomic64 variable
14554+ * @v: pointer to type atomic64_t
14555+ *
14556+ * Atomically decrements @v by 1.
14557+ */
14558+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
14559+{
14560+ asm volatile(LOCK_PREFIX "decq %0\n"
14561 : "=m" (v->counter)
14562 : "m" (v->counter));
14563 }
14564@@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
14565 {
14566 unsigned char c;
14567
14568- asm volatile(LOCK_PREFIX "decq %0; sete %1"
14569+ asm volatile(LOCK_PREFIX "decq %0\n"
14570+
14571+#ifdef CONFIG_PAX_REFCOUNT
14572+ "jno 0f\n"
14573+ LOCK_PREFIX "incq %0\n"
14574+ "int $4\n0:\n"
14575+ _ASM_EXTABLE(0b, 0b)
14576+#endif
14577+
14578+ "sete %1\n"
14579 : "=m" (v->counter), "=qm" (c)
14580 : "m" (v->counter) : "memory");
14581 return c != 0;
14582@@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
14583 {
14584 unsigned char c;
14585
14586- asm volatile(LOCK_PREFIX "incq %0; sete %1"
14587+ asm volatile(LOCK_PREFIX "incq %0\n"
14588+
14589+#ifdef CONFIG_PAX_REFCOUNT
14590+ "jno 0f\n"
14591+ LOCK_PREFIX "decq %0\n"
14592+ "int $4\n0:\n"
14593+ _ASM_EXTABLE(0b, 0b)
14594+#endif
14595+
14596+ "sete %1\n"
14597 : "=m" (v->counter), "=qm" (c)
14598 : "m" (v->counter) : "memory");
14599 return c != 0;
14600@@ -155,7 +292,16 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
14601 {
14602 unsigned char c;
14603
14604- asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
14605+ asm volatile(LOCK_PREFIX "addq %2,%0\n"
14606+
14607+#ifdef CONFIG_PAX_REFCOUNT
14608+ "jno 0f\n"
14609+ LOCK_PREFIX "subq %2,%0\n"
14610+ "int $4\n0:\n"
14611+ _ASM_EXTABLE(0b, 0b)
14612+#endif
14613+
14614+ "sets %1\n"
14615 : "=m" (v->counter), "=qm" (c)
14616 : "er" (i), "m" (v->counter) : "memory");
14617 return c;
14618@@ -170,6 +316,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
14619 */
14620 static inline long atomic64_add_return(long i, atomic64_t *v)
14621 {
14622+ return i + xadd_check_overflow(&v->counter, i);
14623+}
14624+
14625+/**
14626+ * atomic64_add_return_unchecked - add and return
14627+ * @i: integer value to add
14628+ * @v: pointer to type atomic64_unchecked_t
14629+ *
14630+ * Atomically adds @i to @v and returns @i + @v
14631+ */
14632+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
14633+{
14634 return i + xadd(&v->counter, i);
14635 }
14636
14637@@ -179,6 +337,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
14638 }
14639
14640 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
14641+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
14642+{
14643+ return atomic64_add_return_unchecked(1, v);
14644+}
14645 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
14646
14647 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
14648@@ -186,6 +348,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
14649 return cmpxchg(&v->counter, old, new);
14650 }
14651
14652+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
14653+{
14654+ return cmpxchg(&v->counter, old, new);
14655+}
14656+
14657 static inline long atomic64_xchg(atomic64_t *v, long new)
14658 {
14659 return xchg(&v->counter, new);
14660@@ -202,17 +369,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
14661 */
14662 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
14663 {
14664- long c, old;
14665+ long c, old, new;
14666 c = atomic64_read(v);
14667 for (;;) {
14668- if (unlikely(c == (u)))
14669+ if (unlikely(c == u))
14670 break;
14671- old = atomic64_cmpxchg((v), c, c + (a));
14672+
14673+ asm volatile("add %2,%0\n"
14674+
14675+#ifdef CONFIG_PAX_REFCOUNT
14676+ "jno 0f\n"
14677+ "sub %2,%0\n"
14678+ "int $4\n0:\n"
14679+ _ASM_EXTABLE(0b, 0b)
14680+#endif
14681+
14682+ : "=r" (new)
14683+ : "0" (c), "ir" (a));
14684+
14685+ old = atomic64_cmpxchg(v, c, new);
14686 if (likely(old == c))
14687 break;
14688 c = old;
14689 }
14690- return c != (u);
14691+ return c != u;
14692 }
14693
14694 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
14695diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
14696index 41639ce..0bd8c87 100644
14697--- a/arch/x86/include/asm/bitops.h
14698+++ b/arch/x86/include/asm/bitops.h
14699@@ -48,7 +48,7 @@
14700 * a mask operation on a byte.
14701 */
14702 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
14703-#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
14704+#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
14705 #define CONST_MASK(nr) (1 << ((nr) & 7))
14706
14707 /**
14708@@ -361,7 +361,7 @@ static int test_bit(int nr, const volatile unsigned long *addr);
14709 *
14710 * Undefined if no bit exists, so code should check against 0 first.
14711 */
14712-static inline unsigned long __ffs(unsigned long word)
14713+static inline unsigned long __intentional_overflow(-1) __ffs(unsigned long word)
14714 {
14715 asm("rep; bsf %1,%0"
14716 : "=r" (word)
14717@@ -375,7 +375,7 @@ static inline unsigned long __ffs(unsigned long word)
14718 *
14719 * Undefined if no zero exists, so code should check against ~0UL first.
14720 */
14721-static inline unsigned long ffz(unsigned long word)
14722+static inline unsigned long __intentional_overflow(-1) ffz(unsigned long word)
14723 {
14724 asm("rep; bsf %1,%0"
14725 : "=r" (word)
14726@@ -494,7 +494,7 @@ static inline int fls(int x)
14727 * at position 64.
14728 */
14729 #ifdef CONFIG_X86_64
14730-static __always_inline int fls64(__u64 x)
14731+static __always_inline long fls64(__u64 x)
14732 {
14733 int bitpos = -1;
14734 /*
14735diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
14736index 4fa687a..60f2d39 100644
14737--- a/arch/x86/include/asm/boot.h
14738+++ b/arch/x86/include/asm/boot.h
14739@@ -6,10 +6,15 @@
14740 #include <uapi/asm/boot.h>
14741
14742 /* Physical address where kernel should be loaded. */
14743-#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
14744+#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
14745 + (CONFIG_PHYSICAL_ALIGN - 1)) \
14746 & ~(CONFIG_PHYSICAL_ALIGN - 1))
14747
14748+#ifndef __ASSEMBLY__
14749+extern unsigned char __LOAD_PHYSICAL_ADDR[];
14750+#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
14751+#endif
14752+
14753 /* Minimum kernel alignment, as a power of two */
14754 #ifdef CONFIG_X86_64
14755 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
14756diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
14757index 48f99f1..d78ebf9 100644
14758--- a/arch/x86/include/asm/cache.h
14759+++ b/arch/x86/include/asm/cache.h
14760@@ -5,12 +5,13 @@
14761
14762 /* L1 cache line size */
14763 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
14764-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
14765+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
14766
14767 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
14768+#define __read_only __attribute__((__section__(".data..read_only")))
14769
14770 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
14771-#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
14772+#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
14773
14774 #ifdef CONFIG_X86_VSMP
14775 #ifdef CONFIG_SMP
14776diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
14777index 9863ee3..4a1f8e1 100644
14778--- a/arch/x86/include/asm/cacheflush.h
14779+++ b/arch/x86/include/asm/cacheflush.h
14780@@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
14781 unsigned long pg_flags = pg->flags & _PGMT_MASK;
14782
14783 if (pg_flags == _PGMT_DEFAULT)
14784- return -1;
14785+ return ~0UL;
14786 else if (pg_flags == _PGMT_WC)
14787 return _PAGE_CACHE_WC;
14788 else if (pg_flags == _PGMT_UC_MINUS)
14789diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
14790index f50de69..2b0a458 100644
14791--- a/arch/x86/include/asm/checksum_32.h
14792+++ b/arch/x86/include/asm/checksum_32.h
14793@@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
14794 int len, __wsum sum,
14795 int *src_err_ptr, int *dst_err_ptr);
14796
14797+asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
14798+ int len, __wsum sum,
14799+ int *src_err_ptr, int *dst_err_ptr);
14800+
14801+asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
14802+ int len, __wsum sum,
14803+ int *src_err_ptr, int *dst_err_ptr);
14804+
14805 /*
14806 * Note: when you get a NULL pointer exception here this means someone
14807 * passed in an incorrect kernel address to one of these functions.
14808@@ -53,7 +61,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
14809
14810 might_sleep();
14811 stac();
14812- ret = csum_partial_copy_generic((__force void *)src, dst,
14813+ ret = csum_partial_copy_generic_from_user((__force void *)src, dst,
14814 len, sum, err_ptr, NULL);
14815 clac();
14816
14817@@ -187,7 +195,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
14818 might_sleep();
14819 if (access_ok(VERIFY_WRITE, dst, len)) {
14820 stac();
14821- ret = csum_partial_copy_generic(src, (__force void *)dst,
14822+ ret = csum_partial_copy_generic_to_user(src, (__force void *)dst,
14823 len, sum, NULL, err_ptr);
14824 clac();
14825 return ret;
14826diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
14827index d47786a..ce1b05d 100644
14828--- a/arch/x86/include/asm/cmpxchg.h
14829+++ b/arch/x86/include/asm/cmpxchg.h
14830@@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
14831 __compiletime_error("Bad argument size for cmpxchg");
14832 extern void __xadd_wrong_size(void)
14833 __compiletime_error("Bad argument size for xadd");
14834+extern void __xadd_check_overflow_wrong_size(void)
14835+ __compiletime_error("Bad argument size for xadd_check_overflow");
14836 extern void __add_wrong_size(void)
14837 __compiletime_error("Bad argument size for add");
14838+extern void __add_check_overflow_wrong_size(void)
14839+ __compiletime_error("Bad argument size for add_check_overflow");
14840
14841 /*
14842 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
14843@@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
14844 __ret; \
14845 })
14846
14847+#define __xchg_op_check_overflow(ptr, arg, op, lock) \
14848+ ({ \
14849+ __typeof__ (*(ptr)) __ret = (arg); \
14850+ switch (sizeof(*(ptr))) { \
14851+ case __X86_CASE_L: \
14852+ asm volatile (lock #op "l %0, %1\n" \
14853+ "jno 0f\n" \
14854+ "mov %0,%1\n" \
14855+ "int $4\n0:\n" \
14856+ _ASM_EXTABLE(0b, 0b) \
14857+ : "+r" (__ret), "+m" (*(ptr)) \
14858+ : : "memory", "cc"); \
14859+ break; \
14860+ case __X86_CASE_Q: \
14861+ asm volatile (lock #op "q %q0, %1\n" \
14862+ "jno 0f\n" \
14863+ "mov %0,%1\n" \
14864+ "int $4\n0:\n" \
14865+ _ASM_EXTABLE(0b, 0b) \
14866+ : "+r" (__ret), "+m" (*(ptr)) \
14867+ : : "memory", "cc"); \
14868+ break; \
14869+ default: \
14870+ __ ## op ## _check_overflow_wrong_size(); \
14871+ } \
14872+ __ret; \
14873+ })
14874+
14875 /*
14876 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
14877 * Since this is generally used to protect other memory information, we
14878@@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
14879 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
14880 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
14881
14882+#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
14883+#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
14884+
14885 #define __add(ptr, inc, lock) \
14886 ({ \
14887 __typeof__ (*(ptr)) __ret = (inc); \
14888diff --git a/arch/x86/include/asm/compat.h b/arch/x86/include/asm/compat.h
14889index 59c6c40..5e0b22c 100644
14890--- a/arch/x86/include/asm/compat.h
14891+++ b/arch/x86/include/asm/compat.h
14892@@ -41,7 +41,7 @@ typedef s64 __attribute__((aligned(4))) compat_s64;
14893 typedef u32 compat_uint_t;
14894 typedef u32 compat_ulong_t;
14895 typedef u64 __attribute__((aligned(4))) compat_u64;
14896-typedef u32 compat_uptr_t;
14897+typedef u32 __user compat_uptr_t;
14898
14899 struct compat_timespec {
14900 compat_time_t tv_sec;
14901diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
14902index 89270b4..f0abf8e 100644
14903--- a/arch/x86/include/asm/cpufeature.h
14904+++ b/arch/x86/include/asm/cpufeature.h
14905@@ -203,7 +203,7 @@
14906 #define X86_FEATURE_DECODEASSISTS (8*32+12) /* AMD Decode Assists support */
14907 #define X86_FEATURE_PAUSEFILTER (8*32+13) /* AMD filtered pause intercept */
14908 #define X86_FEATURE_PFTHRESHOLD (8*32+14) /* AMD pause filter threshold */
14909-
14910+#define X86_FEATURE_STRONGUDEREF (8*32+31) /* PaX PCID based strong UDEREF */
14911
14912 /* Intel-defined CPU features, CPUID level 0x00000007:0 (ebx), word 9 */
14913 #define X86_FEATURE_FSGSBASE (9*32+ 0) /* {RD/WR}{FS/GS}BASE instructions*/
14914@@ -211,7 +211,7 @@
14915 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
14916 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
14917 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
14918-#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
14919+#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
14920 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
14921 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
14922 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
14923@@ -353,6 +353,7 @@ extern const char * const x86_power_flags[32];
14924 #undef cpu_has_centaur_mcr
14925 #define cpu_has_centaur_mcr 0
14926
14927+#define cpu_has_pcid boot_cpu_has(X86_FEATURE_PCID)
14928 #endif /* CONFIG_X86_64 */
14929
14930 #if __GNUC__ >= 4
14931@@ -405,7 +406,8 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
14932
14933 #ifdef CONFIG_X86_DEBUG_STATIC_CPU_HAS
14934 t_warn:
14935- warn_pre_alternatives();
14936+ if (bit != X86_FEATURE_PCID && bit != X86_FEATURE_INVPCID)
14937+ warn_pre_alternatives();
14938 return false;
14939 #endif
14940
14941@@ -425,7 +427,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
14942 ".section .discard,\"aw\",@progbits\n"
14943 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
14944 ".previous\n"
14945- ".section .altinstr_replacement,\"ax\"\n"
14946+ ".section .altinstr_replacement,\"a\"\n"
14947 "3: movb $1,%0\n"
14948 "4:\n"
14949 ".previous\n"
14950@@ -462,7 +464,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
14951 " .byte 2b - 1b\n" /* src len */
14952 " .byte 4f - 3f\n" /* repl len */
14953 ".previous\n"
14954- ".section .altinstr_replacement,\"ax\"\n"
14955+ ".section .altinstr_replacement,\"a\"\n"
14956 "3: .byte 0xe9\n .long %l[t_no] - 2b\n"
14957 "4:\n"
14958 ".previous\n"
14959@@ -495,7 +497,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
14960 ".section .discard,\"aw\",@progbits\n"
14961 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
14962 ".previous\n"
14963- ".section .altinstr_replacement,\"ax\"\n"
14964+ ".section .altinstr_replacement,\"a\"\n"
14965 "3: movb $0,%0\n"
14966 "4:\n"
14967 ".previous\n"
14968@@ -509,7 +511,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
14969 ".section .discard,\"aw\",@progbits\n"
14970 " .byte 0xff + (6f-5f) - (4b-3b)\n" /* size check */
14971 ".previous\n"
14972- ".section .altinstr_replacement,\"ax\"\n"
14973+ ".section .altinstr_replacement,\"a\"\n"
14974 "5: movb $1,%0\n"
14975 "6:\n"
14976 ".previous\n"
14977diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
14978index b90e5df..b462c91 100644
14979--- a/arch/x86/include/asm/desc.h
14980+++ b/arch/x86/include/asm/desc.h
14981@@ -4,6 +4,7 @@
14982 #include <asm/desc_defs.h>
14983 #include <asm/ldt.h>
14984 #include <asm/mmu.h>
14985+#include <asm/pgtable.h>
14986
14987 #include <linux/smp.h>
14988 #include <linux/percpu.h>
14989@@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
14990
14991 desc->type = (info->read_exec_only ^ 1) << 1;
14992 desc->type |= info->contents << 2;
14993+ desc->type |= info->seg_not_present ^ 1;
14994
14995 desc->s = 1;
14996 desc->dpl = 0x3;
14997@@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
14998 }
14999
15000 extern struct desc_ptr idt_descr;
15001-extern gate_desc idt_table[];
15002-extern struct desc_ptr debug_idt_descr;
15003-extern gate_desc debug_idt_table[];
15004-
15005-struct gdt_page {
15006- struct desc_struct gdt[GDT_ENTRIES];
15007-} __attribute__((aligned(PAGE_SIZE)));
15008-
15009-DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
15010+extern gate_desc idt_table[IDT_ENTRIES];
15011+extern const struct desc_ptr debug_idt_descr;
15012+extern gate_desc debug_idt_table[IDT_ENTRIES];
15013
15014+extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
15015 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
15016 {
15017- return per_cpu(gdt_page, cpu).gdt;
15018+ return cpu_gdt_table[cpu];
15019 }
15020
15021 #ifdef CONFIG_X86_64
15022@@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
15023 unsigned long base, unsigned dpl, unsigned flags,
15024 unsigned short seg)
15025 {
15026- gate->a = (seg << 16) | (base & 0xffff);
15027- gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
15028+ gate->gate.offset_low = base;
15029+ gate->gate.seg = seg;
15030+ gate->gate.reserved = 0;
15031+ gate->gate.type = type;
15032+ gate->gate.s = 0;
15033+ gate->gate.dpl = dpl;
15034+ gate->gate.p = 1;
15035+ gate->gate.offset_high = base >> 16;
15036 }
15037
15038 #endif
15039@@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
15040
15041 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
15042 {
15043+ pax_open_kernel();
15044 memcpy(&idt[entry], gate, sizeof(*gate));
15045+ pax_close_kernel();
15046 }
15047
15048 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
15049 {
15050+ pax_open_kernel();
15051 memcpy(&ldt[entry], desc, 8);
15052+ pax_close_kernel();
15053 }
15054
15055 static inline void
15056@@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
15057 default: size = sizeof(*gdt); break;
15058 }
15059
15060+ pax_open_kernel();
15061 memcpy(&gdt[entry], desc, size);
15062+ pax_close_kernel();
15063 }
15064
15065 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
15066@@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
15067
15068 static inline void native_load_tr_desc(void)
15069 {
15070+ pax_open_kernel();
15071 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
15072+ pax_close_kernel();
15073 }
15074
15075 static inline void native_load_gdt(const struct desc_ptr *dtr)
15076@@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
15077 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
15078 unsigned int i;
15079
15080+ pax_open_kernel();
15081 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
15082 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
15083+ pax_close_kernel();
15084 }
15085
15086 #define _LDT_empty(info) \
15087@@ -287,7 +300,7 @@ static inline void load_LDT(mm_context_t *pc)
15088 preempt_enable();
15089 }
15090
15091-static inline unsigned long get_desc_base(const struct desc_struct *desc)
15092+static inline unsigned long __intentional_overflow(-1) get_desc_base(const struct desc_struct *desc)
15093 {
15094 return (unsigned)(desc->base0 | ((desc->base1) << 16) | ((desc->base2) << 24));
15095 }
15096@@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
15097 }
15098
15099 #ifdef CONFIG_X86_64
15100-static inline void set_nmi_gate(int gate, void *addr)
15101+static inline void set_nmi_gate(int gate, const void *addr)
15102 {
15103 gate_desc s;
15104
15105@@ -321,8 +334,8 @@ static inline void set_nmi_gate(int gate, void *addr)
15106 #endif
15107
15108 #ifdef CONFIG_TRACING
15109-extern struct desc_ptr trace_idt_descr;
15110-extern gate_desc trace_idt_table[];
15111+extern const struct desc_ptr trace_idt_descr;
15112+extern gate_desc trace_idt_table[IDT_ENTRIES];
15113 static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
15114 {
15115 write_idt_entry(trace_idt_table, entry, gate);
15116@@ -333,7 +346,7 @@ static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
15117 }
15118 #endif
15119
15120-static inline void _set_gate(int gate, unsigned type, void *addr,
15121+static inline void _set_gate(int gate, unsigned type, const void *addr,
15122 unsigned dpl, unsigned ist, unsigned seg)
15123 {
15124 gate_desc s;
15125@@ -353,7 +366,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
15126 * Pentium F0 0F bugfix can have resulted in the mapped
15127 * IDT being write-protected.
15128 */
15129-static inline void set_intr_gate(unsigned int n, void *addr)
15130+static inline void set_intr_gate(unsigned int n, const void *addr)
15131 {
15132 BUG_ON((unsigned)n > 0xFF);
15133 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
15134@@ -410,19 +423,19 @@ static inline void __alloc_intr_gate(unsigned int n, void *addr)
15135 /*
15136 * This routine sets up an interrupt gate at directory privilege level 3.
15137 */
15138-static inline void set_system_intr_gate(unsigned int n, void *addr)
15139+static inline void set_system_intr_gate(unsigned int n, const void *addr)
15140 {
15141 BUG_ON((unsigned)n > 0xFF);
15142 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
15143 }
15144
15145-static inline void set_system_trap_gate(unsigned int n, void *addr)
15146+static inline void set_system_trap_gate(unsigned int n, const void *addr)
15147 {
15148 BUG_ON((unsigned)n > 0xFF);
15149 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
15150 }
15151
15152-static inline void set_trap_gate(unsigned int n, void *addr)
15153+static inline void set_trap_gate(unsigned int n, const void *addr)
15154 {
15155 BUG_ON((unsigned)n > 0xFF);
15156 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
15157@@ -431,16 +444,16 @@ static inline void set_trap_gate(unsigned int n, void *addr)
15158 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
15159 {
15160 BUG_ON((unsigned)n > 0xFF);
15161- _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
15162+ _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
15163 }
15164
15165-static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
15166+static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
15167 {
15168 BUG_ON((unsigned)n > 0xFF);
15169 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
15170 }
15171
15172-static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
15173+static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
15174 {
15175 BUG_ON((unsigned)n > 0xFF);
15176 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
15177@@ -512,4 +525,17 @@ static inline void load_current_idt(void)
15178 else
15179 load_idt((const struct desc_ptr *)&idt_descr);
15180 }
15181+
15182+#ifdef CONFIG_X86_32
15183+static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
15184+{
15185+ struct desc_struct d;
15186+
15187+ if (likely(limit))
15188+ limit = (limit - 1UL) >> PAGE_SHIFT;
15189+ pack_descriptor(&d, base, limit, 0xFB, 0xC);
15190+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
15191+}
15192+#endif
15193+
15194 #endif /* _ASM_X86_DESC_H */
15195diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
15196index 278441f..b95a174 100644
15197--- a/arch/x86/include/asm/desc_defs.h
15198+++ b/arch/x86/include/asm/desc_defs.h
15199@@ -31,6 +31,12 @@ struct desc_struct {
15200 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
15201 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
15202 };
15203+ struct {
15204+ u16 offset_low;
15205+ u16 seg;
15206+ unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
15207+ unsigned offset_high: 16;
15208+ } gate;
15209 };
15210 } __attribute__((packed));
15211
15212diff --git a/arch/x86/include/asm/div64.h b/arch/x86/include/asm/div64.h
15213index ced283a..ffe04cc 100644
15214--- a/arch/x86/include/asm/div64.h
15215+++ b/arch/x86/include/asm/div64.h
15216@@ -39,7 +39,7 @@
15217 __mod; \
15218 })
15219
15220-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
15221+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
15222 {
15223 union {
15224 u64 v64;
15225diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
15226index 9c999c1..3860cb8 100644
15227--- a/arch/x86/include/asm/elf.h
15228+++ b/arch/x86/include/asm/elf.h
15229@@ -243,7 +243,25 @@ extern int force_personality32;
15230 the loader. We need to make sure that it is out of the way of the program
15231 that it will "exec", and that there is sufficient room for the brk. */
15232
15233+#ifdef CONFIG_PAX_SEGMEXEC
15234+#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
15235+#else
15236 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
15237+#endif
15238+
15239+#ifdef CONFIG_PAX_ASLR
15240+#ifdef CONFIG_X86_32
15241+#define PAX_ELF_ET_DYN_BASE 0x10000000UL
15242+
15243+#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
15244+#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
15245+#else
15246+#define PAX_ELF_ET_DYN_BASE 0x400000UL
15247+
15248+#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
15249+#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
15250+#endif
15251+#endif
15252
15253 /* This yields a mask that user programs can use to figure out what
15254 instruction set this CPU supports. This could be done in user space,
15255@@ -296,16 +314,12 @@ do { \
15256
15257 #define ARCH_DLINFO \
15258 do { \
15259- if (vdso_enabled) \
15260- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
15261- (unsigned long)current->mm->context.vdso); \
15262+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
15263 } while (0)
15264
15265 #define ARCH_DLINFO_X32 \
15266 do { \
15267- if (vdso_enabled) \
15268- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
15269- (unsigned long)current->mm->context.vdso); \
15270+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
15271 } while (0)
15272
15273 #define AT_SYSINFO 32
15274@@ -320,7 +334,7 @@ else \
15275
15276 #endif /* !CONFIG_X86_32 */
15277
15278-#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
15279+#define VDSO_CURRENT_BASE (current->mm->context.vdso)
15280
15281 #define VDSO_ENTRY \
15282 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
15283@@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
15284 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
15285 #define compat_arch_setup_additional_pages syscall32_setup_pages
15286
15287-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
15288-#define arch_randomize_brk arch_randomize_brk
15289-
15290 /*
15291 * True on X86_32 or when emulating IA32 on X86_64
15292 */
15293diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
15294index 77a99ac..39ff7f5 100644
15295--- a/arch/x86/include/asm/emergency-restart.h
15296+++ b/arch/x86/include/asm/emergency-restart.h
15297@@ -1,6 +1,6 @@
15298 #ifndef _ASM_X86_EMERGENCY_RESTART_H
15299 #define _ASM_X86_EMERGENCY_RESTART_H
15300
15301-extern void machine_emergency_restart(void);
15302+extern void machine_emergency_restart(void) __noreturn;
15303
15304 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
15305diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
15306index 4d0bda7..221da4d 100644
15307--- a/arch/x86/include/asm/fpu-internal.h
15308+++ b/arch/x86/include/asm/fpu-internal.h
15309@@ -124,8 +124,11 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
15310 #define user_insn(insn, output, input...) \
15311 ({ \
15312 int err; \
15313+ pax_open_userland(); \
15314 asm volatile(ASM_STAC "\n" \
15315- "1:" #insn "\n\t" \
15316+ "1:" \
15317+ __copyuser_seg \
15318+ #insn "\n\t" \
15319 "2: " ASM_CLAC "\n" \
15320 ".section .fixup,\"ax\"\n" \
15321 "3: movl $-1,%[err]\n" \
15322@@ -134,6 +137,7 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
15323 _ASM_EXTABLE(1b, 3b) \
15324 : [err] "=r" (err), output \
15325 : "0"(0), input); \
15326+ pax_close_userland(); \
15327 err; \
15328 })
15329
15330@@ -298,7 +302,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
15331 "emms\n\t" /* clear stack tags */
15332 "fildl %P[addr]", /* set F?P to defined value */
15333 X86_FEATURE_FXSAVE_LEAK,
15334- [addr] "m" (tsk->thread.fpu.has_fpu));
15335+ [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
15336
15337 return fpu_restore_checking(&tsk->thread.fpu);
15338 }
15339diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
15340index be27ba1..04a8801 100644
15341--- a/arch/x86/include/asm/futex.h
15342+++ b/arch/x86/include/asm/futex.h
15343@@ -12,6 +12,7 @@
15344 #include <asm/smap.h>
15345
15346 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
15347+ typecheck(u32 __user *, uaddr); \
15348 asm volatile("\t" ASM_STAC "\n" \
15349 "1:\t" insn "\n" \
15350 "2:\t" ASM_CLAC "\n" \
15351@@ -20,15 +21,16 @@
15352 "\tjmp\t2b\n" \
15353 "\t.previous\n" \
15354 _ASM_EXTABLE(1b, 3b) \
15355- : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
15356+ : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
15357 : "i" (-EFAULT), "0" (oparg), "1" (0))
15358
15359 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
15360+ typecheck(u32 __user *, uaddr); \
15361 asm volatile("\t" ASM_STAC "\n" \
15362 "1:\tmovl %2, %0\n" \
15363 "\tmovl\t%0, %3\n" \
15364 "\t" insn "\n" \
15365- "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
15366+ "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
15367 "\tjnz\t1b\n" \
15368 "3:\t" ASM_CLAC "\n" \
15369 "\t.section .fixup,\"ax\"\n" \
15370@@ -38,7 +40,7 @@
15371 _ASM_EXTABLE(1b, 4b) \
15372 _ASM_EXTABLE(2b, 4b) \
15373 : "=&a" (oldval), "=&r" (ret), \
15374- "+m" (*uaddr), "=&r" (tem) \
15375+ "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
15376 : "r" (oparg), "i" (-EFAULT), "1" (0))
15377
15378 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
15379@@ -57,12 +59,13 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
15380
15381 pagefault_disable();
15382
15383+ pax_open_userland();
15384 switch (op) {
15385 case FUTEX_OP_SET:
15386- __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
15387+ __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
15388 break;
15389 case FUTEX_OP_ADD:
15390- __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
15391+ __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
15392 uaddr, oparg);
15393 break;
15394 case FUTEX_OP_OR:
15395@@ -77,6 +80,7 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
15396 default:
15397 ret = -ENOSYS;
15398 }
15399+ pax_close_userland();
15400
15401 pagefault_enable();
15402
15403@@ -115,18 +119,20 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
15404 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
15405 return -EFAULT;
15406
15407+ pax_open_userland();
15408 asm volatile("\t" ASM_STAC "\n"
15409- "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
15410+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
15411 "2:\t" ASM_CLAC "\n"
15412 "\t.section .fixup, \"ax\"\n"
15413 "3:\tmov %3, %0\n"
15414 "\tjmp 2b\n"
15415 "\t.previous\n"
15416 _ASM_EXTABLE(1b, 3b)
15417- : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
15418+ : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
15419 : "i" (-EFAULT), "r" (newval), "1" (oldval)
15420 : "memory"
15421 );
15422+ pax_close_userland();
15423
15424 *uval = oldval;
15425 return ret;
15426diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
15427index 92b3bae..3866449 100644
15428--- a/arch/x86/include/asm/hw_irq.h
15429+++ b/arch/x86/include/asm/hw_irq.h
15430@@ -165,8 +165,8 @@ extern void setup_ioapic_dest(void);
15431 extern void enable_IO_APIC(void);
15432
15433 /* Statistics */
15434-extern atomic_t irq_err_count;
15435-extern atomic_t irq_mis_count;
15436+extern atomic_unchecked_t irq_err_count;
15437+extern atomic_unchecked_t irq_mis_count;
15438
15439 /* EISA */
15440 extern void eisa_set_level_irq(unsigned int irq);
15441diff --git a/arch/x86/include/asm/i8259.h b/arch/x86/include/asm/i8259.h
15442index a203659..9889f1c 100644
15443--- a/arch/x86/include/asm/i8259.h
15444+++ b/arch/x86/include/asm/i8259.h
15445@@ -62,7 +62,7 @@ struct legacy_pic {
15446 void (*init)(int auto_eoi);
15447 int (*irq_pending)(unsigned int irq);
15448 void (*make_irq)(unsigned int irq);
15449-};
15450+} __do_const;
15451
15452 extern struct legacy_pic *legacy_pic;
15453 extern struct legacy_pic null_legacy_pic;
15454diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
15455index 34f69cb..6d95446 100644
15456--- a/arch/x86/include/asm/io.h
15457+++ b/arch/x86/include/asm/io.h
15458@@ -51,12 +51,12 @@ static inline void name(type val, volatile void __iomem *addr) \
15459 "m" (*(volatile type __force *)addr) barrier); }
15460
15461 build_mmio_read(readb, "b", unsigned char, "=q", :"memory")
15462-build_mmio_read(readw, "w", unsigned short, "=r", :"memory")
15463-build_mmio_read(readl, "l", unsigned int, "=r", :"memory")
15464+build_mmio_read(__intentional_overflow(-1) readw, "w", unsigned short, "=r", :"memory")
15465+build_mmio_read(__intentional_overflow(-1) readl, "l", unsigned int, "=r", :"memory")
15466
15467 build_mmio_read(__readb, "b", unsigned char, "=q", )
15468-build_mmio_read(__readw, "w", unsigned short, "=r", )
15469-build_mmio_read(__readl, "l", unsigned int, "=r", )
15470+build_mmio_read(__intentional_overflow(-1) __readw, "w", unsigned short, "=r", )
15471+build_mmio_read(__intentional_overflow(-1) __readl, "l", unsigned int, "=r", )
15472
15473 build_mmio_write(writeb, "b", unsigned char, "q", :"memory")
15474 build_mmio_write(writew, "w", unsigned short, "r", :"memory")
15475@@ -184,7 +184,7 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
15476 return ioremap_nocache(offset, size);
15477 }
15478
15479-extern void iounmap(volatile void __iomem *addr);
15480+extern void iounmap(const volatile void __iomem *addr);
15481
15482 extern void set_iounmap_nonlazy(void);
15483
15484@@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
15485
15486 #include <linux/vmalloc.h>
15487
15488+#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
15489+static inline int valid_phys_addr_range(unsigned long addr, size_t count)
15490+{
15491+ return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
15492+}
15493+
15494+static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
15495+{
15496+ return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
15497+}
15498+
15499 /*
15500 * Convert a virtual cached pointer to an uncached pointer
15501 */
15502diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
15503index bba3cf8..06bc8da 100644
15504--- a/arch/x86/include/asm/irqflags.h
15505+++ b/arch/x86/include/asm/irqflags.h
15506@@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
15507 sti; \
15508 sysexit
15509
15510+#define GET_CR0_INTO_RDI mov %cr0, %rdi
15511+#define SET_RDI_INTO_CR0 mov %rdi, %cr0
15512+#define GET_CR3_INTO_RDI mov %cr3, %rdi
15513+#define SET_RDI_INTO_CR3 mov %rdi, %cr3
15514+
15515 #else
15516 #define INTERRUPT_RETURN iret
15517 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
15518diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
15519index 9454c16..e4100e3 100644
15520--- a/arch/x86/include/asm/kprobes.h
15521+++ b/arch/x86/include/asm/kprobes.h
15522@@ -38,13 +38,8 @@ typedef u8 kprobe_opcode_t;
15523 #define RELATIVEJUMP_SIZE 5
15524 #define RELATIVECALL_OPCODE 0xe8
15525 #define RELATIVE_ADDR_SIZE 4
15526-#define MAX_STACK_SIZE 64
15527-#define MIN_STACK_SIZE(ADDR) \
15528- (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
15529- THREAD_SIZE - (unsigned long)(ADDR))) \
15530- ? (MAX_STACK_SIZE) \
15531- : (((unsigned long)current_thread_info()) + \
15532- THREAD_SIZE - (unsigned long)(ADDR)))
15533+#define MAX_STACK_SIZE 64UL
15534+#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
15535
15536 #define flush_insn_slot(p) do { } while (0)
15537
15538diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
15539index 2d89e39..baee879 100644
15540--- a/arch/x86/include/asm/local.h
15541+++ b/arch/x86/include/asm/local.h
15542@@ -10,33 +10,97 @@ typedef struct {
15543 atomic_long_t a;
15544 } local_t;
15545
15546+typedef struct {
15547+ atomic_long_unchecked_t a;
15548+} local_unchecked_t;
15549+
15550 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
15551
15552 #define local_read(l) atomic_long_read(&(l)->a)
15553+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
15554 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
15555+#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
15556
15557 static inline void local_inc(local_t *l)
15558 {
15559- asm volatile(_ASM_INC "%0"
15560+ asm volatile(_ASM_INC "%0\n"
15561+
15562+#ifdef CONFIG_PAX_REFCOUNT
15563+ "jno 0f\n"
15564+ _ASM_DEC "%0\n"
15565+ "int $4\n0:\n"
15566+ _ASM_EXTABLE(0b, 0b)
15567+#endif
15568+
15569+ : "+m" (l->a.counter));
15570+}
15571+
15572+static inline void local_inc_unchecked(local_unchecked_t *l)
15573+{
15574+ asm volatile(_ASM_INC "%0\n"
15575 : "+m" (l->a.counter));
15576 }
15577
15578 static inline void local_dec(local_t *l)
15579 {
15580- asm volatile(_ASM_DEC "%0"
15581+ asm volatile(_ASM_DEC "%0\n"
15582+
15583+#ifdef CONFIG_PAX_REFCOUNT
15584+ "jno 0f\n"
15585+ _ASM_INC "%0\n"
15586+ "int $4\n0:\n"
15587+ _ASM_EXTABLE(0b, 0b)
15588+#endif
15589+
15590+ : "+m" (l->a.counter));
15591+}
15592+
15593+static inline void local_dec_unchecked(local_unchecked_t *l)
15594+{
15595+ asm volatile(_ASM_DEC "%0\n"
15596 : "+m" (l->a.counter));
15597 }
15598
15599 static inline void local_add(long i, local_t *l)
15600 {
15601- asm volatile(_ASM_ADD "%1,%0"
15602+ asm volatile(_ASM_ADD "%1,%0\n"
15603+
15604+#ifdef CONFIG_PAX_REFCOUNT
15605+ "jno 0f\n"
15606+ _ASM_SUB "%1,%0\n"
15607+ "int $4\n0:\n"
15608+ _ASM_EXTABLE(0b, 0b)
15609+#endif
15610+
15611+ : "+m" (l->a.counter)
15612+ : "ir" (i));
15613+}
15614+
15615+static inline void local_add_unchecked(long i, local_unchecked_t *l)
15616+{
15617+ asm volatile(_ASM_ADD "%1,%0\n"
15618 : "+m" (l->a.counter)
15619 : "ir" (i));
15620 }
15621
15622 static inline void local_sub(long i, local_t *l)
15623 {
15624- asm volatile(_ASM_SUB "%1,%0"
15625+ asm volatile(_ASM_SUB "%1,%0\n"
15626+
15627+#ifdef CONFIG_PAX_REFCOUNT
15628+ "jno 0f\n"
15629+ _ASM_ADD "%1,%0\n"
15630+ "int $4\n0:\n"
15631+ _ASM_EXTABLE(0b, 0b)
15632+#endif
15633+
15634+ : "+m" (l->a.counter)
15635+ : "ir" (i));
15636+}
15637+
15638+static inline void local_sub_unchecked(long i, local_unchecked_t *l)
15639+{
15640+ asm volatile(_ASM_SUB "%1,%0\n"
15641 : "+m" (l->a.counter)
15642 : "ir" (i));
15643 }
15644@@ -54,7 +118,16 @@ static inline int local_sub_and_test(long i, local_t *l)
15645 {
15646 unsigned char c;
15647
15648- asm volatile(_ASM_SUB "%2,%0; sete %1"
15649+ asm volatile(_ASM_SUB "%2,%0\n"
15650+
15651+#ifdef CONFIG_PAX_REFCOUNT
15652+ "jno 0f\n"
15653+ _ASM_ADD "%2,%0\n"
15654+ "int $4\n0:\n"
15655+ _ASM_EXTABLE(0b, 0b)
15656+#endif
15657+
15658+ "sete %1\n"
15659 : "+m" (l->a.counter), "=qm" (c)
15660 : "ir" (i) : "memory");
15661 return c;
15662@@ -72,7 +145,16 @@ static inline int local_dec_and_test(local_t *l)
15663 {
15664 unsigned char c;
15665
15666- asm volatile(_ASM_DEC "%0; sete %1"
15667+ asm volatile(_ASM_DEC "%0\n"
15668+
15669+#ifdef CONFIG_PAX_REFCOUNT
15670+ "jno 0f\n"
15671+ _ASM_INC "%0\n"
15672+ "int $4\n0:\n"
15673+ _ASM_EXTABLE(0b, 0b)
15674+#endif
15675+
15676+ "sete %1\n"
15677 : "+m" (l->a.counter), "=qm" (c)
15678 : : "memory");
15679 return c != 0;
15680@@ -90,7 +172,16 @@ static inline int local_inc_and_test(local_t *l)
15681 {
15682 unsigned char c;
15683
15684- asm volatile(_ASM_INC "%0; sete %1"
15685+ asm volatile(_ASM_INC "%0\n"
15686+
15687+#ifdef CONFIG_PAX_REFCOUNT
15688+ "jno 0f\n"
15689+ _ASM_DEC "%0\n"
15690+ "int $4\n0:\n"
15691+ _ASM_EXTABLE(0b, 0b)
15692+#endif
15693+
15694+ "sete %1\n"
15695 : "+m" (l->a.counter), "=qm" (c)
15696 : : "memory");
15697 return c != 0;
15698@@ -109,7 +200,16 @@ static inline int local_add_negative(long i, local_t *l)
15699 {
15700 unsigned char c;
15701
15702- asm volatile(_ASM_ADD "%2,%0; sets %1"
15703+ asm volatile(_ASM_ADD "%2,%0\n"
15704+
15705+#ifdef CONFIG_PAX_REFCOUNT
15706+ "jno 0f\n"
15707+ _ASM_SUB "%2,%0\n"
15708+ "int $4\n0:\n"
15709+ _ASM_EXTABLE(0b, 0b)
15710+#endif
15711+
15712+ "sets %1\n"
15713 : "+m" (l->a.counter), "=qm" (c)
15714 : "ir" (i) : "memory");
15715 return c;
15716@@ -125,6 +225,30 @@ static inline int local_add_negative(long i, local_t *l)
15717 static inline long local_add_return(long i, local_t *l)
15718 {
15719 long __i = i;
15720+ asm volatile(_ASM_XADD "%0, %1\n"
15721+
15722+#ifdef CONFIG_PAX_REFCOUNT
15723+ "jno 0f\n"
15724+ _ASM_MOV "%0,%1\n"
15725+ "int $4\n0:\n"
15726+ _ASM_EXTABLE(0b, 0b)
15727+#endif
15728+
15729+ : "+r" (i), "+m" (l->a.counter)
15730+ : : "memory");
15731+ return i + __i;
15732+}
15733+
15734+/**
15735+ * local_add_return_unchecked - add and return
15736+ * @i: integer value to add
15737+ * @l: pointer to type local_unchecked_t
15738+ *
15739+ * Atomically adds @i to @l and returns @i + @l
15740+ */
15741+static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
15742+{
15743+ long __i = i;
15744 asm volatile(_ASM_XADD "%0, %1;"
15745 : "+r" (i), "+m" (l->a.counter)
15746 : : "memory");
15747@@ -141,6 +265,8 @@ static inline long local_sub_return(long i, local_t *l)
15748
15749 #define local_cmpxchg(l, o, n) \
15750 (cmpxchg_local(&((l)->a.counter), (o), (n)))
15751+#define local_cmpxchg_unchecked(l, o, n) \
15752+ (cmpxchg_local(&((l)->a.counter), (o), (n)))
15753 /* Always has a lock prefix */
15754 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
15755
15756diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
15757new file mode 100644
15758index 0000000..2bfd3ba
15759--- /dev/null
15760+++ b/arch/x86/include/asm/mman.h
15761@@ -0,0 +1,15 @@
15762+#ifndef _X86_MMAN_H
15763+#define _X86_MMAN_H
15764+
15765+#include <uapi/asm/mman.h>
15766+
15767+#ifdef __KERNEL__
15768+#ifndef __ASSEMBLY__
15769+#ifdef CONFIG_X86_32
15770+#define arch_mmap_check i386_mmap_check
15771+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags);
15772+#endif
15773+#endif
15774+#endif
15775+
15776+#endif /* X86_MMAN_H */
15777diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
15778index 5f55e69..e20bfb1 100644
15779--- a/arch/x86/include/asm/mmu.h
15780+++ b/arch/x86/include/asm/mmu.h
15781@@ -9,7 +9,7 @@
15782 * we put the segment information here.
15783 */
15784 typedef struct {
15785- void *ldt;
15786+ struct desc_struct *ldt;
15787 int size;
15788
15789 #ifdef CONFIG_X86_64
15790@@ -18,7 +18,19 @@ typedef struct {
15791 #endif
15792
15793 struct mutex lock;
15794- void *vdso;
15795+ unsigned long vdso;
15796+
15797+#ifdef CONFIG_X86_32
15798+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
15799+ unsigned long user_cs_base;
15800+ unsigned long user_cs_limit;
15801+
15802+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
15803+ cpumask_t cpu_user_cs_mask;
15804+#endif
15805+
15806+#endif
15807+#endif
15808 } mm_context_t;
15809
15810 #ifdef CONFIG_SMP
15811diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
15812index be12c53..4d24039 100644
15813--- a/arch/x86/include/asm/mmu_context.h
15814+++ b/arch/x86/include/asm/mmu_context.h
15815@@ -24,6 +24,20 @@ void destroy_context(struct mm_struct *mm);
15816
15817 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
15818 {
15819+
15820+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15821+ if (!(static_cpu_has(X86_FEATURE_PCID))) {
15822+ unsigned int i;
15823+ pgd_t *pgd;
15824+
15825+ pax_open_kernel();
15826+ pgd = get_cpu_pgd(smp_processor_id(), kernel);
15827+ for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
15828+ set_pgd_batched(pgd+i, native_make_pgd(0));
15829+ pax_close_kernel();
15830+ }
15831+#endif
15832+
15833 #ifdef CONFIG_SMP
15834 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
15835 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
15836@@ -34,16 +48,59 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
15837 struct task_struct *tsk)
15838 {
15839 unsigned cpu = smp_processor_id();
15840+#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
15841+ int tlbstate = TLBSTATE_OK;
15842+#endif
15843
15844 if (likely(prev != next)) {
15845 #ifdef CONFIG_SMP
15846+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
15847+ tlbstate = this_cpu_read(cpu_tlbstate.state);
15848+#endif
15849 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
15850 this_cpu_write(cpu_tlbstate.active_mm, next);
15851 #endif
15852 cpumask_set_cpu(cpu, mm_cpumask(next));
15853
15854 /* Re-load page tables */
15855+#ifdef CONFIG_PAX_PER_CPU_PGD
15856+ pax_open_kernel();
15857+
15858+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15859+ if (static_cpu_has(X86_FEATURE_PCID))
15860+ __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
15861+ else
15862+#endif
15863+
15864+ __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
15865+ __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
15866+ pax_close_kernel();
15867+ 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));
15868+
15869+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15870+ if (static_cpu_has(X86_FEATURE_PCID)) {
15871+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
15872+ u64 descriptor[2];
15873+ descriptor[0] = PCID_USER;
15874+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
15875+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
15876+ descriptor[0] = PCID_KERNEL;
15877+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
15878+ }
15879+ } else {
15880+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
15881+ if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
15882+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
15883+ else
15884+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
15885+ }
15886+ } else
15887+#endif
15888+
15889+ load_cr3(get_cpu_pgd(cpu, kernel));
15890+#else
15891 load_cr3(next->pgd);
15892+#endif
15893
15894 /* Stop flush ipis for the previous mm */
15895 cpumask_clear_cpu(cpu, mm_cpumask(prev));
15896@@ -51,9 +108,67 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
15897 /* Load the LDT, if the LDT is different: */
15898 if (unlikely(prev->context.ldt != next->context.ldt))
15899 load_LDT_nolock(&next->context);
15900+
15901+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
15902+ if (!(__supported_pte_mask & _PAGE_NX)) {
15903+ smp_mb__before_clear_bit();
15904+ cpu_clear(cpu, prev->context.cpu_user_cs_mask);
15905+ smp_mb__after_clear_bit();
15906+ cpu_set(cpu, next->context.cpu_user_cs_mask);
15907+ }
15908+#endif
15909+
15910+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
15911+ if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
15912+ prev->context.user_cs_limit != next->context.user_cs_limit))
15913+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
15914+#ifdef CONFIG_SMP
15915+ else if (unlikely(tlbstate != TLBSTATE_OK))
15916+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
15917+#endif
15918+#endif
15919+
15920 }
15921+ else {
15922+
15923+#ifdef CONFIG_PAX_PER_CPU_PGD
15924+ pax_open_kernel();
15925+
15926+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15927+ if (static_cpu_has(X86_FEATURE_PCID))
15928+ __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
15929+ else
15930+#endif
15931+
15932+ __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
15933+ __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
15934+ pax_close_kernel();
15935+ 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));
15936+
15937+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15938+ if (static_cpu_has(X86_FEATURE_PCID)) {
15939+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
15940+ u64 descriptor[2];
15941+ descriptor[0] = PCID_USER;
15942+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
15943+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
15944+ descriptor[0] = PCID_KERNEL;
15945+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
15946+ }
15947+ } else {
15948+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
15949+ if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
15950+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
15951+ else
15952+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
15953+ }
15954+ } else
15955+#endif
15956+
15957+ load_cr3(get_cpu_pgd(cpu, kernel));
15958+#endif
15959+
15960 #ifdef CONFIG_SMP
15961- else {
15962 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
15963 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
15964
15965@@ -70,11 +185,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
15966 * tlb flush IPI delivery. We must reload CR3
15967 * to make sure to use no freed page tables.
15968 */
15969+
15970+#ifndef CONFIG_PAX_PER_CPU_PGD
15971 load_cr3(next->pgd);
15972+#endif
15973+
15974 load_LDT_nolock(&next->context);
15975+
15976+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
15977+ if (!(__supported_pte_mask & _PAGE_NX))
15978+ cpu_set(cpu, next->context.cpu_user_cs_mask);
15979+#endif
15980+
15981+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
15982+#ifdef CONFIG_PAX_PAGEEXEC
15983+ if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
15984+#endif
15985+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
15986+#endif
15987+
15988 }
15989+#endif
15990 }
15991-#endif
15992 }
15993
15994 #define activate_mm(prev, next) \
15995diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
15996index e3b7819..b257c64 100644
15997--- a/arch/x86/include/asm/module.h
15998+++ b/arch/x86/include/asm/module.h
15999@@ -5,6 +5,7 @@
16000
16001 #ifdef CONFIG_X86_64
16002 /* X86_64 does not define MODULE_PROC_FAMILY */
16003+#define MODULE_PROC_FAMILY ""
16004 #elif defined CONFIG_M486
16005 #define MODULE_PROC_FAMILY "486 "
16006 #elif defined CONFIG_M586
16007@@ -57,8 +58,20 @@
16008 #error unknown processor family
16009 #endif
16010
16011-#ifdef CONFIG_X86_32
16012-# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
16013+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
16014+#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
16015+#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
16016+#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
16017+#else
16018+#define MODULE_PAX_KERNEXEC ""
16019 #endif
16020
16021+#ifdef CONFIG_PAX_MEMORY_UDEREF
16022+#define MODULE_PAX_UDEREF "UDEREF "
16023+#else
16024+#define MODULE_PAX_UDEREF ""
16025+#endif
16026+
16027+#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
16028+
16029 #endif /* _ASM_X86_MODULE_H */
16030diff --git a/arch/x86/include/asm/nmi.h b/arch/x86/include/asm/nmi.h
16031index 86f9301..b365cda 100644
16032--- a/arch/x86/include/asm/nmi.h
16033+++ b/arch/x86/include/asm/nmi.h
16034@@ -40,11 +40,11 @@ struct nmiaction {
16035 nmi_handler_t handler;
16036 unsigned long flags;
16037 const char *name;
16038-};
16039+} __do_const;
16040
16041 #define register_nmi_handler(t, fn, fg, n, init...) \
16042 ({ \
16043- static struct nmiaction init fn##_na = { \
16044+ static const struct nmiaction init fn##_na = { \
16045 .handler = (fn), \
16046 .name = (n), \
16047 .flags = (fg), \
16048@@ -52,7 +52,7 @@ struct nmiaction {
16049 __register_nmi_handler((t), &fn##_na); \
16050 })
16051
16052-int __register_nmi_handler(unsigned int, struct nmiaction *);
16053+int __register_nmi_handler(unsigned int, const struct nmiaction *);
16054
16055 void unregister_nmi_handler(unsigned int, const char *);
16056
16057diff --git a/arch/x86/include/asm/page.h b/arch/x86/include/asm/page.h
16058index c878924..21f4889 100644
16059--- a/arch/x86/include/asm/page.h
16060+++ b/arch/x86/include/asm/page.h
16061@@ -52,6 +52,7 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
16062 __phys_addr_symbol(__phys_reloc_hide((unsigned long)(x)))
16063
16064 #define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET))
16065+#define __early_va(x) ((void *)((unsigned long)(x)+__START_KERNEL_map - phys_base))
16066
16067 #define __boot_va(x) __va(x)
16068 #define __boot_pa(x) __pa(x)
16069diff --git a/arch/x86/include/asm/page_64.h b/arch/x86/include/asm/page_64.h
16070index 0f1ddee..e2fc3d1 100644
16071--- a/arch/x86/include/asm/page_64.h
16072+++ b/arch/x86/include/asm/page_64.h
16073@@ -7,9 +7,9 @@
16074
16075 /* duplicated to the one in bootmem.h */
16076 extern unsigned long max_pfn;
16077-extern unsigned long phys_base;
16078+extern const unsigned long phys_base;
16079
16080-static inline unsigned long __phys_addr_nodebug(unsigned long x)
16081+static inline unsigned long __intentional_overflow(-1) __phys_addr_nodebug(unsigned long x)
16082 {
16083 unsigned long y = x - __START_KERNEL_map;
16084
16085diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
16086index 401f350..dee5d13 100644
16087--- a/arch/x86/include/asm/paravirt.h
16088+++ b/arch/x86/include/asm/paravirt.h
16089@@ -560,7 +560,7 @@ static inline pmd_t __pmd(pmdval_t val)
16090 return (pmd_t) { ret };
16091 }
16092
16093-static inline pmdval_t pmd_val(pmd_t pmd)
16094+static inline __intentional_overflow(-1) pmdval_t pmd_val(pmd_t pmd)
16095 {
16096 pmdval_t ret;
16097
16098@@ -626,6 +626,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
16099 val);
16100 }
16101
16102+static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
16103+{
16104+ pgdval_t val = native_pgd_val(pgd);
16105+
16106+ if (sizeof(pgdval_t) > sizeof(long))
16107+ PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
16108+ val, (u64)val >> 32);
16109+ else
16110+ PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
16111+ val);
16112+}
16113+
16114 static inline void pgd_clear(pgd_t *pgdp)
16115 {
16116 set_pgd(pgdp, __pgd(0));
16117@@ -710,6 +722,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
16118 pv_mmu_ops.set_fixmap(idx, phys, flags);
16119 }
16120
16121+#ifdef CONFIG_PAX_KERNEXEC
16122+static inline unsigned long pax_open_kernel(void)
16123+{
16124+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
16125+}
16126+
16127+static inline unsigned long pax_close_kernel(void)
16128+{
16129+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
16130+}
16131+#else
16132+static inline unsigned long pax_open_kernel(void) { return 0; }
16133+static inline unsigned long pax_close_kernel(void) { return 0; }
16134+#endif
16135+
16136 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
16137
16138 static __always_inline void __ticket_lock_spinning(struct arch_spinlock *lock,
16139@@ -906,7 +933,7 @@ extern void default_banner(void);
16140
16141 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
16142 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
16143-#define PARA_INDIRECT(addr) *%cs:addr
16144+#define PARA_INDIRECT(addr) *%ss:addr
16145 #endif
16146
16147 #define INTERRUPT_RETURN \
16148@@ -981,6 +1008,21 @@ extern void default_banner(void);
16149 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
16150 CLBR_NONE, \
16151 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
16152+
16153+#define GET_CR0_INTO_RDI \
16154+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
16155+ mov %rax,%rdi
16156+
16157+#define SET_RDI_INTO_CR0 \
16158+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
16159+
16160+#define GET_CR3_INTO_RDI \
16161+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
16162+ mov %rax,%rdi
16163+
16164+#define SET_RDI_INTO_CR3 \
16165+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
16166+
16167 #endif /* CONFIG_X86_32 */
16168
16169 #endif /* __ASSEMBLY__ */
16170diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
16171index aab8f67..2531748 100644
16172--- a/arch/x86/include/asm/paravirt_types.h
16173+++ b/arch/x86/include/asm/paravirt_types.h
16174@@ -84,7 +84,7 @@ struct pv_init_ops {
16175 */
16176 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
16177 unsigned long addr, unsigned len);
16178-};
16179+} __no_const;
16180
16181
16182 struct pv_lazy_ops {
16183@@ -98,7 +98,7 @@ struct pv_time_ops {
16184 unsigned long long (*sched_clock)(void);
16185 unsigned long long (*steal_clock)(int cpu);
16186 unsigned long (*get_tsc_khz)(void);
16187-};
16188+} __no_const;
16189
16190 struct pv_cpu_ops {
16191 /* hooks for various privileged instructions */
16192@@ -192,7 +192,7 @@ struct pv_cpu_ops {
16193
16194 void (*start_context_switch)(struct task_struct *prev);
16195 void (*end_context_switch)(struct task_struct *next);
16196-};
16197+} __no_const;
16198
16199 struct pv_irq_ops {
16200 /*
16201@@ -223,7 +223,7 @@ struct pv_apic_ops {
16202 unsigned long start_eip,
16203 unsigned long start_esp);
16204 #endif
16205-};
16206+} __no_const;
16207
16208 struct pv_mmu_ops {
16209 unsigned long (*read_cr2)(void);
16210@@ -313,6 +313,7 @@ struct pv_mmu_ops {
16211 struct paravirt_callee_save make_pud;
16212
16213 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
16214+ void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
16215 #endif /* PAGETABLE_LEVELS == 4 */
16216 #endif /* PAGETABLE_LEVELS >= 3 */
16217
16218@@ -324,6 +325,12 @@ struct pv_mmu_ops {
16219 an mfn. We can tell which is which from the index. */
16220 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
16221 phys_addr_t phys, pgprot_t flags);
16222+
16223+#ifdef CONFIG_PAX_KERNEXEC
16224+ unsigned long (*pax_open_kernel)(void);
16225+ unsigned long (*pax_close_kernel)(void);
16226+#endif
16227+
16228 };
16229
16230 struct arch_spinlock;
16231diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
16232index b4389a4..7024269 100644
16233--- a/arch/x86/include/asm/pgalloc.h
16234+++ b/arch/x86/include/asm/pgalloc.h
16235@@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
16236 pmd_t *pmd, pte_t *pte)
16237 {
16238 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
16239+ set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
16240+}
16241+
16242+static inline void pmd_populate_user(struct mm_struct *mm,
16243+ pmd_t *pmd, pte_t *pte)
16244+{
16245+ paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
16246 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
16247 }
16248
16249@@ -99,12 +106,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
16250
16251 #ifdef CONFIG_X86_PAE
16252 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
16253+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
16254+{
16255+ pud_populate(mm, pudp, pmd);
16256+}
16257 #else /* !CONFIG_X86_PAE */
16258 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
16259 {
16260 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
16261 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
16262 }
16263+
16264+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
16265+{
16266+ paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
16267+ set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
16268+}
16269 #endif /* CONFIG_X86_PAE */
16270
16271 #if PAGETABLE_LEVELS > 3
16272@@ -114,6 +131,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
16273 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
16274 }
16275
16276+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
16277+{
16278+ paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
16279+ set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
16280+}
16281+
16282 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
16283 {
16284 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
16285diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
16286index 3bf2dd0..23d2a9f 100644
16287--- a/arch/x86/include/asm/pgtable-2level.h
16288+++ b/arch/x86/include/asm/pgtable-2level.h
16289@@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
16290
16291 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
16292 {
16293+ pax_open_kernel();
16294 *pmdp = pmd;
16295+ pax_close_kernel();
16296 }
16297
16298 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
16299diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
16300index 81bb91b..9392125 100644
16301--- a/arch/x86/include/asm/pgtable-3level.h
16302+++ b/arch/x86/include/asm/pgtable-3level.h
16303@@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
16304
16305 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
16306 {
16307+ pax_open_kernel();
16308 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
16309+ pax_close_kernel();
16310 }
16311
16312 static inline void native_set_pud(pud_t *pudp, pud_t pud)
16313 {
16314+ pax_open_kernel();
16315 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
16316+ pax_close_kernel();
16317 }
16318
16319 /*
16320diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
16321index 3d19994..732a48c 100644
16322--- a/arch/x86/include/asm/pgtable.h
16323+++ b/arch/x86/include/asm/pgtable.h
16324@@ -45,6 +45,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
16325
16326 #ifndef __PAGETABLE_PUD_FOLDED
16327 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
16328+#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
16329 #define pgd_clear(pgd) native_pgd_clear(pgd)
16330 #endif
16331
16332@@ -82,12 +83,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
16333
16334 #define arch_end_context_switch(prev) do {} while(0)
16335
16336+#define pax_open_kernel() native_pax_open_kernel()
16337+#define pax_close_kernel() native_pax_close_kernel()
16338 #endif /* CONFIG_PARAVIRT */
16339
16340+#define __HAVE_ARCH_PAX_OPEN_KERNEL
16341+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
16342+
16343+#ifdef CONFIG_PAX_KERNEXEC
16344+static inline unsigned long native_pax_open_kernel(void)
16345+{
16346+ unsigned long cr0;
16347+
16348+ preempt_disable();
16349+ barrier();
16350+ cr0 = read_cr0() ^ X86_CR0_WP;
16351+ BUG_ON(cr0 & X86_CR0_WP);
16352+ write_cr0(cr0);
16353+ return cr0 ^ X86_CR0_WP;
16354+}
16355+
16356+static inline unsigned long native_pax_close_kernel(void)
16357+{
16358+ unsigned long cr0;
16359+
16360+ cr0 = read_cr0() ^ X86_CR0_WP;
16361+ BUG_ON(!(cr0 & X86_CR0_WP));
16362+ write_cr0(cr0);
16363+ barrier();
16364+ preempt_enable_no_resched();
16365+ return cr0 ^ X86_CR0_WP;
16366+}
16367+#else
16368+static inline unsigned long native_pax_open_kernel(void) { return 0; }
16369+static inline unsigned long native_pax_close_kernel(void) { return 0; }
16370+#endif
16371+
16372 /*
16373 * The following only work if pte_present() is true.
16374 * Undefined behaviour if not..
16375 */
16376+static inline int pte_user(pte_t pte)
16377+{
16378+ return pte_val(pte) & _PAGE_USER;
16379+}
16380+
16381 static inline int pte_dirty(pte_t pte)
16382 {
16383 return pte_flags(pte) & _PAGE_DIRTY;
16384@@ -148,6 +188,11 @@ static inline unsigned long pud_pfn(pud_t pud)
16385 return (pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT;
16386 }
16387
16388+static inline unsigned long pgd_pfn(pgd_t pgd)
16389+{
16390+ return (pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT;
16391+}
16392+
16393 #define pte_page(pte) pfn_to_page(pte_pfn(pte))
16394
16395 static inline int pmd_large(pmd_t pte)
16396@@ -201,9 +246,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
16397 return pte_clear_flags(pte, _PAGE_RW);
16398 }
16399
16400+static inline pte_t pte_mkread(pte_t pte)
16401+{
16402+ return __pte(pte_val(pte) | _PAGE_USER);
16403+}
16404+
16405 static inline pte_t pte_mkexec(pte_t pte)
16406 {
16407- return pte_clear_flags(pte, _PAGE_NX);
16408+#ifdef CONFIG_X86_PAE
16409+ if (__supported_pte_mask & _PAGE_NX)
16410+ return pte_clear_flags(pte, _PAGE_NX);
16411+ else
16412+#endif
16413+ return pte_set_flags(pte, _PAGE_USER);
16414+}
16415+
16416+static inline pte_t pte_exprotect(pte_t pte)
16417+{
16418+#ifdef CONFIG_X86_PAE
16419+ if (__supported_pte_mask & _PAGE_NX)
16420+ return pte_set_flags(pte, _PAGE_NX);
16421+ else
16422+#endif
16423+ return pte_clear_flags(pte, _PAGE_USER);
16424 }
16425
16426 static inline pte_t pte_mkdirty(pte_t pte)
16427@@ -430,6 +495,16 @@ pte_t *populate_extra_pte(unsigned long vaddr);
16428 #endif
16429
16430 #ifndef __ASSEMBLY__
16431+
16432+#ifdef CONFIG_PAX_PER_CPU_PGD
16433+extern pgd_t cpu_pgd[NR_CPUS][2][PTRS_PER_PGD];
16434+enum cpu_pgd_type {kernel = 0, user = 1};
16435+static inline pgd_t *get_cpu_pgd(unsigned int cpu, enum cpu_pgd_type type)
16436+{
16437+ return cpu_pgd[cpu][type];
16438+}
16439+#endif
16440+
16441 #include <linux/mm_types.h>
16442 #include <linux/mmdebug.h>
16443 #include <linux/log2.h>
16444@@ -563,7 +638,7 @@ static inline unsigned long pud_page_vaddr(pud_t pud)
16445 * Currently stuck as a macro due to indirect forward reference to
16446 * linux/mmzone.h's __section_mem_map_addr() definition:
16447 */
16448-#define pud_page(pud) pfn_to_page(pud_val(pud) >> PAGE_SHIFT)
16449+#define pud_page(pud) pfn_to_page((pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT)
16450
16451 /* Find an entry in the second-level page table.. */
16452 static inline pmd_t *pmd_offset(pud_t *pud, unsigned long address)
16453@@ -603,7 +678,7 @@ static inline unsigned long pgd_page_vaddr(pgd_t pgd)
16454 * Currently stuck as a macro due to indirect forward reference to
16455 * linux/mmzone.h's __section_mem_map_addr() definition:
16456 */
16457-#define pgd_page(pgd) pfn_to_page(pgd_val(pgd) >> PAGE_SHIFT)
16458+#define pgd_page(pgd) pfn_to_page((pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT)
16459
16460 /* to find an entry in a page-table-directory. */
16461 static inline unsigned long pud_index(unsigned long address)
16462@@ -618,7 +693,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
16463
16464 static inline int pgd_bad(pgd_t pgd)
16465 {
16466- return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
16467+ return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
16468 }
16469
16470 static inline int pgd_none(pgd_t pgd)
16471@@ -641,7 +716,12 @@ static inline int pgd_none(pgd_t pgd)
16472 * pgd_offset() returns a (pgd_t *)
16473 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
16474 */
16475-#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
16476+#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
16477+
16478+#ifdef CONFIG_PAX_PER_CPU_PGD
16479+#define pgd_offset_cpu(cpu, type, address) (get_cpu_pgd(cpu, type) + pgd_index(address))
16480+#endif
16481+
16482 /*
16483 * a shortcut which implies the use of the kernel's pgd, instead
16484 * of a process's
16485@@ -652,6 +732,23 @@ static inline int pgd_none(pgd_t pgd)
16486 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
16487 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
16488
16489+#ifdef CONFIG_X86_32
16490+#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
16491+#else
16492+#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
16493+#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
16494+
16495+#ifdef CONFIG_PAX_MEMORY_UDEREF
16496+#ifdef __ASSEMBLY__
16497+#define pax_user_shadow_base pax_user_shadow_base(%rip)
16498+#else
16499+extern unsigned long pax_user_shadow_base;
16500+extern pgdval_t clone_pgd_mask;
16501+#endif
16502+#endif
16503+
16504+#endif
16505+
16506 #ifndef __ASSEMBLY__
16507
16508 extern int direct_gbpages;
16509@@ -818,11 +915,24 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
16510 * dst and src can be on the same page, but the range must not overlap,
16511 * and must not cross a page boundary.
16512 */
16513-static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
16514+static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
16515 {
16516- memcpy(dst, src, count * sizeof(pgd_t));
16517+ pax_open_kernel();
16518+ while (count--)
16519+ *dst++ = *src++;
16520+ pax_close_kernel();
16521 }
16522
16523+#ifdef CONFIG_PAX_PER_CPU_PGD
16524+extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
16525+#endif
16526+
16527+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16528+extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
16529+#else
16530+static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
16531+#endif
16532+
16533 #define PTE_SHIFT ilog2(PTRS_PER_PTE)
16534 static inline int page_level_shift(enum pg_level level)
16535 {
16536diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
16537index 9ee3221..b979c6b 100644
16538--- a/arch/x86/include/asm/pgtable_32.h
16539+++ b/arch/x86/include/asm/pgtable_32.h
16540@@ -25,9 +25,6 @@
16541 struct mm_struct;
16542 struct vm_area_struct;
16543
16544-extern pgd_t swapper_pg_dir[1024];
16545-extern pgd_t initial_page_table[1024];
16546-
16547 static inline void pgtable_cache_init(void) { }
16548 static inline void check_pgt_cache(void) { }
16549 void paging_init(void);
16550@@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
16551 # include <asm/pgtable-2level.h>
16552 #endif
16553
16554+extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
16555+extern pgd_t initial_page_table[PTRS_PER_PGD];
16556+#ifdef CONFIG_X86_PAE
16557+extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
16558+#endif
16559+
16560 #if defined(CONFIG_HIGHPTE)
16561 #define pte_offset_map(dir, address) \
16562 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
16563@@ -62,12 +65,17 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
16564 /* Clear a kernel PTE and flush it from the TLB */
16565 #define kpte_clear_flush(ptep, vaddr) \
16566 do { \
16567+ pax_open_kernel(); \
16568 pte_clear(&init_mm, (vaddr), (ptep)); \
16569+ pax_close_kernel(); \
16570 __flush_tlb_one((vaddr)); \
16571 } while (0)
16572
16573 #endif /* !__ASSEMBLY__ */
16574
16575+#define HAVE_ARCH_UNMAPPED_AREA
16576+#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
16577+
16578 /*
16579 * kern_addr_valid() is (1) for FLATMEM and (0) for
16580 * SPARSEMEM and DISCONTIGMEM
16581diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
16582index ed5903b..c7fe163 100644
16583--- a/arch/x86/include/asm/pgtable_32_types.h
16584+++ b/arch/x86/include/asm/pgtable_32_types.h
16585@@ -8,7 +8,7 @@
16586 */
16587 #ifdef CONFIG_X86_PAE
16588 # include <asm/pgtable-3level_types.h>
16589-# define PMD_SIZE (1UL << PMD_SHIFT)
16590+# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
16591 # define PMD_MASK (~(PMD_SIZE - 1))
16592 #else
16593 # include <asm/pgtable-2level_types.h>
16594@@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
16595 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
16596 #endif
16597
16598+#ifdef CONFIG_PAX_KERNEXEC
16599+#ifndef __ASSEMBLY__
16600+extern unsigned char MODULES_EXEC_VADDR[];
16601+extern unsigned char MODULES_EXEC_END[];
16602+#endif
16603+#include <asm/boot.h>
16604+#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
16605+#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
16606+#else
16607+#define ktla_ktva(addr) (addr)
16608+#define ktva_ktla(addr) (addr)
16609+#endif
16610+
16611 #define MODULES_VADDR VMALLOC_START
16612 #define MODULES_END VMALLOC_END
16613 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
16614diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
16615index e22c1db..23a625a 100644
16616--- a/arch/x86/include/asm/pgtable_64.h
16617+++ b/arch/x86/include/asm/pgtable_64.h
16618@@ -16,10 +16,14 @@
16619
16620 extern pud_t level3_kernel_pgt[512];
16621 extern pud_t level3_ident_pgt[512];
16622+extern pud_t level3_vmalloc_start_pgt[512];
16623+extern pud_t level3_vmalloc_end_pgt[512];
16624+extern pud_t level3_vmemmap_pgt[512];
16625+extern pud_t level2_vmemmap_pgt[512];
16626 extern pmd_t level2_kernel_pgt[512];
16627 extern pmd_t level2_fixmap_pgt[512];
16628-extern pmd_t level2_ident_pgt[512];
16629-extern pgd_t init_level4_pgt[];
16630+extern pmd_t level2_ident_pgt[512*2];
16631+extern pgd_t init_level4_pgt[512];
16632
16633 #define swapper_pg_dir init_level4_pgt
16634
16635@@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
16636
16637 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
16638 {
16639+ pax_open_kernel();
16640 *pmdp = pmd;
16641+ pax_close_kernel();
16642 }
16643
16644 static inline void native_pmd_clear(pmd_t *pmd)
16645@@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
16646
16647 static inline void native_set_pud(pud_t *pudp, pud_t pud)
16648 {
16649+ pax_open_kernel();
16650 *pudp = pud;
16651+ pax_close_kernel();
16652 }
16653
16654 static inline void native_pud_clear(pud_t *pud)
16655@@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
16656
16657 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
16658 {
16659+ pax_open_kernel();
16660+ *pgdp = pgd;
16661+ pax_close_kernel();
16662+}
16663+
16664+static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
16665+{
16666 *pgdp = pgd;
16667 }
16668
16669diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
16670index 2d88344..4679fc3 100644
16671--- a/arch/x86/include/asm/pgtable_64_types.h
16672+++ b/arch/x86/include/asm/pgtable_64_types.h
16673@@ -61,6 +61,11 @@ typedef struct { pteval_t pte; } pte_t;
16674 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
16675 #define MODULES_END _AC(0xffffffffff000000, UL)
16676 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
16677+#define MODULES_EXEC_VADDR MODULES_VADDR
16678+#define MODULES_EXEC_END MODULES_END
16679+
16680+#define ktla_ktva(addr) (addr)
16681+#define ktva_ktla(addr) (addr)
16682
16683 #define EARLY_DYNAMIC_PAGE_TABLES 64
16684
16685diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
16686index 0ecac25..306c276 100644
16687--- a/arch/x86/include/asm/pgtable_types.h
16688+++ b/arch/x86/include/asm/pgtable_types.h
16689@@ -16,13 +16,12 @@
16690 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
16691 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
16692 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
16693-#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
16694+#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
16695 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
16696 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
16697 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
16698-#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
16699-#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
16700-#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
16701+#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
16702+#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
16703 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
16704
16705 /* If _PAGE_BIT_PRESENT is clear, we use these: */
16706@@ -40,7 +39,6 @@
16707 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
16708 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
16709 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
16710-#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
16711 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
16712 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
16713 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
16714@@ -87,8 +85,10 @@
16715
16716 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
16717 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
16718-#else
16719+#elif defined(CONFIG_KMEMCHECK)
16720 #define _PAGE_NX (_AT(pteval_t, 0))
16721+#else
16722+#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
16723 #endif
16724
16725 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
16726@@ -146,6 +146,9 @@
16727 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
16728 _PAGE_ACCESSED)
16729
16730+#define PAGE_READONLY_NOEXEC PAGE_READONLY
16731+#define PAGE_SHARED_NOEXEC PAGE_SHARED
16732+
16733 #define __PAGE_KERNEL_EXEC \
16734 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
16735 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
16736@@ -156,7 +159,7 @@
16737 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
16738 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
16739 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
16740-#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
16741+#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
16742 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
16743 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
16744 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
16745@@ -218,8 +221,8 @@
16746 * bits are combined, this will alow user to access the high address mapped
16747 * VDSO in the presence of CONFIG_COMPAT_VDSO
16748 */
16749-#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
16750-#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
16751+#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
16752+#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
16753 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
16754 #endif
16755
16756@@ -257,7 +260,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
16757 {
16758 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
16759 }
16760+#endif
16761
16762+#if PAGETABLE_LEVELS == 3
16763+#include <asm-generic/pgtable-nopud.h>
16764+#endif
16765+
16766+#if PAGETABLE_LEVELS == 2
16767+#include <asm-generic/pgtable-nopmd.h>
16768+#endif
16769+
16770+#ifndef __ASSEMBLY__
16771 #if PAGETABLE_LEVELS > 3
16772 typedef struct { pudval_t pud; } pud_t;
16773
16774@@ -271,8 +284,6 @@ static inline pudval_t native_pud_val(pud_t pud)
16775 return pud.pud;
16776 }
16777 #else
16778-#include <asm-generic/pgtable-nopud.h>
16779-
16780 static inline pudval_t native_pud_val(pud_t pud)
16781 {
16782 return native_pgd_val(pud.pgd);
16783@@ -292,8 +303,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
16784 return pmd.pmd;
16785 }
16786 #else
16787-#include <asm-generic/pgtable-nopmd.h>
16788-
16789 static inline pmdval_t native_pmd_val(pmd_t pmd)
16790 {
16791 return native_pgd_val(pmd.pud.pgd);
16792@@ -333,7 +342,6 @@ typedef struct page *pgtable_t;
16793
16794 extern pteval_t __supported_pte_mask;
16795 extern void set_nx(void);
16796-extern int nx_enabled;
16797
16798 #define pgprot_writecombine pgprot_writecombine
16799 extern pgprot_t pgprot_writecombine(pgprot_t prot);
16800diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
16801index 987c75e..2723054 100644
16802--- a/arch/x86/include/asm/processor.h
16803+++ b/arch/x86/include/asm/processor.h
16804@@ -199,9 +199,21 @@ static inline void native_cpuid(unsigned int *eax, unsigned int *ebx,
16805 : "memory");
16806 }
16807
16808+/* invpcid (%rdx),%rax */
16809+#define __ASM_INVPCID ".byte 0x66,0x0f,0x38,0x82,0x02"
16810+
16811+#define INVPCID_SINGLE_ADDRESS 0UL
16812+#define INVPCID_SINGLE_CONTEXT 1UL
16813+#define INVPCID_ALL_GLOBAL 2UL
16814+#define INVPCID_ALL_MONGLOBAL 3UL
16815+
16816+#define PCID_KERNEL 0UL
16817+#define PCID_USER 1UL
16818+#define PCID_NOFLUSH (1UL << 63)
16819+
16820 static inline void load_cr3(pgd_t *pgdir)
16821 {
16822- write_cr3(__pa(pgdir));
16823+ write_cr3(__pa(pgdir) | PCID_KERNEL);
16824 }
16825
16826 #ifdef CONFIG_X86_32
16827@@ -283,7 +295,7 @@ struct tss_struct {
16828
16829 } ____cacheline_aligned;
16830
16831-DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
16832+extern struct tss_struct init_tss[NR_CPUS];
16833
16834 /*
16835 * Save the original ist values for checking stack pointers during debugging
16836@@ -453,6 +465,7 @@ struct thread_struct {
16837 unsigned short ds;
16838 unsigned short fsindex;
16839 unsigned short gsindex;
16840+ unsigned short ss;
16841 #endif
16842 #ifdef CONFIG_X86_32
16843 unsigned long ip;
16844@@ -553,29 +566,8 @@ static inline void load_sp0(struct tss_struct *tss,
16845 extern unsigned long mmu_cr4_features;
16846 extern u32 *trampoline_cr4_features;
16847
16848-static inline void set_in_cr4(unsigned long mask)
16849-{
16850- unsigned long cr4;
16851-
16852- mmu_cr4_features |= mask;
16853- if (trampoline_cr4_features)
16854- *trampoline_cr4_features = mmu_cr4_features;
16855- cr4 = read_cr4();
16856- cr4 |= mask;
16857- write_cr4(cr4);
16858-}
16859-
16860-static inline void clear_in_cr4(unsigned long mask)
16861-{
16862- unsigned long cr4;
16863-
16864- mmu_cr4_features &= ~mask;
16865- if (trampoline_cr4_features)
16866- *trampoline_cr4_features = mmu_cr4_features;
16867- cr4 = read_cr4();
16868- cr4 &= ~mask;
16869- write_cr4(cr4);
16870-}
16871+extern void set_in_cr4(unsigned long mask);
16872+extern void clear_in_cr4(unsigned long mask);
16873
16874 typedef struct {
16875 unsigned long seg;
16876@@ -824,11 +816,18 @@ static inline void spin_lock_prefetch(const void *x)
16877 */
16878 #define TASK_SIZE PAGE_OFFSET
16879 #define TASK_SIZE_MAX TASK_SIZE
16880+
16881+#ifdef CONFIG_PAX_SEGMEXEC
16882+#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
16883+#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
16884+#else
16885 #define STACK_TOP TASK_SIZE
16886-#define STACK_TOP_MAX STACK_TOP
16887+#endif
16888+
16889+#define STACK_TOP_MAX TASK_SIZE
16890
16891 #define INIT_THREAD { \
16892- .sp0 = sizeof(init_stack) + (long)&init_stack, \
16893+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
16894 .vm86_info = NULL, \
16895 .sysenter_cs = __KERNEL_CS, \
16896 .io_bitmap_ptr = NULL, \
16897@@ -842,7 +841,7 @@ static inline void spin_lock_prefetch(const void *x)
16898 */
16899 #define INIT_TSS { \
16900 .x86_tss = { \
16901- .sp0 = sizeof(init_stack) + (long)&init_stack, \
16902+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
16903 .ss0 = __KERNEL_DS, \
16904 .ss1 = __KERNEL_CS, \
16905 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
16906@@ -853,11 +852,7 @@ static inline void spin_lock_prefetch(const void *x)
16907 extern unsigned long thread_saved_pc(struct task_struct *tsk);
16908
16909 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
16910-#define KSTK_TOP(info) \
16911-({ \
16912- unsigned long *__ptr = (unsigned long *)(info); \
16913- (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
16914-})
16915+#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
16916
16917 /*
16918 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
16919@@ -872,7 +867,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
16920 #define task_pt_regs(task) \
16921 ({ \
16922 struct pt_regs *__regs__; \
16923- __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
16924+ __regs__ = (struct pt_regs *)((task)->thread.sp0); \
16925 __regs__ - 1; \
16926 })
16927
16928@@ -882,13 +877,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
16929 /*
16930 * User space process size. 47bits minus one guard page.
16931 */
16932-#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
16933+#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
16934
16935 /* This decides where the kernel will search for a free chunk of vm
16936 * space during mmap's.
16937 */
16938 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
16939- 0xc0000000 : 0xFFFFe000)
16940+ 0xc0000000 : 0xFFFFf000)
16941
16942 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
16943 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
16944@@ -899,11 +894,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
16945 #define STACK_TOP_MAX TASK_SIZE_MAX
16946
16947 #define INIT_THREAD { \
16948- .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
16949+ .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
16950 }
16951
16952 #define INIT_TSS { \
16953- .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
16954+ .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
16955 }
16956
16957 /*
16958@@ -931,6 +926,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
16959 */
16960 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
16961
16962+#ifdef CONFIG_PAX_SEGMEXEC
16963+#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
16964+#endif
16965+
16966 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
16967
16968 /* Get/set a process' ability to use the timestamp counter instruction */
16969@@ -957,7 +956,7 @@ static inline uint32_t hypervisor_cpuid_base(const char *sig, uint32_t leaves)
16970 return 0;
16971 }
16972
16973-extern unsigned long arch_align_stack(unsigned long sp);
16974+#define arch_align_stack(x) ((x) & ~0xfUL)
16975 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
16976
16977 void default_idle(void);
16978@@ -967,6 +966,6 @@ bool xen_set_default_idle(void);
16979 #define xen_set_default_idle 0
16980 #endif
16981
16982-void stop_this_cpu(void *dummy);
16983+void stop_this_cpu(void *dummy) __noreturn;
16984 void df_debug(struct pt_regs *regs, long error_code);
16985 #endif /* _ASM_X86_PROCESSOR_H */
16986diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
16987index 942a086..6c26446 100644
16988--- a/arch/x86/include/asm/ptrace.h
16989+++ b/arch/x86/include/asm/ptrace.h
16990@@ -85,28 +85,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
16991 }
16992
16993 /*
16994- * user_mode_vm(regs) determines whether a register set came from user mode.
16995+ * user_mode(regs) determines whether a register set came from user mode.
16996 * This is true if V8086 mode was enabled OR if the register set was from
16997 * protected mode with RPL-3 CS value. This tricky test checks that with
16998 * one comparison. Many places in the kernel can bypass this full check
16999- * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
17000+ * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
17001+ * be used.
17002 */
17003-static inline int user_mode(struct pt_regs *regs)
17004+static inline int user_mode_novm(struct pt_regs *regs)
17005 {
17006 #ifdef CONFIG_X86_32
17007 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
17008 #else
17009- return !!(regs->cs & 3);
17010+ return !!(regs->cs & SEGMENT_RPL_MASK);
17011 #endif
17012 }
17013
17014-static inline int user_mode_vm(struct pt_regs *regs)
17015+static inline int user_mode(struct pt_regs *regs)
17016 {
17017 #ifdef CONFIG_X86_32
17018 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
17019 USER_RPL;
17020 #else
17021- return user_mode(regs);
17022+ return user_mode_novm(regs);
17023 #endif
17024 }
17025
17026@@ -122,15 +123,16 @@ static inline int v8086_mode(struct pt_regs *regs)
17027 #ifdef CONFIG_X86_64
17028 static inline bool user_64bit_mode(struct pt_regs *regs)
17029 {
17030+ unsigned long cs = regs->cs & 0xffff;
17031 #ifndef CONFIG_PARAVIRT
17032 /*
17033 * On non-paravirt systems, this is the only long mode CPL 3
17034 * selector. We do not allow long mode selectors in the LDT.
17035 */
17036- return regs->cs == __USER_CS;
17037+ return cs == __USER_CS;
17038 #else
17039 /* Headers are too twisted for this to go in paravirt.h. */
17040- return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
17041+ return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
17042 #endif
17043 }
17044
17045@@ -181,9 +183,11 @@ static inline unsigned long regs_get_register(struct pt_regs *regs,
17046 * Traps from the kernel do not save sp and ss.
17047 * Use the helper function to retrieve sp.
17048 */
17049- if (offset == offsetof(struct pt_regs, sp) &&
17050- regs->cs == __KERNEL_CS)
17051- return kernel_stack_pointer(regs);
17052+ if (offset == offsetof(struct pt_regs, sp)) {
17053+ unsigned long cs = regs->cs & 0xffff;
17054+ if (cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS)
17055+ return kernel_stack_pointer(regs);
17056+ }
17057 #endif
17058 return *(unsigned long *)((unsigned long)regs + offset);
17059 }
17060diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
17061index 9c6b890..5305f53 100644
17062--- a/arch/x86/include/asm/realmode.h
17063+++ b/arch/x86/include/asm/realmode.h
17064@@ -22,16 +22,14 @@ struct real_mode_header {
17065 #endif
17066 /* APM/BIOS reboot */
17067 u32 machine_real_restart_asm;
17068-#ifdef CONFIG_X86_64
17069 u32 machine_real_restart_seg;
17070-#endif
17071 };
17072
17073 /* This must match data at trampoline_32/64.S */
17074 struct trampoline_header {
17075 #ifdef CONFIG_X86_32
17076 u32 start;
17077- u16 gdt_pad;
17078+ u16 boot_cs;
17079 u16 gdt_limit;
17080 u32 gdt_base;
17081 #else
17082diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
17083index a82c4f1..ac45053 100644
17084--- a/arch/x86/include/asm/reboot.h
17085+++ b/arch/x86/include/asm/reboot.h
17086@@ -6,13 +6,13 @@
17087 struct pt_regs;
17088
17089 struct machine_ops {
17090- void (*restart)(char *cmd);
17091- void (*halt)(void);
17092- void (*power_off)(void);
17093+ void (* __noreturn restart)(char *cmd);
17094+ void (* __noreturn halt)(void);
17095+ void (* __noreturn power_off)(void);
17096 void (*shutdown)(void);
17097 void (*crash_shutdown)(struct pt_regs *);
17098- void (*emergency_restart)(void);
17099-};
17100+ void (* __noreturn emergency_restart)(void);
17101+} __no_const;
17102
17103 extern struct machine_ops machine_ops;
17104
17105diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
17106index cad82c9..2e5c5c1 100644
17107--- a/arch/x86/include/asm/rwsem.h
17108+++ b/arch/x86/include/asm/rwsem.h
17109@@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
17110 {
17111 asm volatile("# beginning down_read\n\t"
17112 LOCK_PREFIX _ASM_INC "(%1)\n\t"
17113+
17114+#ifdef CONFIG_PAX_REFCOUNT
17115+ "jno 0f\n"
17116+ LOCK_PREFIX _ASM_DEC "(%1)\n"
17117+ "int $4\n0:\n"
17118+ _ASM_EXTABLE(0b, 0b)
17119+#endif
17120+
17121 /* adds 0x00000001 */
17122 " jns 1f\n"
17123 " call call_rwsem_down_read_failed\n"
17124@@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
17125 "1:\n\t"
17126 " mov %1,%2\n\t"
17127 " add %3,%2\n\t"
17128+
17129+#ifdef CONFIG_PAX_REFCOUNT
17130+ "jno 0f\n"
17131+ "sub %3,%2\n"
17132+ "int $4\n0:\n"
17133+ _ASM_EXTABLE(0b, 0b)
17134+#endif
17135+
17136 " jle 2f\n\t"
17137 LOCK_PREFIX " cmpxchg %2,%0\n\t"
17138 " jnz 1b\n\t"
17139@@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
17140 long tmp;
17141 asm volatile("# beginning down_write\n\t"
17142 LOCK_PREFIX " xadd %1,(%2)\n\t"
17143+
17144+#ifdef CONFIG_PAX_REFCOUNT
17145+ "jno 0f\n"
17146+ "mov %1,(%2)\n"
17147+ "int $4\n0:\n"
17148+ _ASM_EXTABLE(0b, 0b)
17149+#endif
17150+
17151 /* adds 0xffff0001, returns the old value */
17152 " test " __ASM_SEL(%w1,%k1) "," __ASM_SEL(%w1,%k1) "\n\t"
17153 /* was the active mask 0 before? */
17154@@ -155,6 +179,14 @@ static inline void __up_read(struct rw_semaphore *sem)
17155 long tmp;
17156 asm volatile("# beginning __up_read\n\t"
17157 LOCK_PREFIX " xadd %1,(%2)\n\t"
17158+
17159+#ifdef CONFIG_PAX_REFCOUNT
17160+ "jno 0f\n"
17161+ "mov %1,(%2)\n"
17162+ "int $4\n0:\n"
17163+ _ASM_EXTABLE(0b, 0b)
17164+#endif
17165+
17166 /* subtracts 1, returns the old value */
17167 " jns 1f\n\t"
17168 " call call_rwsem_wake\n" /* expects old value in %edx */
17169@@ -173,6 +205,14 @@ static inline void __up_write(struct rw_semaphore *sem)
17170 long tmp;
17171 asm volatile("# beginning __up_write\n\t"
17172 LOCK_PREFIX " xadd %1,(%2)\n\t"
17173+
17174+#ifdef CONFIG_PAX_REFCOUNT
17175+ "jno 0f\n"
17176+ "mov %1,(%2)\n"
17177+ "int $4\n0:\n"
17178+ _ASM_EXTABLE(0b, 0b)
17179+#endif
17180+
17181 /* subtracts 0xffff0001, returns the old value */
17182 " jns 1f\n\t"
17183 " call call_rwsem_wake\n" /* expects old value in %edx */
17184@@ -190,6 +230,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
17185 {
17186 asm volatile("# beginning __downgrade_write\n\t"
17187 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
17188+
17189+#ifdef CONFIG_PAX_REFCOUNT
17190+ "jno 0f\n"
17191+ LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
17192+ "int $4\n0:\n"
17193+ _ASM_EXTABLE(0b, 0b)
17194+#endif
17195+
17196 /*
17197 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
17198 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
17199@@ -208,7 +256,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
17200 */
17201 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
17202 {
17203- asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
17204+ asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
17205+
17206+#ifdef CONFIG_PAX_REFCOUNT
17207+ "jno 0f\n"
17208+ LOCK_PREFIX _ASM_SUB "%1,%0\n"
17209+ "int $4\n0:\n"
17210+ _ASM_EXTABLE(0b, 0b)
17211+#endif
17212+
17213 : "+m" (sem->count)
17214 : "er" (delta));
17215 }
17216@@ -218,7 +274,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
17217 */
17218 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
17219 {
17220- return delta + xadd(&sem->count, delta);
17221+ return delta + xadd_check_overflow(&sem->count, delta);
17222 }
17223
17224 #endif /* __KERNEL__ */
17225diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
17226index c48a950..bc40804 100644
17227--- a/arch/x86/include/asm/segment.h
17228+++ b/arch/x86/include/asm/segment.h
17229@@ -64,10 +64,15 @@
17230 * 26 - ESPFIX small SS
17231 * 27 - per-cpu [ offset to per-cpu data area ]
17232 * 28 - stack_canary-20 [ for stack protector ]
17233- * 29 - unused
17234- * 30 - unused
17235+ * 29 - PCI BIOS CS
17236+ * 30 - PCI BIOS DS
17237 * 31 - TSS for double fault handler
17238 */
17239+#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
17240+#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
17241+#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
17242+#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
17243+
17244 #define GDT_ENTRY_TLS_MIN 6
17245 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
17246
17247@@ -79,6 +84,8 @@
17248
17249 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
17250
17251+#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
17252+
17253 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
17254
17255 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
17256@@ -104,6 +111,12 @@
17257 #define __KERNEL_STACK_CANARY 0
17258 #endif
17259
17260+#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
17261+#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
17262+
17263+#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
17264+#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
17265+
17266 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
17267
17268 /*
17269@@ -141,7 +154,7 @@
17270 */
17271
17272 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
17273-#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
17274+#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
17275
17276
17277 #else
17278@@ -165,6 +178,8 @@
17279 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
17280 #define __USER32_DS __USER_DS
17281
17282+#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
17283+
17284 #define GDT_ENTRY_TSS 8 /* needs two entries */
17285 #define GDT_ENTRY_LDT 10 /* needs two entries */
17286 #define GDT_ENTRY_TLS_MIN 12
17287@@ -173,6 +188,8 @@
17288 #define GDT_ENTRY_PER_CPU 15 /* Abused to load per CPU data from limit */
17289 #define __PER_CPU_SEG (GDT_ENTRY_PER_CPU * 8 + 3)
17290
17291+#define GDT_ENTRY_UDEREF_KERNEL_DS 16
17292+
17293 /* TLS indexes for 64bit - hardcoded in arch_prctl */
17294 #define FS_TLS 0
17295 #define GS_TLS 1
17296@@ -180,12 +197,14 @@
17297 #define GS_TLS_SEL ((GDT_ENTRY_TLS_MIN+GS_TLS)*8 + 3)
17298 #define FS_TLS_SEL ((GDT_ENTRY_TLS_MIN+FS_TLS)*8 + 3)
17299
17300-#define GDT_ENTRIES 16
17301+#define GDT_ENTRIES 17
17302
17303 #endif
17304
17305 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
17306+#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
17307 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
17308+#define __UDEREF_KERNEL_DS (GDT_ENTRY_UDEREF_KERNEL_DS*8)
17309 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
17310 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
17311 #ifndef CONFIG_PARAVIRT
17312@@ -265,7 +284,7 @@ static inline unsigned long get_limit(unsigned long segment)
17313 {
17314 unsigned long __limit;
17315 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
17316- return __limit + 1;
17317+ return __limit;
17318 }
17319
17320 #endif /* !__ASSEMBLY__ */
17321diff --git a/arch/x86/include/asm/smap.h b/arch/x86/include/asm/smap.h
17322index 8d3120f..352b440 100644
17323--- a/arch/x86/include/asm/smap.h
17324+++ b/arch/x86/include/asm/smap.h
17325@@ -25,11 +25,40 @@
17326
17327 #include <asm/alternative-asm.h>
17328
17329+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17330+#define ASM_PAX_OPEN_USERLAND \
17331+ 661: jmp 663f; \
17332+ .pushsection .altinstr_replacement, "a" ; \
17333+ 662: pushq %rax; nop; \
17334+ .popsection ; \
17335+ .pushsection .altinstructions, "a" ; \
17336+ altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
17337+ .popsection ; \
17338+ call __pax_open_userland; \
17339+ popq %rax; \
17340+ 663:
17341+
17342+#define ASM_PAX_CLOSE_USERLAND \
17343+ 661: jmp 663f; \
17344+ .pushsection .altinstr_replacement, "a" ; \
17345+ 662: pushq %rax; nop; \
17346+ .popsection; \
17347+ .pushsection .altinstructions, "a" ; \
17348+ altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
17349+ .popsection; \
17350+ call __pax_close_userland; \
17351+ popq %rax; \
17352+ 663:
17353+#else
17354+#define ASM_PAX_OPEN_USERLAND
17355+#define ASM_PAX_CLOSE_USERLAND
17356+#endif
17357+
17358 #ifdef CONFIG_X86_SMAP
17359
17360 #define ASM_CLAC \
17361 661: ASM_NOP3 ; \
17362- .pushsection .altinstr_replacement, "ax" ; \
17363+ .pushsection .altinstr_replacement, "a" ; \
17364 662: __ASM_CLAC ; \
17365 .popsection ; \
17366 .pushsection .altinstructions, "a" ; \
17367@@ -38,7 +67,7 @@
17368
17369 #define ASM_STAC \
17370 661: ASM_NOP3 ; \
17371- .pushsection .altinstr_replacement, "ax" ; \
17372+ .pushsection .altinstr_replacement, "a" ; \
17373 662: __ASM_STAC ; \
17374 .popsection ; \
17375 .pushsection .altinstructions, "a" ; \
17376@@ -56,6 +85,37 @@
17377
17378 #include <asm/alternative.h>
17379
17380+#define __HAVE_ARCH_PAX_OPEN_USERLAND
17381+#define __HAVE_ARCH_PAX_CLOSE_USERLAND
17382+
17383+extern void __pax_open_userland(void);
17384+static __always_inline unsigned long pax_open_userland(void)
17385+{
17386+
17387+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17388+ asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[open]", X86_FEATURE_STRONGUDEREF)
17389+ :
17390+ : [open] "i" (__pax_open_userland)
17391+ : "memory", "rax");
17392+#endif
17393+
17394+ return 0;
17395+}
17396+
17397+extern void __pax_close_userland(void);
17398+static __always_inline unsigned long pax_close_userland(void)
17399+{
17400+
17401+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17402+ asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[close]", X86_FEATURE_STRONGUDEREF)
17403+ :
17404+ : [close] "i" (__pax_close_userland)
17405+ : "memory", "rax");
17406+#endif
17407+
17408+ return 0;
17409+}
17410+
17411 #ifdef CONFIG_X86_SMAP
17412
17413 static __always_inline void clac(void)
17414diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
17415index 4137890..03fa172 100644
17416--- a/arch/x86/include/asm/smp.h
17417+++ b/arch/x86/include/asm/smp.h
17418@@ -36,7 +36,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
17419 /* cpus sharing the last level cache: */
17420 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
17421 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
17422-DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
17423+DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
17424
17425 static inline struct cpumask *cpu_sibling_mask(int cpu)
17426 {
17427@@ -79,7 +79,7 @@ struct smp_ops {
17428
17429 void (*send_call_func_ipi)(const struct cpumask *mask);
17430 void (*send_call_func_single_ipi)(int cpu);
17431-};
17432+} __no_const;
17433
17434 /* Globals due to paravirt */
17435 extern void set_cpu_sibling_map(int cpu);
17436@@ -191,14 +191,8 @@ extern unsigned disabled_cpus;
17437 extern int safe_smp_processor_id(void);
17438
17439 #elif defined(CONFIG_X86_64_SMP)
17440-#define raw_smp_processor_id() (this_cpu_read(cpu_number))
17441-
17442-#define stack_smp_processor_id() \
17443-({ \
17444- struct thread_info *ti; \
17445- __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
17446- ti->cpu; \
17447-})
17448+#define raw_smp_processor_id() (this_cpu_read(cpu_number))
17449+#define stack_smp_processor_id() raw_smp_processor_id()
17450 #define safe_smp_processor_id() smp_processor_id()
17451
17452 #endif
17453diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
17454index bf156de..1a782ab 100644
17455--- a/arch/x86/include/asm/spinlock.h
17456+++ b/arch/x86/include/asm/spinlock.h
17457@@ -223,6 +223,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
17458 static inline void arch_read_lock(arch_rwlock_t *rw)
17459 {
17460 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
17461+
17462+#ifdef CONFIG_PAX_REFCOUNT
17463+ "jno 0f\n"
17464+ LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
17465+ "int $4\n0:\n"
17466+ _ASM_EXTABLE(0b, 0b)
17467+#endif
17468+
17469 "jns 1f\n"
17470 "call __read_lock_failed\n\t"
17471 "1:\n"
17472@@ -232,6 +240,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
17473 static inline void arch_write_lock(arch_rwlock_t *rw)
17474 {
17475 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
17476+
17477+#ifdef CONFIG_PAX_REFCOUNT
17478+ "jno 0f\n"
17479+ LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
17480+ "int $4\n0:\n"
17481+ _ASM_EXTABLE(0b, 0b)
17482+#endif
17483+
17484 "jz 1f\n"
17485 "call __write_lock_failed\n\t"
17486 "1:\n"
17487@@ -261,13 +277,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
17488
17489 static inline void arch_read_unlock(arch_rwlock_t *rw)
17490 {
17491- asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
17492+ asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
17493+
17494+#ifdef CONFIG_PAX_REFCOUNT
17495+ "jno 0f\n"
17496+ LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
17497+ "int $4\n0:\n"
17498+ _ASM_EXTABLE(0b, 0b)
17499+#endif
17500+
17501 :"+m" (rw->lock) : : "memory");
17502 }
17503
17504 static inline void arch_write_unlock(arch_rwlock_t *rw)
17505 {
17506- asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
17507+ asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
17508+
17509+#ifdef CONFIG_PAX_REFCOUNT
17510+ "jno 0f\n"
17511+ LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
17512+ "int $4\n0:\n"
17513+ _ASM_EXTABLE(0b, 0b)
17514+#endif
17515+
17516 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
17517 }
17518
17519diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
17520index 6a99859..03cb807 100644
17521--- a/arch/x86/include/asm/stackprotector.h
17522+++ b/arch/x86/include/asm/stackprotector.h
17523@@ -47,7 +47,7 @@
17524 * head_32 for boot CPU and setup_per_cpu_areas() for others.
17525 */
17526 #define GDT_STACK_CANARY_INIT \
17527- [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
17528+ [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
17529
17530 /*
17531 * Initialize the stackprotector canary value.
17532@@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
17533
17534 static inline void load_stack_canary_segment(void)
17535 {
17536-#ifdef CONFIG_X86_32
17537+#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
17538 asm volatile ("mov %0, %%gs" : : "r" (0));
17539 #endif
17540 }
17541diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
17542index 70bbe39..4ae2bd4 100644
17543--- a/arch/x86/include/asm/stacktrace.h
17544+++ b/arch/x86/include/asm/stacktrace.h
17545@@ -11,28 +11,20 @@
17546
17547 extern int kstack_depth_to_print;
17548
17549-struct thread_info;
17550+struct task_struct;
17551 struct stacktrace_ops;
17552
17553-typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
17554- unsigned long *stack,
17555- unsigned long bp,
17556- const struct stacktrace_ops *ops,
17557- void *data,
17558- unsigned long *end,
17559- int *graph);
17560+typedef unsigned long walk_stack_t(struct task_struct *task,
17561+ void *stack_start,
17562+ unsigned long *stack,
17563+ unsigned long bp,
17564+ const struct stacktrace_ops *ops,
17565+ void *data,
17566+ unsigned long *end,
17567+ int *graph);
17568
17569-extern unsigned long
17570-print_context_stack(struct thread_info *tinfo,
17571- unsigned long *stack, unsigned long bp,
17572- const struct stacktrace_ops *ops, void *data,
17573- unsigned long *end, int *graph);
17574-
17575-extern unsigned long
17576-print_context_stack_bp(struct thread_info *tinfo,
17577- unsigned long *stack, unsigned long bp,
17578- const struct stacktrace_ops *ops, void *data,
17579- unsigned long *end, int *graph);
17580+extern walk_stack_t print_context_stack;
17581+extern walk_stack_t print_context_stack_bp;
17582
17583 /* Generic stack tracer with callbacks */
17584
17585@@ -40,7 +32,7 @@ struct stacktrace_ops {
17586 void (*address)(void *data, unsigned long address, int reliable);
17587 /* On negative return stop dumping */
17588 int (*stack)(void *data, char *name);
17589- walk_stack_t walk_stack;
17590+ walk_stack_t *walk_stack;
17591 };
17592
17593 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
17594diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
17595index d7f3b3b..3cc39f1 100644
17596--- a/arch/x86/include/asm/switch_to.h
17597+++ b/arch/x86/include/asm/switch_to.h
17598@@ -108,7 +108,7 @@ do { \
17599 "call __switch_to\n\t" \
17600 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
17601 __switch_canary \
17602- "movq %P[thread_info](%%rsi),%%r8\n\t" \
17603+ "movq "__percpu_arg([thread_info])",%%r8\n\t" \
17604 "movq %%rax,%%rdi\n\t" \
17605 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
17606 "jnz ret_from_fork\n\t" \
17607@@ -119,7 +119,7 @@ do { \
17608 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
17609 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
17610 [_tif_fork] "i" (_TIF_FORK), \
17611- [thread_info] "i" (offsetof(struct task_struct, stack)), \
17612+ [thread_info] "m" (current_tinfo), \
17613 [current_task] "m" (current_task) \
17614 __switch_canary_iparam \
17615 : "memory", "cc" __EXTRA_CLOBBER)
17616diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
17617index 2781119..618b59b 100644
17618--- a/arch/x86/include/asm/thread_info.h
17619+++ b/arch/x86/include/asm/thread_info.h
17620@@ -10,6 +10,7 @@
17621 #include <linux/compiler.h>
17622 #include <asm/page.h>
17623 #include <asm/types.h>
17624+#include <asm/percpu.h>
17625
17626 /*
17627 * low level task data that entry.S needs immediate access to
17628@@ -23,7 +24,6 @@ struct exec_domain;
17629 #include <linux/atomic.h>
17630
17631 struct thread_info {
17632- struct task_struct *task; /* main task structure */
17633 struct exec_domain *exec_domain; /* execution domain */
17634 __u32 flags; /* low level flags */
17635 __u32 status; /* thread synchronous flags */
17636@@ -33,19 +33,13 @@ struct thread_info {
17637 mm_segment_t addr_limit;
17638 struct restart_block restart_block;
17639 void __user *sysenter_return;
17640-#ifdef CONFIG_X86_32
17641- unsigned long previous_esp; /* ESP of the previous stack in
17642- case of nested (IRQ) stacks
17643- */
17644- __u8 supervisor_stack[0];
17645-#endif
17646+ unsigned long lowest_stack;
17647 unsigned int sig_on_uaccess_error:1;
17648 unsigned int uaccess_err:1; /* uaccess failed */
17649 };
17650
17651-#define INIT_THREAD_INFO(tsk) \
17652+#define INIT_THREAD_INFO \
17653 { \
17654- .task = &tsk, \
17655 .exec_domain = &default_exec_domain, \
17656 .flags = 0, \
17657 .cpu = 0, \
17658@@ -56,7 +50,7 @@ struct thread_info {
17659 }, \
17660 }
17661
17662-#define init_thread_info (init_thread_union.thread_info)
17663+#define init_thread_info (init_thread_union.stack)
17664 #define init_stack (init_thread_union.stack)
17665
17666 #else /* !__ASSEMBLY__ */
17667@@ -96,6 +90,7 @@ struct thread_info {
17668 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
17669 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
17670 #define TIF_X32 30 /* 32-bit native x86-64 binary */
17671+#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
17672
17673 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
17674 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
17675@@ -119,17 +114,18 @@ struct thread_info {
17676 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
17677 #define _TIF_ADDR32 (1 << TIF_ADDR32)
17678 #define _TIF_X32 (1 << TIF_X32)
17679+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
17680
17681 /* work to do in syscall_trace_enter() */
17682 #define _TIF_WORK_SYSCALL_ENTRY \
17683 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
17684 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
17685- _TIF_NOHZ)
17686+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
17687
17688 /* work to do in syscall_trace_leave() */
17689 #define _TIF_WORK_SYSCALL_EXIT \
17690 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
17691- _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
17692+ _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
17693
17694 /* work to do on interrupt/exception return */
17695 #define _TIF_WORK_MASK \
17696@@ -140,7 +136,7 @@ struct thread_info {
17697 /* work to do on any return to user space */
17698 #define _TIF_ALLWORK_MASK \
17699 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
17700- _TIF_NOHZ)
17701+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
17702
17703 /* Only used for 64 bit */
17704 #define _TIF_DO_NOTIFY_MASK \
17705@@ -156,45 +152,40 @@ struct thread_info {
17706
17707 #define PREEMPT_ACTIVE 0x10000000
17708
17709-#ifdef CONFIG_X86_32
17710-
17711-#define STACK_WARN (THREAD_SIZE/8)
17712-/*
17713- * macros/functions for gaining access to the thread information structure
17714- *
17715- * preempt_count needs to be 1 initially, until the scheduler is functional.
17716- */
17717-#ifndef __ASSEMBLY__
17718-
17719-
17720-/* how to get the current stack pointer from C */
17721-register unsigned long current_stack_pointer asm("esp") __used;
17722-
17723-/* how to get the thread information struct from C */
17724-static inline struct thread_info *current_thread_info(void)
17725-{
17726- return (struct thread_info *)
17727- (current_stack_pointer & ~(THREAD_SIZE - 1));
17728-}
17729-
17730-#else /* !__ASSEMBLY__ */
17731-
17732+#ifdef __ASSEMBLY__
17733 /* how to get the thread information struct from ASM */
17734 #define GET_THREAD_INFO(reg) \
17735- movl $-THREAD_SIZE, reg; \
17736- andl %esp, reg
17737+ mov PER_CPU_VAR(current_tinfo), reg
17738
17739 /* use this one if reg already contains %esp */
17740-#define GET_THREAD_INFO_WITH_ESP(reg) \
17741- andl $-THREAD_SIZE, reg
17742+#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
17743+#else
17744+/* how to get the thread information struct from C */
17745+DECLARE_PER_CPU(struct thread_info *, current_tinfo);
17746+
17747+static __always_inline struct thread_info *current_thread_info(void)
17748+{
17749+ return this_cpu_read_stable(current_tinfo);
17750+}
17751+#endif
17752+
17753+#ifdef CONFIG_X86_32
17754+
17755+#define STACK_WARN (THREAD_SIZE/8)
17756+/*
17757+ * macros/functions for gaining access to the thread information structure
17758+ *
17759+ * preempt_count needs to be 1 initially, until the scheduler is functional.
17760+ */
17761+#ifndef __ASSEMBLY__
17762+
17763+/* how to get the current stack pointer from C */
17764+register unsigned long current_stack_pointer asm("esp") __used;
17765
17766 #endif
17767
17768 #else /* X86_32 */
17769
17770-#include <asm/percpu.h>
17771-#define KERNEL_STACK_OFFSET (5*8)
17772-
17773 /*
17774 * macros/functions for gaining access to the thread information structure
17775 * preempt_count needs to be 1 initially, until the scheduler is functional.
17776@@ -202,27 +193,8 @@ static inline struct thread_info *current_thread_info(void)
17777 #ifndef __ASSEMBLY__
17778 DECLARE_PER_CPU(unsigned long, kernel_stack);
17779
17780-static inline struct thread_info *current_thread_info(void)
17781-{
17782- struct thread_info *ti;
17783- ti = (void *)(this_cpu_read_stable(kernel_stack) +
17784- KERNEL_STACK_OFFSET - THREAD_SIZE);
17785- return ti;
17786-}
17787-
17788-#else /* !__ASSEMBLY__ */
17789-
17790-/* how to get the thread information struct from ASM */
17791-#define GET_THREAD_INFO(reg) \
17792- movq PER_CPU_VAR(kernel_stack),reg ; \
17793- subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
17794-
17795-/*
17796- * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
17797- * a certain register (to be used in assembler memory operands).
17798- */
17799-#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
17800-
17801+/* how to get the current stack pointer from C */
17802+register unsigned long current_stack_pointer asm("rsp") __used;
17803 #endif
17804
17805 #endif /* !X86_32 */
17806@@ -281,5 +253,12 @@ static inline bool is_ia32_task(void)
17807 extern void arch_task_cache_init(void);
17808 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
17809 extern void arch_release_task_struct(struct task_struct *tsk);
17810+
17811+#define __HAVE_THREAD_FUNCTIONS
17812+#define task_thread_info(task) (&(task)->tinfo)
17813+#define task_stack_page(task) ((task)->stack)
17814+#define setup_thread_stack(p, org) do {} while (0)
17815+#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
17816+
17817 #endif
17818 #endif /* _ASM_X86_THREAD_INFO_H */
17819diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflush.h
17820index e6d90ba..0897f44 100644
17821--- a/arch/x86/include/asm/tlbflush.h
17822+++ b/arch/x86/include/asm/tlbflush.h
17823@@ -17,18 +17,44 @@
17824
17825 static inline void __native_flush_tlb(void)
17826 {
17827+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
17828+ u64 descriptor[2];
17829+
17830+ descriptor[0] = PCID_KERNEL;
17831+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_MONGLOBAL) : "memory");
17832+ return;
17833+ }
17834+
17835+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17836+ if (static_cpu_has(X86_FEATURE_PCID)) {
17837+ unsigned int cpu = raw_get_cpu();
17838+
17839+ native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
17840+ native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
17841+ raw_put_cpu_no_resched();
17842+ return;
17843+ }
17844+#endif
17845+
17846 native_write_cr3(native_read_cr3());
17847 }
17848
17849 static inline void __native_flush_tlb_global_irq_disabled(void)
17850 {
17851- unsigned long cr4;
17852+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
17853+ u64 descriptor[2];
17854
17855- cr4 = native_read_cr4();
17856- /* clear PGE */
17857- native_write_cr4(cr4 & ~X86_CR4_PGE);
17858- /* write old PGE again and flush TLBs */
17859- native_write_cr4(cr4);
17860+ descriptor[0] = PCID_KERNEL;
17861+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_GLOBAL) : "memory");
17862+ } else {
17863+ unsigned long cr4;
17864+
17865+ cr4 = native_read_cr4();
17866+ /* clear PGE */
17867+ native_write_cr4(cr4 & ~X86_CR4_PGE);
17868+ /* write old PGE again and flush TLBs */
17869+ native_write_cr4(cr4);
17870+ }
17871 }
17872
17873 static inline void __native_flush_tlb_global(void)
17874@@ -49,6 +75,42 @@ static inline void __native_flush_tlb_global(void)
17875
17876 static inline void __native_flush_tlb_single(unsigned long addr)
17877 {
17878+
17879+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
17880+ u64 descriptor[2];
17881+
17882+ descriptor[0] = PCID_KERNEL;
17883+ descriptor[1] = addr;
17884+
17885+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17886+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) || addr >= TASK_SIZE_MAX) {
17887+ if (addr < TASK_SIZE_MAX)
17888+ descriptor[1] += pax_user_shadow_base;
17889+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
17890+ }
17891+
17892+ descriptor[0] = PCID_USER;
17893+ descriptor[1] = addr;
17894+#endif
17895+
17896+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
17897+ return;
17898+ }
17899+
17900+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17901+ if (static_cpu_has(X86_FEATURE_PCID)) {
17902+ unsigned int cpu = raw_get_cpu();
17903+
17904+ native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
17905+ asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
17906+ native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
17907+ raw_put_cpu_no_resched();
17908+
17909+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) && addr < TASK_SIZE_MAX)
17910+ addr += pax_user_shadow_base;
17911+ }
17912+#endif
17913+
17914 asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
17915 }
17916
17917diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
17918index 5838fa9..f7ae572 100644
17919--- a/arch/x86/include/asm/uaccess.h
17920+++ b/arch/x86/include/asm/uaccess.h
17921@@ -7,6 +7,7 @@
17922 #include <linux/compiler.h>
17923 #include <linux/thread_info.h>
17924 #include <linux/string.h>
17925+#include <linux/sched.h>
17926 #include <asm/asm.h>
17927 #include <asm/page.h>
17928 #include <asm/smap.h>
17929@@ -29,7 +30,12 @@
17930
17931 #define get_ds() (KERNEL_DS)
17932 #define get_fs() (current_thread_info()->addr_limit)
17933+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
17934+void __set_fs(mm_segment_t x);
17935+void set_fs(mm_segment_t x);
17936+#else
17937 #define set_fs(x) (current_thread_info()->addr_limit = (x))
17938+#endif
17939
17940 #define segment_eq(a, b) ((a).seg == (b).seg)
17941
17942@@ -77,8 +83,33 @@
17943 * checks that the pointer is in the user space range - after calling
17944 * this function, memory access functions may still return -EFAULT.
17945 */
17946-#define access_ok(type, addr, size) \
17947- (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
17948+#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
17949+#define access_ok(type, addr, size) \
17950+({ \
17951+ long __size = size; \
17952+ unsigned long __addr = (unsigned long)addr; \
17953+ unsigned long __addr_ao = __addr & PAGE_MASK; \
17954+ unsigned long __end_ao = __addr + __size - 1; \
17955+ bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
17956+ if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
17957+ while(__addr_ao <= __end_ao) { \
17958+ char __c_ao; \
17959+ __addr_ao += PAGE_SIZE; \
17960+ if (__size > PAGE_SIZE) \
17961+ cond_resched(); \
17962+ if (__get_user(__c_ao, (char __user *)__addr)) \
17963+ break; \
17964+ if (type != VERIFY_WRITE) { \
17965+ __addr = __addr_ao; \
17966+ continue; \
17967+ } \
17968+ if (__put_user(__c_ao, (char __user *)__addr)) \
17969+ break; \
17970+ __addr = __addr_ao; \
17971+ } \
17972+ } \
17973+ __ret_ao; \
17974+})
17975
17976 /*
17977 * The exception table consists of pairs of addresses relative to the
17978@@ -168,10 +199,12 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
17979 register __inttype(*(ptr)) __val_gu asm("%"_ASM_DX); \
17980 __chk_user_ptr(ptr); \
17981 might_fault(); \
17982+ pax_open_userland(); \
17983 asm volatile("call __get_user_%P3" \
17984 : "=a" (__ret_gu), "=r" (__val_gu) \
17985 : "0" (ptr), "i" (sizeof(*(ptr)))); \
17986 (x) = (__typeof__(*(ptr))) __val_gu; \
17987+ pax_close_userland(); \
17988 __ret_gu; \
17989 })
17990
17991@@ -179,13 +212,21 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
17992 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
17993 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
17994
17995-
17996+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
17997+#define __copyuser_seg "gs;"
17998+#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
17999+#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
18000+#else
18001+#define __copyuser_seg
18002+#define __COPYUSER_SET_ES
18003+#define __COPYUSER_RESTORE_ES
18004+#endif
18005
18006 #ifdef CONFIG_X86_32
18007 #define __put_user_asm_u64(x, addr, err, errret) \
18008 asm volatile(ASM_STAC "\n" \
18009- "1: movl %%eax,0(%2)\n" \
18010- "2: movl %%edx,4(%2)\n" \
18011+ "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
18012+ "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
18013 "3: " ASM_CLAC "\n" \
18014 ".section .fixup,\"ax\"\n" \
18015 "4: movl %3,%0\n" \
18016@@ -198,8 +239,8 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
18017
18018 #define __put_user_asm_ex_u64(x, addr) \
18019 asm volatile(ASM_STAC "\n" \
18020- "1: movl %%eax,0(%1)\n" \
18021- "2: movl %%edx,4(%1)\n" \
18022+ "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
18023+ "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
18024 "3: " ASM_CLAC "\n" \
18025 _ASM_EXTABLE_EX(1b, 2b) \
18026 _ASM_EXTABLE_EX(2b, 3b) \
18027@@ -249,7 +290,8 @@ extern void __put_user_8(void);
18028 __typeof__(*(ptr)) __pu_val; \
18029 __chk_user_ptr(ptr); \
18030 might_fault(); \
18031- __pu_val = x; \
18032+ __pu_val = (x); \
18033+ pax_open_userland(); \
18034 switch (sizeof(*(ptr))) { \
18035 case 1: \
18036 __put_user_x(1, __pu_val, ptr, __ret_pu); \
18037@@ -267,6 +309,7 @@ extern void __put_user_8(void);
18038 __put_user_x(X, __pu_val, ptr, __ret_pu); \
18039 break; \
18040 } \
18041+ pax_close_userland(); \
18042 __ret_pu; \
18043 })
18044
18045@@ -347,8 +390,10 @@ do { \
18046 } while (0)
18047
18048 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
18049+do { \
18050+ pax_open_userland(); \
18051 asm volatile(ASM_STAC "\n" \
18052- "1: mov"itype" %2,%"rtype"1\n" \
18053+ "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
18054 "2: " ASM_CLAC "\n" \
18055 ".section .fixup,\"ax\"\n" \
18056 "3: mov %3,%0\n" \
18057@@ -356,8 +401,10 @@ do { \
18058 " jmp 2b\n" \
18059 ".previous\n" \
18060 _ASM_EXTABLE(1b, 3b) \
18061- : "=r" (err), ltype(x) \
18062- : "m" (__m(addr)), "i" (errret), "0" (err))
18063+ : "=r" (err), ltype (x) \
18064+ : "m" (__m(addr)), "i" (errret), "0" (err)); \
18065+ pax_close_userland(); \
18066+} while (0)
18067
18068 #define __get_user_size_ex(x, ptr, size) \
18069 do { \
18070@@ -381,7 +428,7 @@ do { \
18071 } while (0)
18072
18073 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
18074- asm volatile("1: mov"itype" %1,%"rtype"0\n" \
18075+ asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
18076 "2:\n" \
18077 _ASM_EXTABLE_EX(1b, 2b) \
18078 : ltype(x) : "m" (__m(addr)))
18079@@ -398,13 +445,24 @@ do { \
18080 int __gu_err; \
18081 unsigned long __gu_val; \
18082 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
18083- (x) = (__force __typeof__(*(ptr)))__gu_val; \
18084+ (x) = (__typeof__(*(ptr)))__gu_val; \
18085 __gu_err; \
18086 })
18087
18088 /* FIXME: this hack is definitely wrong -AK */
18089 struct __large_struct { unsigned long buf[100]; };
18090-#define __m(x) (*(struct __large_struct __user *)(x))
18091+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18092+#define ____m(x) \
18093+({ \
18094+ unsigned long ____x = (unsigned long)(x); \
18095+ if (____x < pax_user_shadow_base) \
18096+ ____x += pax_user_shadow_base; \
18097+ (typeof(x))____x; \
18098+})
18099+#else
18100+#define ____m(x) (x)
18101+#endif
18102+#define __m(x) (*(struct __large_struct __user *)____m(x))
18103
18104 /*
18105 * Tell gcc we read from memory instead of writing: this is because
18106@@ -412,8 +470,10 @@ struct __large_struct { unsigned long buf[100]; };
18107 * aliasing issues.
18108 */
18109 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
18110+do { \
18111+ pax_open_userland(); \
18112 asm volatile(ASM_STAC "\n" \
18113- "1: mov"itype" %"rtype"1,%2\n" \
18114+ "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
18115 "2: " ASM_CLAC "\n" \
18116 ".section .fixup,\"ax\"\n" \
18117 "3: mov %3,%0\n" \
18118@@ -421,10 +481,12 @@ struct __large_struct { unsigned long buf[100]; };
18119 ".previous\n" \
18120 _ASM_EXTABLE(1b, 3b) \
18121 : "=r"(err) \
18122- : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
18123+ : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err));\
18124+ pax_close_userland(); \
18125+} while (0)
18126
18127 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
18128- asm volatile("1: mov"itype" %"rtype"0,%1\n" \
18129+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
18130 "2:\n" \
18131 _ASM_EXTABLE_EX(1b, 2b) \
18132 : : ltype(x), "m" (__m(addr)))
18133@@ -434,11 +496,13 @@ struct __large_struct { unsigned long buf[100]; };
18134 */
18135 #define uaccess_try do { \
18136 current_thread_info()->uaccess_err = 0; \
18137+ pax_open_userland(); \
18138 stac(); \
18139 barrier();
18140
18141 #define uaccess_catch(err) \
18142 clac(); \
18143+ pax_close_userland(); \
18144 (err) |= (current_thread_info()->uaccess_err ? -EFAULT : 0); \
18145 } while (0)
18146
18147@@ -463,8 +527,12 @@ struct __large_struct { unsigned long buf[100]; };
18148 * On error, the variable @x is set to zero.
18149 */
18150
18151+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18152+#define __get_user(x, ptr) get_user((x), (ptr))
18153+#else
18154 #define __get_user(x, ptr) \
18155 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
18156+#endif
18157
18158 /**
18159 * __put_user: - Write a simple value into user space, with less checking.
18160@@ -486,8 +554,12 @@ struct __large_struct { unsigned long buf[100]; };
18161 * Returns zero on success, or -EFAULT on error.
18162 */
18163
18164+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18165+#define __put_user(x, ptr) put_user((x), (ptr))
18166+#else
18167 #define __put_user(x, ptr) \
18168 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
18169+#endif
18170
18171 #define __get_user_unaligned __get_user
18172 #define __put_user_unaligned __put_user
18173@@ -505,7 +577,7 @@ struct __large_struct { unsigned long buf[100]; };
18174 #define get_user_ex(x, ptr) do { \
18175 unsigned long __gue_val; \
18176 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
18177- (x) = (__force __typeof__(*(ptr)))__gue_val; \
18178+ (x) = (__typeof__(*(ptr)))__gue_val; \
18179 } while (0)
18180
18181 #define put_user_try uaccess_try
18182diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
18183index 7f760a9..b596b9a 100644
18184--- a/arch/x86/include/asm/uaccess_32.h
18185+++ b/arch/x86/include/asm/uaccess_32.h
18186@@ -43,6 +43,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
18187 static __always_inline unsigned long __must_check
18188 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
18189 {
18190+ if ((long)n < 0)
18191+ return n;
18192+
18193+ check_object_size(from, n, true);
18194+
18195 if (__builtin_constant_p(n)) {
18196 unsigned long ret;
18197
18198@@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
18199 __copy_to_user(void __user *to, const void *from, unsigned long n)
18200 {
18201 might_fault();
18202+
18203 return __copy_to_user_inatomic(to, from, n);
18204 }
18205
18206 static __always_inline unsigned long
18207 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
18208 {
18209+ if ((long)n < 0)
18210+ return n;
18211+
18212 /* Avoid zeroing the tail if the copy fails..
18213 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
18214 * but as the zeroing behaviour is only significant when n is not
18215@@ -137,6 +146,12 @@ static __always_inline unsigned long
18216 __copy_from_user(void *to, const void __user *from, unsigned long n)
18217 {
18218 might_fault();
18219+
18220+ if ((long)n < 0)
18221+ return n;
18222+
18223+ check_object_size(to, n, false);
18224+
18225 if (__builtin_constant_p(n)) {
18226 unsigned long ret;
18227
18228@@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
18229 const void __user *from, unsigned long n)
18230 {
18231 might_fault();
18232+
18233+ if ((long)n < 0)
18234+ return n;
18235+
18236 if (__builtin_constant_p(n)) {
18237 unsigned long ret;
18238
18239@@ -181,15 +200,19 @@ static __always_inline unsigned long
18240 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
18241 unsigned long n)
18242 {
18243- return __copy_from_user_ll_nocache_nozero(to, from, n);
18244+ if ((long)n < 0)
18245+ return n;
18246+
18247+ return __copy_from_user_ll_nocache_nozero(to, from, n);
18248 }
18249
18250-unsigned long __must_check copy_to_user(void __user *to,
18251- const void *from, unsigned long n);
18252-unsigned long __must_check _copy_from_user(void *to,
18253- const void __user *from,
18254- unsigned long n);
18255-
18256+extern void copy_to_user_overflow(void)
18257+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
18258+ __compiletime_error("copy_to_user() buffer size is not provably correct")
18259+#else
18260+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
18261+#endif
18262+;
18263
18264 extern void copy_from_user_overflow(void)
18265 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
18266@@ -199,17 +222,60 @@ extern void copy_from_user_overflow(void)
18267 #endif
18268 ;
18269
18270-static inline unsigned long __must_check copy_from_user(void *to,
18271- const void __user *from,
18272- unsigned long n)
18273+/**
18274+ * copy_to_user: - Copy a block of data into user space.
18275+ * @to: Destination address, in user space.
18276+ * @from: Source address, in kernel space.
18277+ * @n: Number of bytes to copy.
18278+ *
18279+ * Context: User context only. This function may sleep.
18280+ *
18281+ * Copy data from kernel space to user space.
18282+ *
18283+ * Returns number of bytes that could not be copied.
18284+ * On success, this will be zero.
18285+ */
18286+static inline unsigned long __must_check
18287+copy_to_user(void __user *to, const void *from, unsigned long n)
18288 {
18289- int sz = __compiletime_object_size(to);
18290+ size_t sz = __compiletime_object_size(from);
18291
18292- if (likely(sz == -1 || sz >= n))
18293- n = _copy_from_user(to, from, n);
18294- else
18295+ if (unlikely(sz != (size_t)-1 && sz < n))
18296+ copy_to_user_overflow();
18297+ else if (access_ok(VERIFY_WRITE, to, n))
18298+ n = __copy_to_user(to, from, n);
18299+ return n;
18300+}
18301+
18302+/**
18303+ * copy_from_user: - Copy a block of data from user space.
18304+ * @to: Destination address, in kernel space.
18305+ * @from: Source address, in user space.
18306+ * @n: Number of bytes to copy.
18307+ *
18308+ * Context: User context only. This function may sleep.
18309+ *
18310+ * Copy data from user space to kernel space.
18311+ *
18312+ * Returns number of bytes that could not be copied.
18313+ * On success, this will be zero.
18314+ *
18315+ * If some data could not be copied, this function will pad the copied
18316+ * data to the requested size using zero bytes.
18317+ */
18318+static inline unsigned long __must_check
18319+copy_from_user(void *to, const void __user *from, unsigned long n)
18320+{
18321+ size_t sz = __compiletime_object_size(to);
18322+
18323+ check_object_size(to, n, false);
18324+
18325+ if (unlikely(sz != (size_t)-1 && sz < n))
18326 copy_from_user_overflow();
18327-
18328+ else if (access_ok(VERIFY_READ, from, n))
18329+ n = __copy_from_user(to, from, n);
18330+ else if ((long)n > 0)
18331+ memset(to, 0, n);
18332 return n;
18333 }
18334
18335diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
18336index 4f7923d..201b58d 100644
18337--- a/arch/x86/include/asm/uaccess_64.h
18338+++ b/arch/x86/include/asm/uaccess_64.h
18339@@ -10,6 +10,9 @@
18340 #include <asm/alternative.h>
18341 #include <asm/cpufeature.h>
18342 #include <asm/page.h>
18343+#include <asm/pgtable.h>
18344+
18345+#define set_fs(x) (current_thread_info()->addr_limit = (x))
18346
18347 /*
18348 * Copy To/From Userspace
18349@@ -17,14 +20,14 @@
18350
18351 /* Handles exceptions in both to and from, but doesn't do access_ok */
18352 __must_check unsigned long
18353-copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
18354+copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
18355 __must_check unsigned long
18356-copy_user_generic_string(void *to, const void *from, unsigned len);
18357+copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
18358 __must_check unsigned long
18359-copy_user_generic_unrolled(void *to, const void *from, unsigned len);
18360+copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
18361
18362-static __always_inline __must_check unsigned long
18363-copy_user_generic(void *to, const void *from, unsigned len)
18364+static __always_inline __must_check unsigned long
18365+copy_user_generic(void *to, const void *from, unsigned long len)
18366 {
18367 unsigned ret;
18368
18369@@ -45,138 +48,200 @@ copy_user_generic(void *to, const void *from, unsigned len)
18370 return ret;
18371 }
18372
18373+static __always_inline __must_check unsigned long
18374+__copy_to_user(void __user *to, const void *from, unsigned long len);
18375+static __always_inline __must_check unsigned long
18376+__copy_from_user(void *to, const void __user *from, unsigned long len);
18377 __must_check unsigned long
18378-_copy_to_user(void __user *to, const void *from, unsigned len);
18379-__must_check unsigned long
18380-_copy_from_user(void *to, const void __user *from, unsigned len);
18381-__must_check unsigned long
18382-copy_in_user(void __user *to, const void __user *from, unsigned len);
18383+copy_in_user(void __user *to, const void __user *from, unsigned long len);
18384+
18385+extern void copy_to_user_overflow(void)
18386+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
18387+ __compiletime_error("copy_to_user() buffer size is not provably correct")
18388+#else
18389+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
18390+#endif
18391+;
18392+
18393+extern void copy_from_user_overflow(void)
18394+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
18395+ __compiletime_error("copy_from_user() buffer size is not provably correct")
18396+#else
18397+ __compiletime_warning("copy_from_user() buffer size is not provably correct")
18398+#endif
18399+;
18400
18401 static inline unsigned long __must_check copy_from_user(void *to,
18402 const void __user *from,
18403 unsigned long n)
18404 {
18405- int sz = __compiletime_object_size(to);
18406-
18407 might_fault();
18408- if (likely(sz == -1 || sz >= n))
18409- n = _copy_from_user(to, from, n);
18410-#ifdef CONFIG_DEBUG_VM
18411- else
18412- WARN(1, "Buffer overflow detected!\n");
18413-#endif
18414+
18415+ check_object_size(to, n, false);
18416+
18417+ if (access_ok(VERIFY_READ, from, n))
18418+ n = __copy_from_user(to, from, n);
18419+ else if (n < INT_MAX)
18420+ memset(to, 0, n);
18421 return n;
18422 }
18423
18424 static __always_inline __must_check
18425-int copy_to_user(void __user *dst, const void *src, unsigned size)
18426+int copy_to_user(void __user *dst, const void *src, unsigned long size)
18427 {
18428 might_fault();
18429
18430- return _copy_to_user(dst, src, size);
18431+ if (access_ok(VERIFY_WRITE, dst, size))
18432+ size = __copy_to_user(dst, src, size);
18433+ return size;
18434 }
18435
18436 static __always_inline __must_check
18437-int __copy_from_user(void *dst, const void __user *src, unsigned size)
18438+unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
18439 {
18440- int ret = 0;
18441+ size_t sz = __compiletime_object_size(dst);
18442+ unsigned ret = 0;
18443
18444 might_fault();
18445+
18446+ if (size > INT_MAX)
18447+ return size;
18448+
18449+ check_object_size(dst, size, false);
18450+
18451+#ifdef CONFIG_PAX_MEMORY_UDEREF
18452+ if (!__access_ok(VERIFY_READ, src, size))
18453+ return size;
18454+#endif
18455+
18456+ if (unlikely(sz != (size_t)-1 && sz < size)) {
18457+ copy_from_user_overflow();
18458+ return size;
18459+ }
18460+
18461 if (!__builtin_constant_p(size))
18462- return copy_user_generic(dst, (__force void *)src, size);
18463+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
18464 switch (size) {
18465- case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
18466+ case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
18467 ret, "b", "b", "=q", 1);
18468 return ret;
18469- case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
18470+ case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
18471 ret, "w", "w", "=r", 2);
18472 return ret;
18473- case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
18474+ case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
18475 ret, "l", "k", "=r", 4);
18476 return ret;
18477- case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
18478+ case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
18479 ret, "q", "", "=r", 8);
18480 return ret;
18481 case 10:
18482- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
18483+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
18484 ret, "q", "", "=r", 10);
18485 if (unlikely(ret))
18486 return ret;
18487 __get_user_asm(*(u16 *)(8 + (char *)dst),
18488- (u16 __user *)(8 + (char __user *)src),
18489+ (const u16 __user *)(8 + (const char __user *)src),
18490 ret, "w", "w", "=r", 2);
18491 return ret;
18492 case 16:
18493- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
18494+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
18495 ret, "q", "", "=r", 16);
18496 if (unlikely(ret))
18497 return ret;
18498 __get_user_asm(*(u64 *)(8 + (char *)dst),
18499- (u64 __user *)(8 + (char __user *)src),
18500+ (const u64 __user *)(8 + (const char __user *)src),
18501 ret, "q", "", "=r", 8);
18502 return ret;
18503 default:
18504- return copy_user_generic(dst, (__force void *)src, size);
18505+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
18506 }
18507 }
18508
18509 static __always_inline __must_check
18510-int __copy_to_user(void __user *dst, const void *src, unsigned size)
18511+unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
18512 {
18513- int ret = 0;
18514+ size_t sz = __compiletime_object_size(src);
18515+ unsigned ret = 0;
18516
18517 might_fault();
18518+
18519+ if (size > INT_MAX)
18520+ return size;
18521+
18522+ check_object_size(src, size, true);
18523+
18524+#ifdef CONFIG_PAX_MEMORY_UDEREF
18525+ if (!__access_ok(VERIFY_WRITE, dst, size))
18526+ return size;
18527+#endif
18528+
18529+ if (unlikely(sz != (size_t)-1 && sz < size)) {
18530+ copy_to_user_overflow();
18531+ return size;
18532+ }
18533+
18534 if (!__builtin_constant_p(size))
18535- return copy_user_generic((__force void *)dst, src, size);
18536+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
18537 switch (size) {
18538- case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
18539+ case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
18540 ret, "b", "b", "iq", 1);
18541 return ret;
18542- case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
18543+ case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
18544 ret, "w", "w", "ir", 2);
18545 return ret;
18546- case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
18547+ case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
18548 ret, "l", "k", "ir", 4);
18549 return ret;
18550- case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
18551+ case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
18552 ret, "q", "", "er", 8);
18553 return ret;
18554 case 10:
18555- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
18556+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
18557 ret, "q", "", "er", 10);
18558 if (unlikely(ret))
18559 return ret;
18560 asm("":::"memory");
18561- __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
18562+ __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
18563 ret, "w", "w", "ir", 2);
18564 return ret;
18565 case 16:
18566- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
18567+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
18568 ret, "q", "", "er", 16);
18569 if (unlikely(ret))
18570 return ret;
18571 asm("":::"memory");
18572- __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
18573+ __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
18574 ret, "q", "", "er", 8);
18575 return ret;
18576 default:
18577- return copy_user_generic((__force void *)dst, src, size);
18578+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
18579 }
18580 }
18581
18582 static __always_inline __must_check
18583-int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
18584+unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
18585 {
18586- int ret = 0;
18587+ unsigned ret = 0;
18588
18589 might_fault();
18590+
18591+ if (size > INT_MAX)
18592+ return size;
18593+
18594+#ifdef CONFIG_PAX_MEMORY_UDEREF
18595+ if (!__access_ok(VERIFY_READ, src, size))
18596+ return size;
18597+ if (!__access_ok(VERIFY_WRITE, dst, size))
18598+ return size;
18599+#endif
18600+
18601 if (!__builtin_constant_p(size))
18602- return copy_user_generic((__force void *)dst,
18603- (__force void *)src, size);
18604+ return copy_user_generic((__force_kernel void *)____m(dst),
18605+ (__force_kernel const void *)____m(src), size);
18606 switch (size) {
18607 case 1: {
18608 u8 tmp;
18609- __get_user_asm(tmp, (u8 __user *)src,
18610+ __get_user_asm(tmp, (const u8 __user *)src,
18611 ret, "b", "b", "=q", 1);
18612 if (likely(!ret))
18613 __put_user_asm(tmp, (u8 __user *)dst,
18614@@ -185,7 +250,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
18615 }
18616 case 2: {
18617 u16 tmp;
18618- __get_user_asm(tmp, (u16 __user *)src,
18619+ __get_user_asm(tmp, (const u16 __user *)src,
18620 ret, "w", "w", "=r", 2);
18621 if (likely(!ret))
18622 __put_user_asm(tmp, (u16 __user *)dst,
18623@@ -195,7 +260,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
18624
18625 case 4: {
18626 u32 tmp;
18627- __get_user_asm(tmp, (u32 __user *)src,
18628+ __get_user_asm(tmp, (const u32 __user *)src,
18629 ret, "l", "k", "=r", 4);
18630 if (likely(!ret))
18631 __put_user_asm(tmp, (u32 __user *)dst,
18632@@ -204,7 +269,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
18633 }
18634 case 8: {
18635 u64 tmp;
18636- __get_user_asm(tmp, (u64 __user *)src,
18637+ __get_user_asm(tmp, (const u64 __user *)src,
18638 ret, "q", "", "=r", 8);
18639 if (likely(!ret))
18640 __put_user_asm(tmp, (u64 __user *)dst,
18641@@ -212,41 +277,74 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
18642 return ret;
18643 }
18644 default:
18645- return copy_user_generic((__force void *)dst,
18646- (__force void *)src, size);
18647+ return copy_user_generic((__force_kernel void *)____m(dst),
18648+ (__force_kernel const void *)____m(src), size);
18649 }
18650 }
18651
18652-static __must_check __always_inline int
18653-__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
18654+static __must_check __always_inline unsigned long
18655+__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
18656 {
18657- return copy_user_generic(dst, (__force const void *)src, size);
18658+ if (size > INT_MAX)
18659+ return size;
18660+
18661+#ifdef CONFIG_PAX_MEMORY_UDEREF
18662+ if (!__access_ok(VERIFY_READ, src, size))
18663+ return size;
18664+#endif
18665+
18666+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
18667 }
18668
18669-static __must_check __always_inline int
18670-__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
18671+static __must_check __always_inline unsigned long
18672+__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
18673 {
18674- return copy_user_generic((__force void *)dst, src, size);
18675+ if (size > INT_MAX)
18676+ return size;
18677+
18678+#ifdef CONFIG_PAX_MEMORY_UDEREF
18679+ if (!__access_ok(VERIFY_WRITE, dst, size))
18680+ return size;
18681+#endif
18682+
18683+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
18684 }
18685
18686-extern long __copy_user_nocache(void *dst, const void __user *src,
18687- unsigned size, int zerorest);
18688+extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
18689+ unsigned long size, int zerorest);
18690
18691-static inline int
18692-__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
18693+static inline unsigned long
18694+__copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
18695 {
18696 might_fault();
18697+
18698+ if (size > INT_MAX)
18699+ return size;
18700+
18701+#ifdef CONFIG_PAX_MEMORY_UDEREF
18702+ if (!__access_ok(VERIFY_READ, src, size))
18703+ return size;
18704+#endif
18705+
18706 return __copy_user_nocache(dst, src, size, 1);
18707 }
18708
18709-static inline int
18710+static inline unsigned long
18711 __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
18712- unsigned size)
18713+ unsigned long size)
18714 {
18715+ if (size > INT_MAX)
18716+ return size;
18717+
18718+#ifdef CONFIG_PAX_MEMORY_UDEREF
18719+ if (!__access_ok(VERIFY_READ, src, size))
18720+ return size;
18721+#endif
18722+
18723 return __copy_user_nocache(dst, src, size, 0);
18724 }
18725
18726 unsigned long
18727-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
18728+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
18729
18730 #endif /* _ASM_X86_UACCESS_64_H */
18731diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
18732index 5b238981..77fdd78 100644
18733--- a/arch/x86/include/asm/word-at-a-time.h
18734+++ b/arch/x86/include/asm/word-at-a-time.h
18735@@ -11,7 +11,7 @@
18736 * and shift, for example.
18737 */
18738 struct word_at_a_time {
18739- const unsigned long one_bits, high_bits;
18740+ unsigned long one_bits, high_bits;
18741 };
18742
18743 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
18744diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
18745index 828a156..650e625 100644
18746--- a/arch/x86/include/asm/x86_init.h
18747+++ b/arch/x86/include/asm/x86_init.h
18748@@ -129,7 +129,7 @@ struct x86_init_ops {
18749 struct x86_init_timers timers;
18750 struct x86_init_iommu iommu;
18751 struct x86_init_pci pci;
18752-};
18753+} __no_const;
18754
18755 /**
18756 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
18757@@ -140,7 +140,7 @@ struct x86_cpuinit_ops {
18758 void (*setup_percpu_clockev)(void);
18759 void (*early_percpu_clock_init)(void);
18760 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
18761-};
18762+} __no_const;
18763
18764 struct timespec;
18765
18766@@ -168,7 +168,7 @@ struct x86_platform_ops {
18767 void (*save_sched_clock_state)(void);
18768 void (*restore_sched_clock_state)(void);
18769 void (*apic_post_init)(void);
18770-};
18771+} __no_const;
18772
18773 struct pci_dev;
18774 struct msi_msg;
18775@@ -182,7 +182,7 @@ struct x86_msi_ops {
18776 void (*teardown_msi_irqs)(struct pci_dev *dev);
18777 void (*restore_msi_irqs)(struct pci_dev *dev, int irq);
18778 int (*setup_hpet_msi)(unsigned int irq, unsigned int id);
18779-};
18780+} __no_const;
18781
18782 struct IO_APIC_route_entry;
18783 struct io_apic_irq_attr;
18784@@ -203,7 +203,7 @@ struct x86_io_apic_ops {
18785 unsigned int destination, int vector,
18786 struct io_apic_irq_attr *attr);
18787 void (*eoi_ioapic_pin)(int apic, int pin, int vector);
18788-};
18789+} __no_const;
18790
18791 extern struct x86_init_ops x86_init;
18792 extern struct x86_cpuinit_ops x86_cpuinit;
18793diff --git a/arch/x86/include/asm/xen/page.h b/arch/x86/include/asm/xen/page.h
18794index b913915..4f5a581 100644
18795--- a/arch/x86/include/asm/xen/page.h
18796+++ b/arch/x86/include/asm/xen/page.h
18797@@ -56,7 +56,7 @@ extern int m2p_remove_override(struct page *page,
18798 extern struct page *m2p_find_override(unsigned long mfn);
18799 extern unsigned long m2p_find_override_pfn(unsigned long mfn, unsigned long pfn);
18800
18801-static inline unsigned long pfn_to_mfn(unsigned long pfn)
18802+static inline unsigned long __intentional_overflow(-1) pfn_to_mfn(unsigned long pfn)
18803 {
18804 unsigned long mfn;
18805
18806diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
18807index 0415cda..3b22adc 100644
18808--- a/arch/x86/include/asm/xsave.h
18809+++ b/arch/x86/include/asm/xsave.h
18810@@ -70,8 +70,11 @@ static inline int xsave_user(struct xsave_struct __user *buf)
18811 if (unlikely(err))
18812 return -EFAULT;
18813
18814+ pax_open_userland();
18815 __asm__ __volatile__(ASM_STAC "\n"
18816- "1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
18817+ "1:"
18818+ __copyuser_seg
18819+ ".byte " REX_PREFIX "0x0f,0xae,0x27\n"
18820 "2: " ASM_CLAC "\n"
18821 ".section .fixup,\"ax\"\n"
18822 "3: movl $-1,%[err]\n"
18823@@ -81,18 +84,22 @@ static inline int xsave_user(struct xsave_struct __user *buf)
18824 : [err] "=r" (err)
18825 : "D" (buf), "a" (-1), "d" (-1), "0" (0)
18826 : "memory");
18827+ pax_close_userland();
18828 return err;
18829 }
18830
18831 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
18832 {
18833 int err;
18834- struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
18835+ struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
18836 u32 lmask = mask;
18837 u32 hmask = mask >> 32;
18838
18839+ pax_open_userland();
18840 __asm__ __volatile__(ASM_STAC "\n"
18841- "1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
18842+ "1:"
18843+ __copyuser_seg
18844+ ".byte " REX_PREFIX "0x0f,0xae,0x2f\n"
18845 "2: " ASM_CLAC "\n"
18846 ".section .fixup,\"ax\"\n"
18847 "3: movl $-1,%[err]\n"
18848@@ -102,6 +109,7 @@ static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
18849 : [err] "=r" (err)
18850 : "D" (xstate), "a" (lmask), "d" (hmask), "0" (0)
18851 : "memory"); /* memory required? */
18852+ pax_close_userland();
18853 return err;
18854 }
18855
18856diff --git a/arch/x86/include/uapi/asm/e820.h b/arch/x86/include/uapi/asm/e820.h
18857index bbae024..e1528f9 100644
18858--- a/arch/x86/include/uapi/asm/e820.h
18859+++ b/arch/x86/include/uapi/asm/e820.h
18860@@ -63,7 +63,7 @@ struct e820map {
18861 #define ISA_START_ADDRESS 0xa0000
18862 #define ISA_END_ADDRESS 0x100000
18863
18864-#define BIOS_BEGIN 0x000a0000
18865+#define BIOS_BEGIN 0x000c0000
18866 #define BIOS_END 0x00100000
18867
18868 #define BIOS_ROM_BASE 0xffe00000
18869diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
18870index a5408b9..5133813 100644
18871--- a/arch/x86/kernel/Makefile
18872+++ b/arch/x86/kernel/Makefile
18873@@ -24,7 +24,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
18874 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
18875 obj-$(CONFIG_IRQ_WORK) += irq_work.o
18876 obj-y += probe_roms.o
18877-obj-$(CONFIG_X86_32) += i386_ksyms_32.o
18878+obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
18879 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
18880 obj-y += syscall_$(BITS).o
18881 obj-$(CONFIG_X86_64) += vsyscall_64.o
18882diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
18883index 40c7660..f709f4b 100644
18884--- a/arch/x86/kernel/acpi/boot.c
18885+++ b/arch/x86/kernel/acpi/boot.c
18886@@ -1365,7 +1365,7 @@ static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
18887 * If your system is blacklisted here, but you find that acpi=force
18888 * works for you, please contact linux-acpi@vger.kernel.org
18889 */
18890-static struct dmi_system_id __initdata acpi_dmi_table[] = {
18891+static const struct dmi_system_id __initconst acpi_dmi_table[] = {
18892 /*
18893 * Boxes that need ACPI disabled
18894 */
18895@@ -1440,7 +1440,7 @@ static struct dmi_system_id __initdata acpi_dmi_table[] = {
18896 };
18897
18898 /* second table for DMI checks that should run after early-quirks */
18899-static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
18900+static const struct dmi_system_id __initconst acpi_dmi_table_late[] = {
18901 /*
18902 * HP laptops which use a DSDT reporting as HP/SB400/10000,
18903 * which includes some code which overrides all temperature
18904diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
18905index 3312010..a65ca7b 100644
18906--- a/arch/x86/kernel/acpi/sleep.c
18907+++ b/arch/x86/kernel/acpi/sleep.c
18908@@ -88,8 +88,12 @@ int x86_acpi_suspend_lowlevel(void)
18909 #else /* CONFIG_64BIT */
18910 #ifdef CONFIG_SMP
18911 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
18912+
18913+ pax_open_kernel();
18914 early_gdt_descr.address =
18915 (unsigned long)get_cpu_gdt_table(smp_processor_id());
18916+ pax_close_kernel();
18917+
18918 initial_gs = per_cpu_offset(smp_processor_id());
18919 #endif
18920 initial_code = (unsigned long)wakeup_long64;
18921diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
18922index d1daa66..59fecba 100644
18923--- a/arch/x86/kernel/acpi/wakeup_32.S
18924+++ b/arch/x86/kernel/acpi/wakeup_32.S
18925@@ -29,13 +29,11 @@ wakeup_pmode_return:
18926 # and restore the stack ... but you need gdt for this to work
18927 movl saved_context_esp, %esp
18928
18929- movl %cs:saved_magic, %eax
18930- cmpl $0x12345678, %eax
18931+ cmpl $0x12345678, saved_magic
18932 jne bogus_magic
18933
18934 # jump to place where we left off
18935- movl saved_eip, %eax
18936- jmp *%eax
18937+ jmp *(saved_eip)
18938
18939 bogus_magic:
18940 jmp bogus_magic
18941diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
18942index 15e8563..323cbe1 100644
18943--- a/arch/x86/kernel/alternative.c
18944+++ b/arch/x86/kernel/alternative.c
18945@@ -269,6 +269,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
18946 */
18947 for (a = start; a < end; a++) {
18948 instr = (u8 *)&a->instr_offset + a->instr_offset;
18949+
18950+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18951+ instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
18952+ if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
18953+ instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
18954+#endif
18955+
18956 replacement = (u8 *)&a->repl_offset + a->repl_offset;
18957 BUG_ON(a->replacementlen > a->instrlen);
18958 BUG_ON(a->instrlen > sizeof(insnbuf));
18959@@ -300,10 +307,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
18960 for (poff = start; poff < end; poff++) {
18961 u8 *ptr = (u8 *)poff + *poff;
18962
18963+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18964+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
18965+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
18966+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
18967+#endif
18968+
18969 if (!*poff || ptr < text || ptr >= text_end)
18970 continue;
18971 /* turn DS segment override prefix into lock prefix */
18972- if (*ptr == 0x3e)
18973+ if (*ktla_ktva(ptr) == 0x3e)
18974 text_poke(ptr, ((unsigned char []){0xf0}), 1);
18975 }
18976 mutex_unlock(&text_mutex);
18977@@ -318,10 +331,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
18978 for (poff = start; poff < end; poff++) {
18979 u8 *ptr = (u8 *)poff + *poff;
18980
18981+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18982+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
18983+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
18984+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
18985+#endif
18986+
18987 if (!*poff || ptr < text || ptr >= text_end)
18988 continue;
18989 /* turn lock prefix into DS segment override prefix */
18990- if (*ptr == 0xf0)
18991+ if (*ktla_ktva(ptr) == 0xf0)
18992 text_poke(ptr, ((unsigned char []){0x3E}), 1);
18993 }
18994 mutex_unlock(&text_mutex);
18995@@ -469,7 +488,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
18996
18997 BUG_ON(p->len > MAX_PATCH_LEN);
18998 /* prep the buffer with the original instructions */
18999- memcpy(insnbuf, p->instr, p->len);
19000+ memcpy(insnbuf, ktla_ktva(p->instr), p->len);
19001 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
19002 (unsigned long)p->instr, p->len);
19003
19004@@ -516,7 +535,7 @@ void __init alternative_instructions(void)
19005 if (!uniproc_patched || num_possible_cpus() == 1)
19006 free_init_pages("SMP alternatives",
19007 (unsigned long)__smp_locks,
19008- (unsigned long)__smp_locks_end);
19009+ PAGE_ALIGN((unsigned long)__smp_locks_end));
19010 #endif
19011
19012 apply_paravirt(__parainstructions, __parainstructions_end);
19013@@ -536,13 +555,17 @@ void __init alternative_instructions(void)
19014 * instructions. And on the local CPU you need to be protected again NMI or MCE
19015 * handlers seeing an inconsistent instruction while you patch.
19016 */
19017-void *__init_or_module text_poke_early(void *addr, const void *opcode,
19018+void *__kprobes text_poke_early(void *addr, const void *opcode,
19019 size_t len)
19020 {
19021 unsigned long flags;
19022 local_irq_save(flags);
19023- memcpy(addr, opcode, len);
19024+
19025+ pax_open_kernel();
19026+ memcpy(ktla_ktva(addr), opcode, len);
19027 sync_core();
19028+ pax_close_kernel();
19029+
19030 local_irq_restore(flags);
19031 /* Could also do a CLFLUSH here to speed up CPU recovery; but
19032 that causes hangs on some VIA CPUs. */
19033@@ -564,36 +587,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
19034 */
19035 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
19036 {
19037- unsigned long flags;
19038- char *vaddr;
19039+ unsigned char *vaddr = ktla_ktva(addr);
19040 struct page *pages[2];
19041- int i;
19042+ size_t i;
19043
19044 if (!core_kernel_text((unsigned long)addr)) {
19045- pages[0] = vmalloc_to_page(addr);
19046- pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
19047+ pages[0] = vmalloc_to_page(vaddr);
19048+ pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
19049 } else {
19050- pages[0] = virt_to_page(addr);
19051+ pages[0] = virt_to_page(vaddr);
19052 WARN_ON(!PageReserved(pages[0]));
19053- pages[1] = virt_to_page(addr + PAGE_SIZE);
19054+ pages[1] = virt_to_page(vaddr + PAGE_SIZE);
19055 }
19056 BUG_ON(!pages[0]);
19057- local_irq_save(flags);
19058- set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
19059- if (pages[1])
19060- set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
19061- vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
19062- memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
19063- clear_fixmap(FIX_TEXT_POKE0);
19064- if (pages[1])
19065- clear_fixmap(FIX_TEXT_POKE1);
19066- local_flush_tlb();
19067- sync_core();
19068- /* Could also do a CLFLUSH here to speed up CPU recovery; but
19069- that causes hangs on some VIA CPUs. */
19070+ text_poke_early(addr, opcode, len);
19071 for (i = 0; i < len; i++)
19072- BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
19073- local_irq_restore(flags);
19074+ BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
19075 return addr;
19076 }
19077
19078@@ -613,7 +622,7 @@ int poke_int3_handler(struct pt_regs *regs)
19079 if (likely(!bp_patching_in_progress))
19080 return 0;
19081
19082- if (user_mode_vm(regs) || regs->ip != (unsigned long)bp_int3_addr)
19083+ if (user_mode(regs) || regs->ip != (unsigned long)bp_int3_addr)
19084 return 0;
19085
19086 /* set up the specified breakpoint handler */
19087@@ -647,7 +656,7 @@ int poke_int3_handler(struct pt_regs *regs)
19088 */
19089 void *text_poke_bp(void *addr, const void *opcode, size_t len, void *handler)
19090 {
19091- unsigned char int3 = 0xcc;
19092+ const unsigned char int3 = 0xcc;
19093
19094 bp_int3_handler = handler;
19095 bp_int3_addr = (u8 *)addr + sizeof(int3);
19096diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
19097index a7eb82d..f6e52d4 100644
19098--- a/arch/x86/kernel/apic/apic.c
19099+++ b/arch/x86/kernel/apic/apic.c
19100@@ -190,7 +190,7 @@ int first_system_vector = 0xfe;
19101 /*
19102 * Debug level, exported for io_apic.c
19103 */
19104-unsigned int apic_verbosity;
19105+int apic_verbosity;
19106
19107 int pic_mode;
19108
19109@@ -1985,7 +1985,7 @@ static inline void __smp_error_interrupt(struct pt_regs *regs)
19110 apic_write(APIC_ESR, 0);
19111 v1 = apic_read(APIC_ESR);
19112 ack_APIC_irq();
19113- atomic_inc(&irq_err_count);
19114+ atomic_inc_unchecked(&irq_err_count);
19115
19116 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
19117 smp_processor_id(), v0 , v1);
19118diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c
19119index 00c77cf..2dc6a2d 100644
19120--- a/arch/x86/kernel/apic/apic_flat_64.c
19121+++ b/arch/x86/kernel/apic/apic_flat_64.c
19122@@ -157,7 +157,7 @@ static int flat_probe(void)
19123 return 1;
19124 }
19125
19126-static struct apic apic_flat = {
19127+static struct apic apic_flat __read_only = {
19128 .name = "flat",
19129 .probe = flat_probe,
19130 .acpi_madt_oem_check = flat_acpi_madt_oem_check,
19131@@ -271,7 +271,7 @@ static int physflat_probe(void)
19132 return 0;
19133 }
19134
19135-static struct apic apic_physflat = {
19136+static struct apic apic_physflat __read_only = {
19137
19138 .name = "physical flat",
19139 .probe = physflat_probe,
19140diff --git a/arch/x86/kernel/apic/apic_noop.c b/arch/x86/kernel/apic/apic_noop.c
19141index e145f28..2752888 100644
19142--- a/arch/x86/kernel/apic/apic_noop.c
19143+++ b/arch/x86/kernel/apic/apic_noop.c
19144@@ -119,7 +119,7 @@ static void noop_apic_write(u32 reg, u32 v)
19145 WARN_ON_ONCE(cpu_has_apic && !disable_apic);
19146 }
19147
19148-struct apic apic_noop = {
19149+struct apic apic_noop __read_only = {
19150 .name = "noop",
19151 .probe = noop_probe,
19152 .acpi_madt_oem_check = NULL,
19153diff --git a/arch/x86/kernel/apic/bigsmp_32.c b/arch/x86/kernel/apic/bigsmp_32.c
19154index d50e364..543bee3 100644
19155--- a/arch/x86/kernel/apic/bigsmp_32.c
19156+++ b/arch/x86/kernel/apic/bigsmp_32.c
19157@@ -152,7 +152,7 @@ static int probe_bigsmp(void)
19158 return dmi_bigsmp;
19159 }
19160
19161-static struct apic apic_bigsmp = {
19162+static struct apic apic_bigsmp __read_only = {
19163
19164 .name = "bigsmp",
19165 .probe = probe_bigsmp,
19166diff --git a/arch/x86/kernel/apic/es7000_32.c b/arch/x86/kernel/apic/es7000_32.c
19167index c552247..587a316 100644
19168--- a/arch/x86/kernel/apic/es7000_32.c
19169+++ b/arch/x86/kernel/apic/es7000_32.c
19170@@ -608,8 +608,7 @@ static int es7000_mps_oem_check_cluster(struct mpc_table *mpc, char *oem,
19171 return ret && es7000_apic_is_cluster();
19172 }
19173
19174-/* We've been warned by a false positive warning.Use __refdata to keep calm. */
19175-static struct apic __refdata apic_es7000_cluster = {
19176+static struct apic apic_es7000_cluster __read_only = {
19177
19178 .name = "es7000",
19179 .probe = probe_es7000,
19180@@ -675,7 +674,7 @@ static struct apic __refdata apic_es7000_cluster = {
19181 .x86_32_early_logical_apicid = es7000_early_logical_apicid,
19182 };
19183
19184-static struct apic __refdata apic_es7000 = {
19185+static struct apic apic_es7000 __read_only = {
19186
19187 .name = "es7000",
19188 .probe = probe_es7000,
19189diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
19190index e63a5bd..c0babf8 100644
19191--- a/arch/x86/kernel/apic/io_apic.c
19192+++ b/arch/x86/kernel/apic/io_apic.c
19193@@ -1060,7 +1060,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
19194 }
19195 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
19196
19197-void lock_vector_lock(void)
19198+void lock_vector_lock(void) __acquires(vector_lock)
19199 {
19200 /* Used to the online set of cpus does not change
19201 * during assign_irq_vector.
19202@@ -1068,7 +1068,7 @@ void lock_vector_lock(void)
19203 raw_spin_lock(&vector_lock);
19204 }
19205
19206-void unlock_vector_lock(void)
19207+void unlock_vector_lock(void) __releases(vector_lock)
19208 {
19209 raw_spin_unlock(&vector_lock);
19210 }
19211@@ -2367,7 +2367,7 @@ static void ack_apic_edge(struct irq_data *data)
19212 ack_APIC_irq();
19213 }
19214
19215-atomic_t irq_mis_count;
19216+atomic_unchecked_t irq_mis_count;
19217
19218 #ifdef CONFIG_GENERIC_PENDING_IRQ
19219 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
19220@@ -2508,7 +2508,7 @@ static void ack_apic_level(struct irq_data *data)
19221 * at the cpu.
19222 */
19223 if (!(v & (1 << (i & 0x1f)))) {
19224- atomic_inc(&irq_mis_count);
19225+ atomic_inc_unchecked(&irq_mis_count);
19226
19227 eoi_ioapic_irq(irq, cfg);
19228 }
19229diff --git a/arch/x86/kernel/apic/numaq_32.c b/arch/x86/kernel/apic/numaq_32.c
19230index 1e42e8f..daacf44 100644
19231--- a/arch/x86/kernel/apic/numaq_32.c
19232+++ b/arch/x86/kernel/apic/numaq_32.c
19233@@ -455,8 +455,7 @@ static void numaq_setup_portio_remap(void)
19234 (u_long) xquad_portio, (u_long) num_quads*XQUAD_PORTIO_QUAD);
19235 }
19236
19237-/* Use __refdata to keep false positive warning calm. */
19238-static struct apic __refdata apic_numaq = {
19239+static struct apic apic_numaq __read_only = {
19240
19241 .name = "NUMAQ",
19242 .probe = probe_numaq,
19243diff --git a/arch/x86/kernel/apic/probe_32.c b/arch/x86/kernel/apic/probe_32.c
19244index eb35ef9..f184a21 100644
19245--- a/arch/x86/kernel/apic/probe_32.c
19246+++ b/arch/x86/kernel/apic/probe_32.c
19247@@ -72,7 +72,7 @@ static int probe_default(void)
19248 return 1;
19249 }
19250
19251-static struct apic apic_default = {
19252+static struct apic apic_default __read_only = {
19253
19254 .name = "default",
19255 .probe = probe_default,
19256diff --git a/arch/x86/kernel/apic/summit_32.c b/arch/x86/kernel/apic/summit_32.c
19257index 77c95c0..434f8a4 100644
19258--- a/arch/x86/kernel/apic/summit_32.c
19259+++ b/arch/x86/kernel/apic/summit_32.c
19260@@ -486,7 +486,7 @@ void setup_summit(void)
19261 }
19262 #endif
19263
19264-static struct apic apic_summit = {
19265+static struct apic apic_summit __read_only = {
19266
19267 .name = "summit",
19268 .probe = probe_summit,
19269diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c
19270index 140e29d..d88bc95 100644
19271--- a/arch/x86/kernel/apic/x2apic_cluster.c
19272+++ b/arch/x86/kernel/apic/x2apic_cluster.c
19273@@ -183,7 +183,7 @@ update_clusterinfo(struct notifier_block *nfb, unsigned long action, void *hcpu)
19274 return notifier_from_errno(err);
19275 }
19276
19277-static struct notifier_block __refdata x2apic_cpu_notifier = {
19278+static struct notifier_block x2apic_cpu_notifier = {
19279 .notifier_call = update_clusterinfo,
19280 };
19281
19282@@ -235,7 +235,7 @@ static void cluster_vector_allocation_domain(int cpu, struct cpumask *retmask,
19283 cpumask_and(retmask, mask, per_cpu(cpus_in_cluster, cpu));
19284 }
19285
19286-static struct apic apic_x2apic_cluster = {
19287+static struct apic apic_x2apic_cluster __read_only = {
19288
19289 .name = "cluster x2apic",
19290 .probe = x2apic_cluster_probe,
19291diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c
19292index 562a76d..a003c0f 100644
19293--- a/arch/x86/kernel/apic/x2apic_phys.c
19294+++ b/arch/x86/kernel/apic/x2apic_phys.c
19295@@ -89,7 +89,7 @@ static int x2apic_phys_probe(void)
19296 return apic == &apic_x2apic_phys;
19297 }
19298
19299-static struct apic apic_x2apic_phys = {
19300+static struct apic apic_x2apic_phys __read_only = {
19301
19302 .name = "physical x2apic",
19303 .probe = x2apic_phys_probe,
19304diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
19305index a419814..1dd34a0 100644
19306--- a/arch/x86/kernel/apic/x2apic_uv_x.c
19307+++ b/arch/x86/kernel/apic/x2apic_uv_x.c
19308@@ -357,7 +357,7 @@ static int uv_probe(void)
19309 return apic == &apic_x2apic_uv_x;
19310 }
19311
19312-static struct apic __refdata apic_x2apic_uv_x = {
19313+static struct apic apic_x2apic_uv_x __read_only = {
19314
19315 .name = "UV large system",
19316 .probe = uv_probe,
19317diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
19318index 3ab0343..814c4787 100644
19319--- a/arch/x86/kernel/apm_32.c
19320+++ b/arch/x86/kernel/apm_32.c
19321@@ -433,7 +433,7 @@ static DEFINE_MUTEX(apm_mutex);
19322 * This is for buggy BIOS's that refer to (real mode) segment 0x40
19323 * even though they are called in protected mode.
19324 */
19325-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
19326+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
19327 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
19328
19329 static const char driver_version[] = "1.16ac"; /* no spaces */
19330@@ -611,7 +611,10 @@ static long __apm_bios_call(void *_call)
19331 BUG_ON(cpu != 0);
19332 gdt = get_cpu_gdt_table(cpu);
19333 save_desc_40 = gdt[0x40 / 8];
19334+
19335+ pax_open_kernel();
19336 gdt[0x40 / 8] = bad_bios_desc;
19337+ pax_close_kernel();
19338
19339 apm_irq_save(flags);
19340 APM_DO_SAVE_SEGS;
19341@@ -620,7 +623,11 @@ static long __apm_bios_call(void *_call)
19342 &call->esi);
19343 APM_DO_RESTORE_SEGS;
19344 apm_irq_restore(flags);
19345+
19346+ pax_open_kernel();
19347 gdt[0x40 / 8] = save_desc_40;
19348+ pax_close_kernel();
19349+
19350 put_cpu();
19351
19352 return call->eax & 0xff;
19353@@ -687,7 +694,10 @@ static long __apm_bios_call_simple(void *_call)
19354 BUG_ON(cpu != 0);
19355 gdt = get_cpu_gdt_table(cpu);
19356 save_desc_40 = gdt[0x40 / 8];
19357+
19358+ pax_open_kernel();
19359 gdt[0x40 / 8] = bad_bios_desc;
19360+ pax_close_kernel();
19361
19362 apm_irq_save(flags);
19363 APM_DO_SAVE_SEGS;
19364@@ -695,7 +705,11 @@ static long __apm_bios_call_simple(void *_call)
19365 &call->eax);
19366 APM_DO_RESTORE_SEGS;
19367 apm_irq_restore(flags);
19368+
19369+ pax_open_kernel();
19370 gdt[0x40 / 8] = save_desc_40;
19371+ pax_close_kernel();
19372+
19373 put_cpu();
19374 return error;
19375 }
19376@@ -2362,12 +2376,15 @@ static int __init apm_init(void)
19377 * code to that CPU.
19378 */
19379 gdt = get_cpu_gdt_table(0);
19380+
19381+ pax_open_kernel();
19382 set_desc_base(&gdt[APM_CS >> 3],
19383 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
19384 set_desc_base(&gdt[APM_CS_16 >> 3],
19385 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
19386 set_desc_base(&gdt[APM_DS >> 3],
19387 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
19388+ pax_close_kernel();
19389
19390 proc_create("apm", 0, NULL, &apm_file_ops);
19391
19392diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
19393index 2861082..6d4718e 100644
19394--- a/arch/x86/kernel/asm-offsets.c
19395+++ b/arch/x86/kernel/asm-offsets.c
19396@@ -33,6 +33,8 @@ void common(void) {
19397 OFFSET(TI_status, thread_info, status);
19398 OFFSET(TI_addr_limit, thread_info, addr_limit);
19399 OFFSET(TI_preempt_count, thread_info, preempt_count);
19400+ OFFSET(TI_lowest_stack, thread_info, lowest_stack);
19401+ DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
19402
19403 BLANK();
19404 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
19405@@ -53,8 +55,26 @@ void common(void) {
19406 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
19407 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
19408 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
19409+
19410+#ifdef CONFIG_PAX_KERNEXEC
19411+ OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
19412 #endif
19413
19414+#ifdef CONFIG_PAX_MEMORY_UDEREF
19415+ OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
19416+ OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
19417+#ifdef CONFIG_X86_64
19418+ OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
19419+#endif
19420+#endif
19421+
19422+#endif
19423+
19424+ BLANK();
19425+ DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
19426+ DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
19427+ DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
19428+
19429 #ifdef CONFIG_XEN
19430 BLANK();
19431 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
19432diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
19433index e7c798b..2b2019b 100644
19434--- a/arch/x86/kernel/asm-offsets_64.c
19435+++ b/arch/x86/kernel/asm-offsets_64.c
19436@@ -77,6 +77,7 @@ int main(void)
19437 BLANK();
19438 #undef ENTRY
19439
19440+ DEFINE(TSS_size, sizeof(struct tss_struct));
19441 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
19442 BLANK();
19443
19444diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
19445index 47b56a7..efc2bc6 100644
19446--- a/arch/x86/kernel/cpu/Makefile
19447+++ b/arch/x86/kernel/cpu/Makefile
19448@@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
19449 CFLAGS_REMOVE_perf_event.o = -pg
19450 endif
19451
19452-# Make sure load_percpu_segment has no stackprotector
19453-nostackp := $(call cc-option, -fno-stack-protector)
19454-CFLAGS_common.o := $(nostackp)
19455-
19456 obj-y := intel_cacheinfo.o scattered.o topology.o
19457 obj-y += proc.o capflags.o powerflags.o common.o
19458 obj-y += rdrand.o
19459diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
19460index 903a264..fc955f3 100644
19461--- a/arch/x86/kernel/cpu/amd.c
19462+++ b/arch/x86/kernel/cpu/amd.c
19463@@ -743,7 +743,7 @@ static void init_amd(struct cpuinfo_x86 *c)
19464 static unsigned int amd_size_cache(struct cpuinfo_x86 *c, unsigned int size)
19465 {
19466 /* AMD errata T13 (order #21922) */
19467- if ((c->x86 == 6)) {
19468+ if (c->x86 == 6) {
19469 /* Duron Rev A0 */
19470 if (c->x86_model == 3 && c->x86_mask == 0)
19471 size = 64;
19472diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
19473index 2793d1f..5c04a30 100644
19474--- a/arch/x86/kernel/cpu/common.c
19475+++ b/arch/x86/kernel/cpu/common.c
19476@@ -88,60 +88,6 @@ static const struct cpu_dev default_cpu = {
19477
19478 static const struct cpu_dev *this_cpu = &default_cpu;
19479
19480-DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
19481-#ifdef CONFIG_X86_64
19482- /*
19483- * We need valid kernel segments for data and code in long mode too
19484- * IRET will check the segment types kkeil 2000/10/28
19485- * Also sysret mandates a special GDT layout
19486- *
19487- * TLS descriptors are currently at a different place compared to i386.
19488- * Hopefully nobody expects them at a fixed place (Wine?)
19489- */
19490- [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
19491- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
19492- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
19493- [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
19494- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
19495- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
19496-#else
19497- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
19498- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
19499- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
19500- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
19501- /*
19502- * Segments used for calling PnP BIOS have byte granularity.
19503- * They code segments and data segments have fixed 64k limits,
19504- * the transfer segment sizes are set at run time.
19505- */
19506- /* 32-bit code */
19507- [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
19508- /* 16-bit code */
19509- [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
19510- /* 16-bit data */
19511- [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
19512- /* 16-bit data */
19513- [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
19514- /* 16-bit data */
19515- [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
19516- /*
19517- * The APM segments have byte granularity and their bases
19518- * are set at run time. All have 64k limits.
19519- */
19520- /* 32-bit code */
19521- [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
19522- /* 16-bit code */
19523- [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
19524- /* data */
19525- [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
19526-
19527- [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
19528- [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
19529- GDT_STACK_CANARY_INIT
19530-#endif
19531-} };
19532-EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
19533-
19534 static int __init x86_xsave_setup(char *s)
19535 {
19536 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
19537@@ -288,6 +234,57 @@ static __always_inline void setup_smap(struct cpuinfo_x86 *c)
19538 set_in_cr4(X86_CR4_SMAP);
19539 }
19540
19541+#ifdef CONFIG_X86_64
19542+static __init int setup_disable_pcid(char *arg)
19543+{
19544+ setup_clear_cpu_cap(X86_FEATURE_PCID);
19545+
19546+#ifdef CONFIG_PAX_MEMORY_UDEREF
19547+ if (clone_pgd_mask != ~(pgdval_t)0UL)
19548+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
19549+#endif
19550+
19551+ return 1;
19552+}
19553+__setup("nopcid", setup_disable_pcid);
19554+
19555+static void setup_pcid(struct cpuinfo_x86 *c)
19556+{
19557+ if (!cpu_has(c, X86_FEATURE_PCID)) {
19558+
19559+#ifdef CONFIG_PAX_MEMORY_UDEREF
19560+ if (clone_pgd_mask != ~(pgdval_t)0UL) {
19561+ pax_open_kernel();
19562+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
19563+ pax_close_kernel();
19564+ printk("PAX: slow and weak UDEREF enabled\n");
19565+ } else
19566+ printk("PAX: UDEREF disabled\n");
19567+#endif
19568+
19569+ return;
19570+ }
19571+
19572+ printk("PAX: PCID detected\n");
19573+ set_in_cr4(X86_CR4_PCIDE);
19574+
19575+#ifdef CONFIG_PAX_MEMORY_UDEREF
19576+ pax_open_kernel();
19577+ clone_pgd_mask = ~(pgdval_t)0UL;
19578+ pax_close_kernel();
19579+ if (pax_user_shadow_base)
19580+ printk("PAX: weak UDEREF enabled\n");
19581+ else {
19582+ set_cpu_cap(c, X86_FEATURE_STRONGUDEREF);
19583+ printk("PAX: strong UDEREF enabled\n");
19584+ }
19585+#endif
19586+
19587+ if (cpu_has(c, X86_FEATURE_INVPCID))
19588+ printk("PAX: INVPCID detected\n");
19589+}
19590+#endif
19591+
19592 /*
19593 * Some CPU features depend on higher CPUID levels, which may not always
19594 * be available due to CPUID level capping or broken virtualization
19595@@ -386,7 +383,7 @@ void switch_to_new_gdt(int cpu)
19596 {
19597 struct desc_ptr gdt_descr;
19598
19599- gdt_descr.address = (long)get_cpu_gdt_table(cpu);
19600+ gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
19601 gdt_descr.size = GDT_SIZE - 1;
19602 load_gdt(&gdt_descr);
19603 /* Reload the per-cpu base */
19604@@ -875,6 +872,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
19605 setup_smep(c);
19606 setup_smap(c);
19607
19608+#ifdef CONFIG_X86_64
19609+ setup_pcid(c);
19610+#endif
19611+
19612 /*
19613 * The vendor-specific functions might have changed features.
19614 * Now we do "generic changes."
19615@@ -883,6 +884,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
19616 /* Filter out anything that depends on CPUID levels we don't have */
19617 filter_cpuid_features(c, true);
19618
19619+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
19620+ setup_clear_cpu_cap(X86_FEATURE_SEP);
19621+#endif
19622+
19623 /* If the model name is still unset, do table lookup. */
19624 if (!c->x86_model_id[0]) {
19625 const char *p;
19626@@ -1070,10 +1075,12 @@ static __init int setup_disablecpuid(char *arg)
19627 }
19628 __setup("clearcpuid=", setup_disablecpuid);
19629
19630+DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
19631+EXPORT_PER_CPU_SYMBOL(current_tinfo);
19632+
19633 #ifdef CONFIG_X86_64
19634-struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
19635-struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1,
19636- (unsigned long) debug_idt_table };
19637+struct desc_ptr idt_descr __read_only = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
19638+const struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) debug_idt_table };
19639
19640 DEFINE_PER_CPU_FIRST(union irq_stack_union,
19641 irq_stack_union) __aligned(PAGE_SIZE) __visible;
19642@@ -1087,7 +1094,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
19643 EXPORT_PER_CPU_SYMBOL(current_task);
19644
19645 DEFINE_PER_CPU(unsigned long, kernel_stack) =
19646- (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
19647+ (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
19648 EXPORT_PER_CPU_SYMBOL(kernel_stack);
19649
19650 DEFINE_PER_CPU(char *, irq_stack_ptr) =
19651@@ -1232,7 +1239,7 @@ void cpu_init(void)
19652 load_ucode_ap();
19653
19654 cpu = stack_smp_processor_id();
19655- t = &per_cpu(init_tss, cpu);
19656+ t = init_tss + cpu;
19657 oist = &per_cpu(orig_ist, cpu);
19658
19659 #ifdef CONFIG_NUMA
19660@@ -1267,7 +1274,6 @@ void cpu_init(void)
19661 wrmsrl(MSR_KERNEL_GS_BASE, 0);
19662 barrier();
19663
19664- x86_configure_nx();
19665 enable_x2apic();
19666
19667 /*
19668@@ -1319,7 +1325,7 @@ void cpu_init(void)
19669 {
19670 int cpu = smp_processor_id();
19671 struct task_struct *curr = current;
19672- struct tss_struct *t = &per_cpu(init_tss, cpu);
19673+ struct tss_struct *t = init_tss + cpu;
19674 struct thread_struct *thread = &curr->thread;
19675
19676 show_ucode_info_early();
19677diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
19678index 1414c90..1159406 100644
19679--- a/arch/x86/kernel/cpu/intel_cacheinfo.c
19680+++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
19681@@ -1014,6 +1014,22 @@ static struct attribute *default_attrs[] = {
19682 };
19683
19684 #ifdef CONFIG_AMD_NB
19685+static struct attribute *default_attrs_amd_nb[] = {
19686+ &type.attr,
19687+ &level.attr,
19688+ &coherency_line_size.attr,
19689+ &physical_line_partition.attr,
19690+ &ways_of_associativity.attr,
19691+ &number_of_sets.attr,
19692+ &size.attr,
19693+ &shared_cpu_map.attr,
19694+ &shared_cpu_list.attr,
19695+ NULL,
19696+ NULL,
19697+ NULL,
19698+ NULL
19699+};
19700+
19701 static struct attribute **amd_l3_attrs(void)
19702 {
19703 static struct attribute **attrs;
19704@@ -1024,18 +1040,7 @@ static struct attribute **amd_l3_attrs(void)
19705
19706 n = ARRAY_SIZE(default_attrs);
19707
19708- if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
19709- n += 2;
19710-
19711- if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
19712- n += 1;
19713-
19714- attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
19715- if (attrs == NULL)
19716- return attrs = default_attrs;
19717-
19718- for (n = 0; default_attrs[n]; n++)
19719- attrs[n] = default_attrs[n];
19720+ attrs = default_attrs_amd_nb;
19721
19722 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
19723 attrs[n++] = &cache_disable_0.attr;
19724@@ -1086,6 +1091,13 @@ static struct kobj_type ktype_cache = {
19725 .default_attrs = default_attrs,
19726 };
19727
19728+#ifdef CONFIG_AMD_NB
19729+static struct kobj_type ktype_cache_amd_nb = {
19730+ .sysfs_ops = &sysfs_ops,
19731+ .default_attrs = default_attrs_amd_nb,
19732+};
19733+#endif
19734+
19735 static struct kobj_type ktype_percpu_entry = {
19736 .sysfs_ops = &sysfs_ops,
19737 };
19738@@ -1151,20 +1163,26 @@ static int cache_add_dev(struct device *dev)
19739 return retval;
19740 }
19741
19742+#ifdef CONFIG_AMD_NB
19743+ amd_l3_attrs();
19744+#endif
19745+
19746 for (i = 0; i < num_cache_leaves; i++) {
19747+ struct kobj_type *ktype;
19748+
19749 this_object = INDEX_KOBJECT_PTR(cpu, i);
19750 this_object->cpu = cpu;
19751 this_object->index = i;
19752
19753 this_leaf = CPUID4_INFO_IDX(cpu, i);
19754
19755- ktype_cache.default_attrs = default_attrs;
19756+ ktype = &ktype_cache;
19757 #ifdef CONFIG_AMD_NB
19758 if (this_leaf->base.nb)
19759- ktype_cache.default_attrs = amd_l3_attrs();
19760+ ktype = &ktype_cache_amd_nb;
19761 #endif
19762 retval = kobject_init_and_add(&(this_object->kobj),
19763- &ktype_cache,
19764+ ktype,
19765 per_cpu(ici_cache_kobject, cpu),
19766 "index%1lu", i);
19767 if (unlikely(retval)) {
19768diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
19769index b3218cd..99a75de 100644
19770--- a/arch/x86/kernel/cpu/mcheck/mce.c
19771+++ b/arch/x86/kernel/cpu/mcheck/mce.c
19772@@ -45,6 +45,7 @@
19773 #include <asm/processor.h>
19774 #include <asm/mce.h>
19775 #include <asm/msr.h>
19776+#include <asm/local.h>
19777
19778 #include "mce-internal.h"
19779
19780@@ -258,7 +259,7 @@ static void print_mce(struct mce *m)
19781 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
19782 m->cs, m->ip);
19783
19784- if (m->cs == __KERNEL_CS)
19785+ if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
19786 print_symbol("{%s}", m->ip);
19787 pr_cont("\n");
19788 }
19789@@ -291,10 +292,10 @@ static void print_mce(struct mce *m)
19790
19791 #define PANIC_TIMEOUT 5 /* 5 seconds */
19792
19793-static atomic_t mce_paniced;
19794+static atomic_unchecked_t mce_paniced;
19795
19796 static int fake_panic;
19797-static atomic_t mce_fake_paniced;
19798+static atomic_unchecked_t mce_fake_paniced;
19799
19800 /* Panic in progress. Enable interrupts and wait for final IPI */
19801 static void wait_for_panic(void)
19802@@ -318,7 +319,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
19803 /*
19804 * Make sure only one CPU runs in machine check panic
19805 */
19806- if (atomic_inc_return(&mce_paniced) > 1)
19807+ if (atomic_inc_return_unchecked(&mce_paniced) > 1)
19808 wait_for_panic();
19809 barrier();
19810
19811@@ -326,7 +327,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
19812 console_verbose();
19813 } else {
19814 /* Don't log too much for fake panic */
19815- if (atomic_inc_return(&mce_fake_paniced) > 1)
19816+ if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
19817 return;
19818 }
19819 /* First print corrected ones that are still unlogged */
19820@@ -365,7 +366,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
19821 if (!fake_panic) {
19822 if (panic_timeout == 0)
19823 panic_timeout = mca_cfg.panic_timeout;
19824- panic(msg);
19825+ panic("%s", msg);
19826 } else
19827 pr_emerg(HW_ERR "Fake kernel panic: %s\n", msg);
19828 }
19829@@ -695,7 +696,7 @@ static int mce_timed_out(u64 *t)
19830 * might have been modified by someone else.
19831 */
19832 rmb();
19833- if (atomic_read(&mce_paniced))
19834+ if (atomic_read_unchecked(&mce_paniced))
19835 wait_for_panic();
19836 if (!mca_cfg.monarch_timeout)
19837 goto out;
19838@@ -1666,7 +1667,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
19839 }
19840
19841 /* Call the installed machine check handler for this CPU setup. */
19842-void (*machine_check_vector)(struct pt_regs *, long error_code) =
19843+void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
19844 unexpected_machine_check;
19845
19846 /*
19847@@ -1689,7 +1690,9 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
19848 return;
19849 }
19850
19851+ pax_open_kernel();
19852 machine_check_vector = do_machine_check;
19853+ pax_close_kernel();
19854
19855 __mcheck_cpu_init_generic();
19856 __mcheck_cpu_init_vendor(c);
19857@@ -1703,7 +1706,7 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
19858 */
19859
19860 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
19861-static int mce_chrdev_open_count; /* #times opened */
19862+static local_t mce_chrdev_open_count; /* #times opened */
19863 static int mce_chrdev_open_exclu; /* already open exclusive? */
19864
19865 static int mce_chrdev_open(struct inode *inode, struct file *file)
19866@@ -1711,7 +1714,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
19867 spin_lock(&mce_chrdev_state_lock);
19868
19869 if (mce_chrdev_open_exclu ||
19870- (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
19871+ (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
19872 spin_unlock(&mce_chrdev_state_lock);
19873
19874 return -EBUSY;
19875@@ -1719,7 +1722,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
19876
19877 if (file->f_flags & O_EXCL)
19878 mce_chrdev_open_exclu = 1;
19879- mce_chrdev_open_count++;
19880+ local_inc(&mce_chrdev_open_count);
19881
19882 spin_unlock(&mce_chrdev_state_lock);
19883
19884@@ -1730,7 +1733,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
19885 {
19886 spin_lock(&mce_chrdev_state_lock);
19887
19888- mce_chrdev_open_count--;
19889+ local_dec(&mce_chrdev_open_count);
19890 mce_chrdev_open_exclu = 0;
19891
19892 spin_unlock(&mce_chrdev_state_lock);
19893@@ -2404,7 +2407,7 @@ static __init void mce_init_banks(void)
19894
19895 for (i = 0; i < mca_cfg.banks; i++) {
19896 struct mce_bank *b = &mce_banks[i];
19897- struct device_attribute *a = &b->attr;
19898+ device_attribute_no_const *a = &b->attr;
19899
19900 sysfs_attr_init(&a->attr);
19901 a->attr.name = b->attrname;
19902@@ -2472,7 +2475,7 @@ struct dentry *mce_get_debugfs_dir(void)
19903 static void mce_reset(void)
19904 {
19905 cpu_missing = 0;
19906- atomic_set(&mce_fake_paniced, 0);
19907+ atomic_set_unchecked(&mce_fake_paniced, 0);
19908 atomic_set(&mce_executing, 0);
19909 atomic_set(&mce_callin, 0);
19910 atomic_set(&global_nwo, 0);
19911diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
19912index 1c044b1..37a2a43 100644
19913--- a/arch/x86/kernel/cpu/mcheck/p5.c
19914+++ b/arch/x86/kernel/cpu/mcheck/p5.c
19915@@ -11,6 +11,7 @@
19916 #include <asm/processor.h>
19917 #include <asm/mce.h>
19918 #include <asm/msr.h>
19919+#include <asm/pgtable.h>
19920
19921 /* By default disabled */
19922 int mce_p5_enabled __read_mostly;
19923@@ -49,7 +50,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
19924 if (!cpu_has(c, X86_FEATURE_MCE))
19925 return;
19926
19927+ pax_open_kernel();
19928 machine_check_vector = pentium_machine_check;
19929+ pax_close_kernel();
19930 /* Make sure the vector pointer is visible before we enable MCEs: */
19931 wmb();
19932
19933diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
19934index e9a701a..35317d6 100644
19935--- a/arch/x86/kernel/cpu/mcheck/winchip.c
19936+++ b/arch/x86/kernel/cpu/mcheck/winchip.c
19937@@ -10,6 +10,7 @@
19938 #include <asm/processor.h>
19939 #include <asm/mce.h>
19940 #include <asm/msr.h>
19941+#include <asm/pgtable.h>
19942
19943 /* Machine check handler for WinChip C6: */
19944 static void winchip_machine_check(struct pt_regs *regs, long error_code)
19945@@ -23,7 +24,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
19946 {
19947 u32 lo, hi;
19948
19949+ pax_open_kernel();
19950 machine_check_vector = winchip_machine_check;
19951+ pax_close_kernel();
19952 /* Make sure the vector pointer is visible before we enable MCEs: */
19953 wmb();
19954
19955diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
19956index f961de9..8a9d332 100644
19957--- a/arch/x86/kernel/cpu/mtrr/main.c
19958+++ b/arch/x86/kernel/cpu/mtrr/main.c
19959@@ -66,7 +66,7 @@ static DEFINE_MUTEX(mtrr_mutex);
19960 u64 size_or_mask, size_and_mask;
19961 static bool mtrr_aps_delayed_init;
19962
19963-static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
19964+static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
19965
19966 const struct mtrr_ops *mtrr_if;
19967
19968diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
19969index df5e41f..816c719 100644
19970--- a/arch/x86/kernel/cpu/mtrr/mtrr.h
19971+++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
19972@@ -25,7 +25,7 @@ struct mtrr_ops {
19973 int (*validate_add_page)(unsigned long base, unsigned long size,
19974 unsigned int type);
19975 int (*have_wrcomb)(void);
19976-};
19977+} __do_const;
19978
19979 extern int generic_get_free_region(unsigned long base, unsigned long size,
19980 int replace_reg);
19981diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
19982index 8a87a32..682a22a 100644
19983--- a/arch/x86/kernel/cpu/perf_event.c
19984+++ b/arch/x86/kernel/cpu/perf_event.c
19985@@ -1348,7 +1348,7 @@ static void __init pmu_check_apic(void)
19986 pr_info("no hardware sampling interrupt available.\n");
19987 }
19988
19989-static struct attribute_group x86_pmu_format_group = {
19990+static attribute_group_no_const x86_pmu_format_group = {
19991 .name = "format",
19992 .attrs = NULL,
19993 };
19994@@ -1447,7 +1447,7 @@ static struct attribute *events_attr[] = {
19995 NULL,
19996 };
19997
19998-static struct attribute_group x86_pmu_events_group = {
19999+static attribute_group_no_const x86_pmu_events_group = {
20000 .name = "events",
20001 .attrs = events_attr,
20002 };
20003@@ -1958,7 +1958,7 @@ static unsigned long get_segment_base(unsigned int segment)
20004 if (idx > GDT_ENTRIES)
20005 return 0;
20006
20007- desc = __this_cpu_ptr(&gdt_page.gdt[0]);
20008+ desc = get_cpu_gdt_table(smp_processor_id());
20009 }
20010
20011 return get_desc_base(desc + idx);
20012@@ -2048,7 +2048,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
20013 break;
20014
20015 perf_callchain_store(entry, frame.return_address);
20016- fp = frame.next_frame;
20017+ fp = (const void __force_user *)frame.next_frame;
20018 }
20019 }
20020
20021diff --git a/arch/x86/kernel/cpu/perf_event_amd_iommu.c b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
20022index 639d128..e92d7e5 100644
20023--- a/arch/x86/kernel/cpu/perf_event_amd_iommu.c
20024+++ b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
20025@@ -405,7 +405,7 @@ static void perf_iommu_del(struct perf_event *event, int flags)
20026 static __init int _init_events_attrs(struct perf_amd_iommu *perf_iommu)
20027 {
20028 struct attribute **attrs;
20029- struct attribute_group *attr_group;
20030+ attribute_group_no_const *attr_group;
20031 int i = 0, j;
20032
20033 while (amd_iommu_v2_event_descs[i].attr.attr.name)
20034diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
20035index f31a165..7b46cd8 100644
20036--- a/arch/x86/kernel/cpu/perf_event_intel.c
20037+++ b/arch/x86/kernel/cpu/perf_event_intel.c
20038@@ -2247,10 +2247,10 @@ __init int intel_pmu_init(void)
20039 * v2 and above have a perf capabilities MSR
20040 */
20041 if (version > 1) {
20042- u64 capabilities;
20043+ u64 capabilities = x86_pmu.intel_cap.capabilities;
20044
20045- rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
20046- x86_pmu.intel_cap.capabilities = capabilities;
20047+ if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
20048+ x86_pmu.intel_cap.capabilities = capabilities;
20049 }
20050
20051 intel_ds_init();
20052diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.c b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
20053index 4118f9f..f91d0ab 100644
20054--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c
20055+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
20056@@ -3204,7 +3204,7 @@ static void __init uncore_types_exit(struct intel_uncore_type **types)
20057 static int __init uncore_type_init(struct intel_uncore_type *type)
20058 {
20059 struct intel_uncore_pmu *pmus;
20060- struct attribute_group *attr_group;
20061+ attribute_group_no_const *attr_group;
20062 struct attribute **attrs;
20063 int i, j;
20064
20065diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.h b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
20066index a80ab71..4089da5 100644
20067--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.h
20068+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
20069@@ -498,7 +498,7 @@ struct intel_uncore_box {
20070 struct uncore_event_desc {
20071 struct kobj_attribute attr;
20072 const char *config;
20073-};
20074+} __do_const;
20075
20076 #define INTEL_UNCORE_EVENT_DESC(_name, _config) \
20077 { \
20078diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
20079index 7d9481c..99c7e4b 100644
20080--- a/arch/x86/kernel/cpuid.c
20081+++ b/arch/x86/kernel/cpuid.c
20082@@ -170,7 +170,7 @@ static int cpuid_class_cpu_callback(struct notifier_block *nfb,
20083 return notifier_from_errno(err);
20084 }
20085
20086-static struct notifier_block __refdata cpuid_class_cpu_notifier =
20087+static struct notifier_block cpuid_class_cpu_notifier =
20088 {
20089 .notifier_call = cpuid_class_cpu_callback,
20090 };
20091diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
20092index e0e0841..da37e6f 100644
20093--- a/arch/x86/kernel/crash.c
20094+++ b/arch/x86/kernel/crash.c
20095@@ -58,10 +58,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
20096 {
20097 #ifdef CONFIG_X86_32
20098 struct pt_regs fixed_regs;
20099-#endif
20100
20101-#ifdef CONFIG_X86_32
20102- if (!user_mode_vm(regs)) {
20103+ if (!user_mode(regs)) {
20104 crash_fixup_ss_esp(&fixed_regs, regs);
20105 regs = &fixed_regs;
20106 }
20107diff --git a/arch/x86/kernel/crash_dump_64.c b/arch/x86/kernel/crash_dump_64.c
20108index afa64ad..dce67dd 100644
20109--- a/arch/x86/kernel/crash_dump_64.c
20110+++ b/arch/x86/kernel/crash_dump_64.c
20111@@ -36,7 +36,7 @@ ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
20112 return -ENOMEM;
20113
20114 if (userbuf) {
20115- if (copy_to_user(buf, vaddr + offset, csize)) {
20116+ if (copy_to_user((char __force_user *)buf, vaddr + offset, csize)) {
20117 iounmap(vaddr);
20118 return -EFAULT;
20119 }
20120diff --git a/arch/x86/kernel/doublefault.c b/arch/x86/kernel/doublefault.c
20121index 5d3fe8d..02e1429 100644
20122--- a/arch/x86/kernel/doublefault.c
20123+++ b/arch/x86/kernel/doublefault.c
20124@@ -13,7 +13,7 @@
20125
20126 #define DOUBLEFAULT_STACKSIZE (1024)
20127 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
20128-#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
20129+#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
20130
20131 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
20132
20133@@ -23,7 +23,7 @@ static void doublefault_fn(void)
20134 unsigned long gdt, tss;
20135
20136 native_store_gdt(&gdt_desc);
20137- gdt = gdt_desc.address;
20138+ gdt = (unsigned long)gdt_desc.address;
20139
20140 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
20141
20142@@ -60,10 +60,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
20143 /* 0x2 bit is always set */
20144 .flags = X86_EFLAGS_SF | 0x2,
20145 .sp = STACK_START,
20146- .es = __USER_DS,
20147+ .es = __KERNEL_DS,
20148 .cs = __KERNEL_CS,
20149 .ss = __KERNEL_DS,
20150- .ds = __USER_DS,
20151+ .ds = __KERNEL_DS,
20152 .fs = __KERNEL_PERCPU,
20153
20154 .__cr3 = __pa_nodebug(swapper_pg_dir),
20155diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
20156index deb6421..76bbc12 100644
20157--- a/arch/x86/kernel/dumpstack.c
20158+++ b/arch/x86/kernel/dumpstack.c
20159@@ -2,6 +2,9 @@
20160 * Copyright (C) 1991, 1992 Linus Torvalds
20161 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
20162 */
20163+#ifdef CONFIG_GRKERNSEC_HIDESYM
20164+#define __INCLUDED_BY_HIDESYM 1
20165+#endif
20166 #include <linux/kallsyms.h>
20167 #include <linux/kprobes.h>
20168 #include <linux/uaccess.h>
20169@@ -35,16 +38,14 @@ void printk_address(unsigned long address, int reliable)
20170 static void
20171 print_ftrace_graph_addr(unsigned long addr, void *data,
20172 const struct stacktrace_ops *ops,
20173- struct thread_info *tinfo, int *graph)
20174+ struct task_struct *task, int *graph)
20175 {
20176- struct task_struct *task;
20177 unsigned long ret_addr;
20178 int index;
20179
20180 if (addr != (unsigned long)return_to_handler)
20181 return;
20182
20183- task = tinfo->task;
20184 index = task->curr_ret_stack;
20185
20186 if (!task->ret_stack || index < *graph)
20187@@ -61,7 +62,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
20188 static inline void
20189 print_ftrace_graph_addr(unsigned long addr, void *data,
20190 const struct stacktrace_ops *ops,
20191- struct thread_info *tinfo, int *graph)
20192+ struct task_struct *task, int *graph)
20193 { }
20194 #endif
20195
20196@@ -72,10 +73,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
20197 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
20198 */
20199
20200-static inline int valid_stack_ptr(struct thread_info *tinfo,
20201- void *p, unsigned int size, void *end)
20202+static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
20203 {
20204- void *t = tinfo;
20205 if (end) {
20206 if (p < end && p >= (end-THREAD_SIZE))
20207 return 1;
20208@@ -86,14 +85,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
20209 }
20210
20211 unsigned long
20212-print_context_stack(struct thread_info *tinfo,
20213+print_context_stack(struct task_struct *task, void *stack_start,
20214 unsigned long *stack, unsigned long bp,
20215 const struct stacktrace_ops *ops, void *data,
20216 unsigned long *end, int *graph)
20217 {
20218 struct stack_frame *frame = (struct stack_frame *)bp;
20219
20220- while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
20221+ while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
20222 unsigned long addr;
20223
20224 addr = *stack;
20225@@ -105,7 +104,7 @@ print_context_stack(struct thread_info *tinfo,
20226 } else {
20227 ops->address(data, addr, 0);
20228 }
20229- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
20230+ print_ftrace_graph_addr(addr, data, ops, task, graph);
20231 }
20232 stack++;
20233 }
20234@@ -114,7 +113,7 @@ print_context_stack(struct thread_info *tinfo,
20235 EXPORT_SYMBOL_GPL(print_context_stack);
20236
20237 unsigned long
20238-print_context_stack_bp(struct thread_info *tinfo,
20239+print_context_stack_bp(struct task_struct *task, void *stack_start,
20240 unsigned long *stack, unsigned long bp,
20241 const struct stacktrace_ops *ops, void *data,
20242 unsigned long *end, int *graph)
20243@@ -122,7 +121,7 @@ print_context_stack_bp(struct thread_info *tinfo,
20244 struct stack_frame *frame = (struct stack_frame *)bp;
20245 unsigned long *ret_addr = &frame->return_address;
20246
20247- while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
20248+ while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
20249 unsigned long addr = *ret_addr;
20250
20251 if (!__kernel_text_address(addr))
20252@@ -131,7 +130,7 @@ print_context_stack_bp(struct thread_info *tinfo,
20253 ops->address(data, addr, 1);
20254 frame = frame->next_frame;
20255 ret_addr = &frame->return_address;
20256- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
20257+ print_ftrace_graph_addr(addr, data, ops, task, graph);
20258 }
20259
20260 return (unsigned long)frame;
20261@@ -150,7 +149,7 @@ static int print_trace_stack(void *data, char *name)
20262 static void print_trace_address(void *data, unsigned long addr, int reliable)
20263 {
20264 touch_nmi_watchdog();
20265- printk(data);
20266+ printk("%s", (char *)data);
20267 printk_address(addr, reliable);
20268 }
20269
20270@@ -219,6 +218,8 @@ unsigned __kprobes long oops_begin(void)
20271 }
20272 EXPORT_SYMBOL_GPL(oops_begin);
20273
20274+extern void gr_handle_kernel_exploit(void);
20275+
20276 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
20277 {
20278 if (regs && kexec_should_crash(current))
20279@@ -240,7 +241,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
20280 panic("Fatal exception in interrupt");
20281 if (panic_on_oops)
20282 panic("Fatal exception");
20283- do_exit(signr);
20284+
20285+ gr_handle_kernel_exploit();
20286+
20287+ do_group_exit(signr);
20288 }
20289
20290 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
20291@@ -268,7 +272,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
20292 print_modules();
20293 show_regs(regs);
20294 #ifdef CONFIG_X86_32
20295- if (user_mode_vm(regs)) {
20296+ if (user_mode(regs)) {
20297 sp = regs->sp;
20298 ss = regs->ss & 0xffff;
20299 } else {
20300@@ -296,7 +300,7 @@ void die(const char *str, struct pt_regs *regs, long err)
20301 unsigned long flags = oops_begin();
20302 int sig = SIGSEGV;
20303
20304- if (!user_mode_vm(regs))
20305+ if (!user_mode(regs))
20306 report_bug(regs->ip, regs);
20307
20308 if (__die(str, regs, err))
20309diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
20310index f2a1770..540657f 100644
20311--- a/arch/x86/kernel/dumpstack_32.c
20312+++ b/arch/x86/kernel/dumpstack_32.c
20313@@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
20314 bp = stack_frame(task, regs);
20315
20316 for (;;) {
20317- struct thread_info *context;
20318+ void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
20319
20320- context = (struct thread_info *)
20321- ((unsigned long)stack & (~(THREAD_SIZE - 1)));
20322- bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
20323+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
20324
20325- stack = (unsigned long *)context->previous_esp;
20326- if (!stack)
20327+ if (stack_start == task_stack_page(task))
20328 break;
20329+ stack = *(unsigned long **)stack_start;
20330 if (ops->stack(data, "IRQ") < 0)
20331 break;
20332 touch_nmi_watchdog();
20333@@ -87,27 +85,28 @@ void show_regs(struct pt_regs *regs)
20334 int i;
20335
20336 show_regs_print_info(KERN_EMERG);
20337- __show_regs(regs, !user_mode_vm(regs));
20338+ __show_regs(regs, !user_mode(regs));
20339
20340 /*
20341 * When in-kernel, we also print out the stack and code at the
20342 * time of the fault..
20343 */
20344- if (!user_mode_vm(regs)) {
20345+ if (!user_mode(regs)) {
20346 unsigned int code_prologue = code_bytes * 43 / 64;
20347 unsigned int code_len = code_bytes;
20348 unsigned char c;
20349 u8 *ip;
20350+ unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
20351
20352 pr_emerg("Stack:\n");
20353 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
20354
20355 pr_emerg("Code:");
20356
20357- ip = (u8 *)regs->ip - code_prologue;
20358+ ip = (u8 *)regs->ip - code_prologue + cs_base;
20359 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
20360 /* try starting at IP */
20361- ip = (u8 *)regs->ip;
20362+ ip = (u8 *)regs->ip + cs_base;
20363 code_len = code_len - code_prologue + 1;
20364 }
20365 for (i = 0; i < code_len; i++, ip++) {
20366@@ -116,7 +115,7 @@ void show_regs(struct pt_regs *regs)
20367 pr_cont(" Bad EIP value.");
20368 break;
20369 }
20370- if (ip == (u8 *)regs->ip)
20371+ if (ip == (u8 *)regs->ip + cs_base)
20372 pr_cont(" <%02x>", c);
20373 else
20374 pr_cont(" %02x", c);
20375@@ -129,6 +128,7 @@ int is_valid_bugaddr(unsigned long ip)
20376 {
20377 unsigned short ud2;
20378
20379+ ip = ktla_ktva(ip);
20380 if (ip < PAGE_OFFSET)
20381 return 0;
20382 if (probe_kernel_address((unsigned short *)ip, ud2))
20383@@ -136,3 +136,15 @@ int is_valid_bugaddr(unsigned long ip)
20384
20385 return ud2 == 0x0b0f;
20386 }
20387+
20388+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
20389+void pax_check_alloca(unsigned long size)
20390+{
20391+ unsigned long sp = (unsigned long)&sp, stack_left;
20392+
20393+ /* all kernel stacks are of the same size */
20394+ stack_left = sp & (THREAD_SIZE - 1);
20395+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
20396+}
20397+EXPORT_SYMBOL(pax_check_alloca);
20398+#endif
20399diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
20400index addb207..99635fa 100644
20401--- a/arch/x86/kernel/dumpstack_64.c
20402+++ b/arch/x86/kernel/dumpstack_64.c
20403@@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
20404 unsigned long *irq_stack_end =
20405 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
20406 unsigned used = 0;
20407- struct thread_info *tinfo;
20408 int graph = 0;
20409 unsigned long dummy;
20410+ void *stack_start;
20411
20412 if (!task)
20413 task = current;
20414@@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
20415 * current stack address. If the stacks consist of nested
20416 * exceptions
20417 */
20418- tinfo = task_thread_info(task);
20419 for (;;) {
20420 char *id;
20421 unsigned long *estack_end;
20422+
20423 estack_end = in_exception_stack(cpu, (unsigned long)stack,
20424 &used, &id);
20425
20426@@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
20427 if (ops->stack(data, id) < 0)
20428 break;
20429
20430- bp = ops->walk_stack(tinfo, stack, bp, ops,
20431+ bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
20432 data, estack_end, &graph);
20433 ops->stack(data, "<EOE>");
20434 /*
20435@@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
20436 * second-to-last pointer (index -2 to end) in the
20437 * exception stack:
20438 */
20439+ if ((u16)estack_end[-1] != __KERNEL_DS)
20440+ goto out;
20441 stack = (unsigned long *) estack_end[-2];
20442 continue;
20443 }
20444@@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
20445 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
20446 if (ops->stack(data, "IRQ") < 0)
20447 break;
20448- bp = ops->walk_stack(tinfo, stack, bp,
20449+ bp = ops->walk_stack(task, irq_stack, stack, bp,
20450 ops, data, irq_stack_end, &graph);
20451 /*
20452 * We link to the next stack (which would be
20453@@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
20454 /*
20455 * This handles the process stack:
20456 */
20457- bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
20458+ stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
20459+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
20460+out:
20461 put_cpu();
20462 }
20463 EXPORT_SYMBOL(dump_trace);
20464@@ -300,3 +304,50 @@ int is_valid_bugaddr(unsigned long ip)
20465
20466 return ud2 == 0x0b0f;
20467 }
20468+
20469+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
20470+void pax_check_alloca(unsigned long size)
20471+{
20472+ unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
20473+ unsigned cpu, used;
20474+ char *id;
20475+
20476+ /* check the process stack first */
20477+ stack_start = (unsigned long)task_stack_page(current);
20478+ stack_end = stack_start + THREAD_SIZE;
20479+ if (likely(stack_start <= sp && sp < stack_end)) {
20480+ unsigned long stack_left = sp & (THREAD_SIZE - 1);
20481+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
20482+ return;
20483+ }
20484+
20485+ cpu = get_cpu();
20486+
20487+ /* check the irq stacks */
20488+ stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
20489+ stack_start = stack_end - IRQ_STACK_SIZE;
20490+ if (stack_start <= sp && sp < stack_end) {
20491+ unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
20492+ put_cpu();
20493+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
20494+ return;
20495+ }
20496+
20497+ /* check the exception stacks */
20498+ used = 0;
20499+ stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
20500+ stack_start = stack_end - EXCEPTION_STKSZ;
20501+ if (stack_end && stack_start <= sp && sp < stack_end) {
20502+ unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
20503+ put_cpu();
20504+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
20505+ return;
20506+ }
20507+
20508+ put_cpu();
20509+
20510+ /* unknown stack */
20511+ BUG();
20512+}
20513+EXPORT_SYMBOL(pax_check_alloca);
20514+#endif
20515diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
20516index 174da5f..5e55606 100644
20517--- a/arch/x86/kernel/e820.c
20518+++ b/arch/x86/kernel/e820.c
20519@@ -803,8 +803,8 @@ unsigned long __init e820_end_of_low_ram_pfn(void)
20520
20521 static void early_panic(char *msg)
20522 {
20523- early_printk(msg);
20524- panic(msg);
20525+ early_printk("%s", msg);
20526+ panic("%s", msg);
20527 }
20528
20529 static int userdef __initdata;
20530diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
20531index d15f575..d692043 100644
20532--- a/arch/x86/kernel/early_printk.c
20533+++ b/arch/x86/kernel/early_printk.c
20534@@ -7,6 +7,7 @@
20535 #include <linux/pci_regs.h>
20536 #include <linux/pci_ids.h>
20537 #include <linux/errno.h>
20538+#include <linux/sched.h>
20539 #include <asm/io.h>
20540 #include <asm/processor.h>
20541 #include <asm/fcntl.h>
20542diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
20543index f0dcb0c..9f39b80 100644
20544--- a/arch/x86/kernel/entry_32.S
20545+++ b/arch/x86/kernel/entry_32.S
20546@@ -177,13 +177,153 @@
20547 /*CFI_REL_OFFSET gs, PT_GS*/
20548 .endm
20549 .macro SET_KERNEL_GS reg
20550+
20551+#ifdef CONFIG_CC_STACKPROTECTOR
20552 movl $(__KERNEL_STACK_CANARY), \reg
20553+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
20554+ movl $(__USER_DS), \reg
20555+#else
20556+ xorl \reg, \reg
20557+#endif
20558+
20559 movl \reg, %gs
20560 .endm
20561
20562 #endif /* CONFIG_X86_32_LAZY_GS */
20563
20564-.macro SAVE_ALL
20565+.macro pax_enter_kernel
20566+#ifdef CONFIG_PAX_KERNEXEC
20567+ call pax_enter_kernel
20568+#endif
20569+.endm
20570+
20571+.macro pax_exit_kernel
20572+#ifdef CONFIG_PAX_KERNEXEC
20573+ call pax_exit_kernel
20574+#endif
20575+.endm
20576+
20577+#ifdef CONFIG_PAX_KERNEXEC
20578+ENTRY(pax_enter_kernel)
20579+#ifdef CONFIG_PARAVIRT
20580+ pushl %eax
20581+ pushl %ecx
20582+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
20583+ mov %eax, %esi
20584+#else
20585+ mov %cr0, %esi
20586+#endif
20587+ bts $16, %esi
20588+ jnc 1f
20589+ mov %cs, %esi
20590+ cmp $__KERNEL_CS, %esi
20591+ jz 3f
20592+ ljmp $__KERNEL_CS, $3f
20593+1: ljmp $__KERNEXEC_KERNEL_CS, $2f
20594+2:
20595+#ifdef CONFIG_PARAVIRT
20596+ mov %esi, %eax
20597+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
20598+#else
20599+ mov %esi, %cr0
20600+#endif
20601+3:
20602+#ifdef CONFIG_PARAVIRT
20603+ popl %ecx
20604+ popl %eax
20605+#endif
20606+ ret
20607+ENDPROC(pax_enter_kernel)
20608+
20609+ENTRY(pax_exit_kernel)
20610+#ifdef CONFIG_PARAVIRT
20611+ pushl %eax
20612+ pushl %ecx
20613+#endif
20614+ mov %cs, %esi
20615+ cmp $__KERNEXEC_KERNEL_CS, %esi
20616+ jnz 2f
20617+#ifdef CONFIG_PARAVIRT
20618+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
20619+ mov %eax, %esi
20620+#else
20621+ mov %cr0, %esi
20622+#endif
20623+ btr $16, %esi
20624+ ljmp $__KERNEL_CS, $1f
20625+1:
20626+#ifdef CONFIG_PARAVIRT
20627+ mov %esi, %eax
20628+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
20629+#else
20630+ mov %esi, %cr0
20631+#endif
20632+2:
20633+#ifdef CONFIG_PARAVIRT
20634+ popl %ecx
20635+ popl %eax
20636+#endif
20637+ ret
20638+ENDPROC(pax_exit_kernel)
20639+#endif
20640+
20641+ .macro pax_erase_kstack
20642+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
20643+ call pax_erase_kstack
20644+#endif
20645+ .endm
20646+
20647+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
20648+/*
20649+ * ebp: thread_info
20650+ */
20651+ENTRY(pax_erase_kstack)
20652+ pushl %edi
20653+ pushl %ecx
20654+ pushl %eax
20655+
20656+ mov TI_lowest_stack(%ebp), %edi
20657+ mov $-0xBEEF, %eax
20658+ std
20659+
20660+1: mov %edi, %ecx
20661+ and $THREAD_SIZE_asm - 1, %ecx
20662+ shr $2, %ecx
20663+ repne scasl
20664+ jecxz 2f
20665+
20666+ cmp $2*16, %ecx
20667+ jc 2f
20668+
20669+ mov $2*16, %ecx
20670+ repe scasl
20671+ jecxz 2f
20672+ jne 1b
20673+
20674+2: cld
20675+ mov %esp, %ecx
20676+ sub %edi, %ecx
20677+
20678+ cmp $THREAD_SIZE_asm, %ecx
20679+ jb 3f
20680+ ud2
20681+3:
20682+
20683+ shr $2, %ecx
20684+ rep stosl
20685+
20686+ mov TI_task_thread_sp0(%ebp), %edi
20687+ sub $128, %edi
20688+ mov %edi, TI_lowest_stack(%ebp)
20689+
20690+ popl %eax
20691+ popl %ecx
20692+ popl %edi
20693+ ret
20694+ENDPROC(pax_erase_kstack)
20695+#endif
20696+
20697+.macro __SAVE_ALL _DS
20698 cld
20699 PUSH_GS
20700 pushl_cfi %fs
20701@@ -206,7 +346,7 @@
20702 CFI_REL_OFFSET ecx, 0
20703 pushl_cfi %ebx
20704 CFI_REL_OFFSET ebx, 0
20705- movl $(__USER_DS), %edx
20706+ movl $\_DS, %edx
20707 movl %edx, %ds
20708 movl %edx, %es
20709 movl $(__KERNEL_PERCPU), %edx
20710@@ -214,6 +354,15 @@
20711 SET_KERNEL_GS %edx
20712 .endm
20713
20714+.macro SAVE_ALL
20715+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
20716+ __SAVE_ALL __KERNEL_DS
20717+ pax_enter_kernel
20718+#else
20719+ __SAVE_ALL __USER_DS
20720+#endif
20721+.endm
20722+
20723 .macro RESTORE_INT_REGS
20724 popl_cfi %ebx
20725 CFI_RESTORE ebx
20726@@ -297,7 +446,7 @@ ENTRY(ret_from_fork)
20727 popfl_cfi
20728 jmp syscall_exit
20729 CFI_ENDPROC
20730-END(ret_from_fork)
20731+ENDPROC(ret_from_fork)
20732
20733 ENTRY(ret_from_kernel_thread)
20734 CFI_STARTPROC
20735@@ -344,7 +493,15 @@ ret_from_intr:
20736 andl $SEGMENT_RPL_MASK, %eax
20737 #endif
20738 cmpl $USER_RPL, %eax
20739+
20740+#ifdef CONFIG_PAX_KERNEXEC
20741+ jae resume_userspace
20742+
20743+ pax_exit_kernel
20744+ jmp resume_kernel
20745+#else
20746 jb resume_kernel # not returning to v8086 or userspace
20747+#endif
20748
20749 ENTRY(resume_userspace)
20750 LOCKDEP_SYS_EXIT
20751@@ -356,8 +513,8 @@ ENTRY(resume_userspace)
20752 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
20753 # int/exception return?
20754 jne work_pending
20755- jmp restore_all
20756-END(ret_from_exception)
20757+ jmp restore_all_pax
20758+ENDPROC(ret_from_exception)
20759
20760 #ifdef CONFIG_PREEMPT
20761 ENTRY(resume_kernel)
20762@@ -372,7 +529,7 @@ need_resched:
20763 jz restore_all
20764 call preempt_schedule_irq
20765 jmp need_resched
20766-END(resume_kernel)
20767+ENDPROC(resume_kernel)
20768 #endif
20769 CFI_ENDPROC
20770 /*
20771@@ -406,30 +563,45 @@ sysenter_past_esp:
20772 /*CFI_REL_OFFSET cs, 0*/
20773 /*
20774 * Push current_thread_info()->sysenter_return to the stack.
20775- * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
20776- * pushed above; +8 corresponds to copy_thread's esp0 setting.
20777 */
20778- pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
20779+ pushl_cfi $0
20780 CFI_REL_OFFSET eip, 0
20781
20782 pushl_cfi %eax
20783 SAVE_ALL
20784+ GET_THREAD_INFO(%ebp)
20785+ movl TI_sysenter_return(%ebp),%ebp
20786+ movl %ebp,PT_EIP(%esp)
20787 ENABLE_INTERRUPTS(CLBR_NONE)
20788
20789 /*
20790 * Load the potential sixth argument from user stack.
20791 * Careful about security.
20792 */
20793+ movl PT_OLDESP(%esp),%ebp
20794+
20795+#ifdef CONFIG_PAX_MEMORY_UDEREF
20796+ mov PT_OLDSS(%esp),%ds
20797+1: movl %ds:(%ebp),%ebp
20798+ push %ss
20799+ pop %ds
20800+#else
20801 cmpl $__PAGE_OFFSET-3,%ebp
20802 jae syscall_fault
20803 ASM_STAC
20804 1: movl (%ebp),%ebp
20805 ASM_CLAC
20806+#endif
20807+
20808 movl %ebp,PT_EBP(%esp)
20809 _ASM_EXTABLE(1b,syscall_fault)
20810
20811 GET_THREAD_INFO(%ebp)
20812
20813+#ifdef CONFIG_PAX_RANDKSTACK
20814+ pax_erase_kstack
20815+#endif
20816+
20817 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
20818 jnz sysenter_audit
20819 sysenter_do_call:
20820@@ -444,12 +616,24 @@ sysenter_do_call:
20821 testl $_TIF_ALLWORK_MASK, %ecx
20822 jne sysexit_audit
20823 sysenter_exit:
20824+
20825+#ifdef CONFIG_PAX_RANDKSTACK
20826+ pushl_cfi %eax
20827+ movl %esp, %eax
20828+ call pax_randomize_kstack
20829+ popl_cfi %eax
20830+#endif
20831+
20832+ pax_erase_kstack
20833+
20834 /* if something modifies registers it must also disable sysexit */
20835 movl PT_EIP(%esp), %edx
20836 movl PT_OLDESP(%esp), %ecx
20837 xorl %ebp,%ebp
20838 TRACE_IRQS_ON
20839 1: mov PT_FS(%esp), %fs
20840+2: mov PT_DS(%esp), %ds
20841+3: mov PT_ES(%esp), %es
20842 PTGS_TO_GS
20843 ENABLE_INTERRUPTS_SYSEXIT
20844
20845@@ -466,6 +650,9 @@ sysenter_audit:
20846 movl %eax,%edx /* 2nd arg: syscall number */
20847 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
20848 call __audit_syscall_entry
20849+
20850+ pax_erase_kstack
20851+
20852 pushl_cfi %ebx
20853 movl PT_EAX(%esp),%eax /* reload syscall number */
20854 jmp sysenter_do_call
20855@@ -491,10 +678,16 @@ sysexit_audit:
20856
20857 CFI_ENDPROC
20858 .pushsection .fixup,"ax"
20859-2: movl $0,PT_FS(%esp)
20860+4: movl $0,PT_FS(%esp)
20861+ jmp 1b
20862+5: movl $0,PT_DS(%esp)
20863+ jmp 1b
20864+6: movl $0,PT_ES(%esp)
20865 jmp 1b
20866 .popsection
20867- _ASM_EXTABLE(1b,2b)
20868+ _ASM_EXTABLE(1b,4b)
20869+ _ASM_EXTABLE(2b,5b)
20870+ _ASM_EXTABLE(3b,6b)
20871 PTGS_TO_GS_EX
20872 ENDPROC(ia32_sysenter_target)
20873
20874@@ -509,6 +702,11 @@ ENTRY(system_call)
20875 pushl_cfi %eax # save orig_eax
20876 SAVE_ALL
20877 GET_THREAD_INFO(%ebp)
20878+
20879+#ifdef CONFIG_PAX_RANDKSTACK
20880+ pax_erase_kstack
20881+#endif
20882+
20883 # system call tracing in operation / emulation
20884 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
20885 jnz syscall_trace_entry
20886@@ -527,6 +725,15 @@ syscall_exit:
20887 testl $_TIF_ALLWORK_MASK, %ecx # current->work
20888 jne syscall_exit_work
20889
20890+restore_all_pax:
20891+
20892+#ifdef CONFIG_PAX_RANDKSTACK
20893+ movl %esp, %eax
20894+ call pax_randomize_kstack
20895+#endif
20896+
20897+ pax_erase_kstack
20898+
20899 restore_all:
20900 TRACE_IRQS_IRET
20901 restore_all_notrace:
20902@@ -583,14 +790,34 @@ ldt_ss:
20903 * compensating for the offset by changing to the ESPFIX segment with
20904 * a base address that matches for the difference.
20905 */
20906-#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
20907+#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
20908 mov %esp, %edx /* load kernel esp */
20909 mov PT_OLDESP(%esp), %eax /* load userspace esp */
20910 mov %dx, %ax /* eax: new kernel esp */
20911 sub %eax, %edx /* offset (low word is 0) */
20912+#ifdef CONFIG_SMP
20913+ movl PER_CPU_VAR(cpu_number), %ebx
20914+ shll $PAGE_SHIFT_asm, %ebx
20915+ addl $cpu_gdt_table, %ebx
20916+#else
20917+ movl $cpu_gdt_table, %ebx
20918+#endif
20919 shr $16, %edx
20920- mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
20921- mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
20922+
20923+#ifdef CONFIG_PAX_KERNEXEC
20924+ mov %cr0, %esi
20925+ btr $16, %esi
20926+ mov %esi, %cr0
20927+#endif
20928+
20929+ mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
20930+ mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
20931+
20932+#ifdef CONFIG_PAX_KERNEXEC
20933+ bts $16, %esi
20934+ mov %esi, %cr0
20935+#endif
20936+
20937 pushl_cfi $__ESPFIX_SS
20938 pushl_cfi %eax /* new kernel esp */
20939 /* Disable interrupts, but do not irqtrace this section: we
20940@@ -619,20 +846,18 @@ work_resched:
20941 movl TI_flags(%ebp), %ecx
20942 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
20943 # than syscall tracing?
20944- jz restore_all
20945+ jz restore_all_pax
20946 testb $_TIF_NEED_RESCHED, %cl
20947 jnz work_resched
20948
20949 work_notifysig: # deal with pending signals and
20950 # notify-resume requests
20951+ movl %esp, %eax
20952 #ifdef CONFIG_VM86
20953 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
20954- movl %esp, %eax
20955 jne work_notifysig_v86 # returning to kernel-space or
20956 # vm86-space
20957 1:
20958-#else
20959- movl %esp, %eax
20960 #endif
20961 TRACE_IRQS_ON
20962 ENABLE_INTERRUPTS(CLBR_NONE)
20963@@ -653,7 +878,7 @@ work_notifysig_v86:
20964 movl %eax, %esp
20965 jmp 1b
20966 #endif
20967-END(work_pending)
20968+ENDPROC(work_pending)
20969
20970 # perform syscall exit tracing
20971 ALIGN
20972@@ -661,11 +886,14 @@ syscall_trace_entry:
20973 movl $-ENOSYS,PT_EAX(%esp)
20974 movl %esp, %eax
20975 call syscall_trace_enter
20976+
20977+ pax_erase_kstack
20978+
20979 /* What it returned is what we'll actually use. */
20980 cmpl $(NR_syscalls), %eax
20981 jnae syscall_call
20982 jmp syscall_exit
20983-END(syscall_trace_entry)
20984+ENDPROC(syscall_trace_entry)
20985
20986 # perform syscall exit tracing
20987 ALIGN
20988@@ -678,21 +906,25 @@ syscall_exit_work:
20989 movl %esp, %eax
20990 call syscall_trace_leave
20991 jmp resume_userspace
20992-END(syscall_exit_work)
20993+ENDPROC(syscall_exit_work)
20994 CFI_ENDPROC
20995
20996 RING0_INT_FRAME # can't unwind into user space anyway
20997 syscall_fault:
20998+#ifdef CONFIG_PAX_MEMORY_UDEREF
20999+ push %ss
21000+ pop %ds
21001+#endif
21002 ASM_CLAC
21003 GET_THREAD_INFO(%ebp)
21004 movl $-EFAULT,PT_EAX(%esp)
21005 jmp resume_userspace
21006-END(syscall_fault)
21007+ENDPROC(syscall_fault)
21008
21009 syscall_badsys:
21010 movl $-ENOSYS,PT_EAX(%esp)
21011 jmp resume_userspace
21012-END(syscall_badsys)
21013+ENDPROC(syscall_badsys)
21014 CFI_ENDPROC
21015 /*
21016 * End of kprobes section
21017@@ -708,8 +940,15 @@ END(syscall_badsys)
21018 * normal stack and adjusts ESP with the matching offset.
21019 */
21020 /* fixup the stack */
21021- mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
21022- mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
21023+#ifdef CONFIG_SMP
21024+ movl PER_CPU_VAR(cpu_number), %ebx
21025+ shll $PAGE_SHIFT_asm, %ebx
21026+ addl $cpu_gdt_table, %ebx
21027+#else
21028+ movl $cpu_gdt_table, %ebx
21029+#endif
21030+ mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
21031+ mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
21032 shl $16, %eax
21033 addl %esp, %eax /* the adjusted stack pointer */
21034 pushl_cfi $__KERNEL_DS
21035@@ -762,7 +1001,7 @@ vector=vector+1
21036 .endr
21037 2: jmp common_interrupt
21038 .endr
21039-END(irq_entries_start)
21040+ENDPROC(irq_entries_start)
21041
21042 .previous
21043 END(interrupt)
21044@@ -823,7 +1062,7 @@ ENTRY(coprocessor_error)
21045 pushl_cfi $do_coprocessor_error
21046 jmp error_code
21047 CFI_ENDPROC
21048-END(coprocessor_error)
21049+ENDPROC(coprocessor_error)
21050
21051 ENTRY(simd_coprocessor_error)
21052 RING0_INT_FRAME
21053@@ -836,7 +1075,7 @@ ENTRY(simd_coprocessor_error)
21054 .section .altinstructions,"a"
21055 altinstruction_entry 661b, 663f, X86_FEATURE_XMM, 662b-661b, 664f-663f
21056 .previous
21057-.section .altinstr_replacement,"ax"
21058+.section .altinstr_replacement,"a"
21059 663: pushl $do_simd_coprocessor_error
21060 664:
21061 .previous
21062@@ -845,7 +1084,7 @@ ENTRY(simd_coprocessor_error)
21063 #endif
21064 jmp error_code
21065 CFI_ENDPROC
21066-END(simd_coprocessor_error)
21067+ENDPROC(simd_coprocessor_error)
21068
21069 ENTRY(device_not_available)
21070 RING0_INT_FRAME
21071@@ -854,18 +1093,18 @@ ENTRY(device_not_available)
21072 pushl_cfi $do_device_not_available
21073 jmp error_code
21074 CFI_ENDPROC
21075-END(device_not_available)
21076+ENDPROC(device_not_available)
21077
21078 #ifdef CONFIG_PARAVIRT
21079 ENTRY(native_iret)
21080 iret
21081 _ASM_EXTABLE(native_iret, iret_exc)
21082-END(native_iret)
21083+ENDPROC(native_iret)
21084
21085 ENTRY(native_irq_enable_sysexit)
21086 sti
21087 sysexit
21088-END(native_irq_enable_sysexit)
21089+ENDPROC(native_irq_enable_sysexit)
21090 #endif
21091
21092 ENTRY(overflow)
21093@@ -875,7 +1114,7 @@ ENTRY(overflow)
21094 pushl_cfi $do_overflow
21095 jmp error_code
21096 CFI_ENDPROC
21097-END(overflow)
21098+ENDPROC(overflow)
21099
21100 ENTRY(bounds)
21101 RING0_INT_FRAME
21102@@ -884,7 +1123,7 @@ ENTRY(bounds)
21103 pushl_cfi $do_bounds
21104 jmp error_code
21105 CFI_ENDPROC
21106-END(bounds)
21107+ENDPROC(bounds)
21108
21109 ENTRY(invalid_op)
21110 RING0_INT_FRAME
21111@@ -893,7 +1132,7 @@ ENTRY(invalid_op)
21112 pushl_cfi $do_invalid_op
21113 jmp error_code
21114 CFI_ENDPROC
21115-END(invalid_op)
21116+ENDPROC(invalid_op)
21117
21118 ENTRY(coprocessor_segment_overrun)
21119 RING0_INT_FRAME
21120@@ -902,7 +1141,7 @@ ENTRY(coprocessor_segment_overrun)
21121 pushl_cfi $do_coprocessor_segment_overrun
21122 jmp error_code
21123 CFI_ENDPROC
21124-END(coprocessor_segment_overrun)
21125+ENDPROC(coprocessor_segment_overrun)
21126
21127 ENTRY(invalid_TSS)
21128 RING0_EC_FRAME
21129@@ -910,7 +1149,7 @@ ENTRY(invalid_TSS)
21130 pushl_cfi $do_invalid_TSS
21131 jmp error_code
21132 CFI_ENDPROC
21133-END(invalid_TSS)
21134+ENDPROC(invalid_TSS)
21135
21136 ENTRY(segment_not_present)
21137 RING0_EC_FRAME
21138@@ -918,7 +1157,7 @@ ENTRY(segment_not_present)
21139 pushl_cfi $do_segment_not_present
21140 jmp error_code
21141 CFI_ENDPROC
21142-END(segment_not_present)
21143+ENDPROC(segment_not_present)
21144
21145 ENTRY(stack_segment)
21146 RING0_EC_FRAME
21147@@ -926,7 +1165,7 @@ ENTRY(stack_segment)
21148 pushl_cfi $do_stack_segment
21149 jmp error_code
21150 CFI_ENDPROC
21151-END(stack_segment)
21152+ENDPROC(stack_segment)
21153
21154 ENTRY(alignment_check)
21155 RING0_EC_FRAME
21156@@ -934,7 +1173,7 @@ ENTRY(alignment_check)
21157 pushl_cfi $do_alignment_check
21158 jmp error_code
21159 CFI_ENDPROC
21160-END(alignment_check)
21161+ENDPROC(alignment_check)
21162
21163 ENTRY(divide_error)
21164 RING0_INT_FRAME
21165@@ -943,7 +1182,7 @@ ENTRY(divide_error)
21166 pushl_cfi $do_divide_error
21167 jmp error_code
21168 CFI_ENDPROC
21169-END(divide_error)
21170+ENDPROC(divide_error)
21171
21172 #ifdef CONFIG_X86_MCE
21173 ENTRY(machine_check)
21174@@ -953,7 +1192,7 @@ ENTRY(machine_check)
21175 pushl_cfi machine_check_vector
21176 jmp error_code
21177 CFI_ENDPROC
21178-END(machine_check)
21179+ENDPROC(machine_check)
21180 #endif
21181
21182 ENTRY(spurious_interrupt_bug)
21183@@ -963,7 +1202,7 @@ ENTRY(spurious_interrupt_bug)
21184 pushl_cfi $do_spurious_interrupt_bug
21185 jmp error_code
21186 CFI_ENDPROC
21187-END(spurious_interrupt_bug)
21188+ENDPROC(spurious_interrupt_bug)
21189 /*
21190 * End of kprobes section
21191 */
21192@@ -1073,7 +1312,7 @@ BUILD_INTERRUPT3(hyperv_callback_vector, HYPERVISOR_CALLBACK_VECTOR,
21193
21194 ENTRY(mcount)
21195 ret
21196-END(mcount)
21197+ENDPROC(mcount)
21198
21199 ENTRY(ftrace_caller)
21200 cmpl $0, function_trace_stop
21201@@ -1106,7 +1345,7 @@ ftrace_graph_call:
21202 .globl ftrace_stub
21203 ftrace_stub:
21204 ret
21205-END(ftrace_caller)
21206+ENDPROC(ftrace_caller)
21207
21208 ENTRY(ftrace_regs_caller)
21209 pushf /* push flags before compare (in cs location) */
21210@@ -1210,7 +1449,7 @@ trace:
21211 popl %ecx
21212 popl %eax
21213 jmp ftrace_stub
21214-END(mcount)
21215+ENDPROC(mcount)
21216 #endif /* CONFIG_DYNAMIC_FTRACE */
21217 #endif /* CONFIG_FUNCTION_TRACER */
21218
21219@@ -1228,7 +1467,7 @@ ENTRY(ftrace_graph_caller)
21220 popl %ecx
21221 popl %eax
21222 ret
21223-END(ftrace_graph_caller)
21224+ENDPROC(ftrace_graph_caller)
21225
21226 .globl return_to_handler
21227 return_to_handler:
21228@@ -1284,15 +1523,18 @@ error_code:
21229 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
21230 REG_TO_PTGS %ecx
21231 SET_KERNEL_GS %ecx
21232- movl $(__USER_DS), %ecx
21233+ movl $(__KERNEL_DS), %ecx
21234 movl %ecx, %ds
21235 movl %ecx, %es
21236+
21237+ pax_enter_kernel
21238+
21239 TRACE_IRQS_OFF
21240 movl %esp,%eax # pt_regs pointer
21241 call *%edi
21242 jmp ret_from_exception
21243 CFI_ENDPROC
21244-END(page_fault)
21245+ENDPROC(page_fault)
21246
21247 /*
21248 * Debug traps and NMI can happen at the one SYSENTER instruction
21249@@ -1335,7 +1577,7 @@ debug_stack_correct:
21250 call do_debug
21251 jmp ret_from_exception
21252 CFI_ENDPROC
21253-END(debug)
21254+ENDPROC(debug)
21255
21256 /*
21257 * NMI is doubly nasty. It can happen _while_ we're handling
21258@@ -1373,6 +1615,9 @@ nmi_stack_correct:
21259 xorl %edx,%edx # zero error code
21260 movl %esp,%eax # pt_regs pointer
21261 call do_nmi
21262+
21263+ pax_exit_kernel
21264+
21265 jmp restore_all_notrace
21266 CFI_ENDPROC
21267
21268@@ -1409,12 +1654,15 @@ nmi_espfix_stack:
21269 FIXUP_ESPFIX_STACK # %eax == %esp
21270 xorl %edx,%edx # zero error code
21271 call do_nmi
21272+
21273+ pax_exit_kernel
21274+
21275 RESTORE_REGS
21276 lss 12+4(%esp), %esp # back to espfix stack
21277 CFI_ADJUST_CFA_OFFSET -24
21278 jmp irq_return
21279 CFI_ENDPROC
21280-END(nmi)
21281+ENDPROC(nmi)
21282
21283 ENTRY(int3)
21284 RING0_INT_FRAME
21285@@ -1427,14 +1675,14 @@ ENTRY(int3)
21286 call do_int3
21287 jmp ret_from_exception
21288 CFI_ENDPROC
21289-END(int3)
21290+ENDPROC(int3)
21291
21292 ENTRY(general_protection)
21293 RING0_EC_FRAME
21294 pushl_cfi $do_general_protection
21295 jmp error_code
21296 CFI_ENDPROC
21297-END(general_protection)
21298+ENDPROC(general_protection)
21299
21300 #ifdef CONFIG_KVM_GUEST
21301 ENTRY(async_page_fault)
21302@@ -1443,7 +1691,7 @@ ENTRY(async_page_fault)
21303 pushl_cfi $do_async_page_fault
21304 jmp error_code
21305 CFI_ENDPROC
21306-END(async_page_fault)
21307+ENDPROC(async_page_fault)
21308 #endif
21309
21310 /*
21311diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
21312index b077f4c..feb26c1 100644
21313--- a/arch/x86/kernel/entry_64.S
21314+++ b/arch/x86/kernel/entry_64.S
21315@@ -59,6 +59,8 @@
21316 #include <asm/context_tracking.h>
21317 #include <asm/smap.h>
21318 #include <linux/err.h>
21319+#include <asm/pgtable.h>
21320+#include <asm/alternative-asm.h>
21321
21322 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
21323 #include <linux/elf-em.h>
21324@@ -80,8 +82,9 @@
21325 #ifdef CONFIG_DYNAMIC_FTRACE
21326
21327 ENTRY(function_hook)
21328+ pax_force_retaddr
21329 retq
21330-END(function_hook)
21331+ENDPROC(function_hook)
21332
21333 /* skip is set if stack has been adjusted */
21334 .macro ftrace_caller_setup skip=0
21335@@ -122,8 +125,9 @@ GLOBAL(ftrace_graph_call)
21336 #endif
21337
21338 GLOBAL(ftrace_stub)
21339+ pax_force_retaddr
21340 retq
21341-END(ftrace_caller)
21342+ENDPROC(ftrace_caller)
21343
21344 ENTRY(ftrace_regs_caller)
21345 /* Save the current flags before compare (in SS location)*/
21346@@ -191,7 +195,7 @@ ftrace_restore_flags:
21347 popfq
21348 jmp ftrace_stub
21349
21350-END(ftrace_regs_caller)
21351+ENDPROC(ftrace_regs_caller)
21352
21353
21354 #else /* ! CONFIG_DYNAMIC_FTRACE */
21355@@ -212,6 +216,7 @@ ENTRY(function_hook)
21356 #endif
21357
21358 GLOBAL(ftrace_stub)
21359+ pax_force_retaddr
21360 retq
21361
21362 trace:
21363@@ -225,12 +230,13 @@ trace:
21364 #endif
21365 subq $MCOUNT_INSN_SIZE, %rdi
21366
21367+ pax_force_fptr ftrace_trace_function
21368 call *ftrace_trace_function
21369
21370 MCOUNT_RESTORE_FRAME
21371
21372 jmp ftrace_stub
21373-END(function_hook)
21374+ENDPROC(function_hook)
21375 #endif /* CONFIG_DYNAMIC_FTRACE */
21376 #endif /* CONFIG_FUNCTION_TRACER */
21377
21378@@ -252,8 +258,9 @@ ENTRY(ftrace_graph_caller)
21379
21380 MCOUNT_RESTORE_FRAME
21381
21382+ pax_force_retaddr
21383 retq
21384-END(ftrace_graph_caller)
21385+ENDPROC(ftrace_graph_caller)
21386
21387 GLOBAL(return_to_handler)
21388 subq $24, %rsp
21389@@ -269,7 +276,9 @@ GLOBAL(return_to_handler)
21390 movq 8(%rsp), %rdx
21391 movq (%rsp), %rax
21392 addq $24, %rsp
21393+ pax_force_fptr %rdi
21394 jmp *%rdi
21395+ENDPROC(return_to_handler)
21396 #endif
21397
21398
21399@@ -284,6 +293,430 @@ ENTRY(native_usergs_sysret64)
21400 ENDPROC(native_usergs_sysret64)
21401 #endif /* CONFIG_PARAVIRT */
21402
21403+ .macro ljmpq sel, off
21404+#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
21405+ .byte 0x48; ljmp *1234f(%rip)
21406+ .pushsection .rodata
21407+ .align 16
21408+ 1234: .quad \off; .word \sel
21409+ .popsection
21410+#else
21411+ pushq $\sel
21412+ pushq $\off
21413+ lretq
21414+#endif
21415+ .endm
21416+
21417+ .macro pax_enter_kernel
21418+ pax_set_fptr_mask
21419+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
21420+ call pax_enter_kernel
21421+#endif
21422+ .endm
21423+
21424+ .macro pax_exit_kernel
21425+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
21426+ call pax_exit_kernel
21427+#endif
21428+
21429+ .endm
21430+
21431+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
21432+ENTRY(pax_enter_kernel)
21433+ pushq %rdi
21434+
21435+#ifdef CONFIG_PARAVIRT
21436+ PV_SAVE_REGS(CLBR_RDI)
21437+#endif
21438+
21439+#ifdef CONFIG_PAX_KERNEXEC
21440+ GET_CR0_INTO_RDI
21441+ bts $16,%rdi
21442+ jnc 3f
21443+ mov %cs,%edi
21444+ cmp $__KERNEL_CS,%edi
21445+ jnz 2f
21446+1:
21447+#endif
21448+
21449+#ifdef CONFIG_PAX_MEMORY_UDEREF
21450+ 661: jmp 111f
21451+ .pushsection .altinstr_replacement, "a"
21452+ 662: ASM_NOP2
21453+ .popsection
21454+ .pushsection .altinstructions, "a"
21455+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
21456+ .popsection
21457+ GET_CR3_INTO_RDI
21458+ cmp $0,%dil
21459+ jnz 112f
21460+ mov $__KERNEL_DS,%edi
21461+ mov %edi,%ss
21462+ jmp 111f
21463+112: cmp $1,%dil
21464+ jz 113f
21465+ ud2
21466+113: sub $4097,%rdi
21467+ bts $63,%rdi
21468+ SET_RDI_INTO_CR3
21469+ mov $__UDEREF_KERNEL_DS,%edi
21470+ mov %edi,%ss
21471+111:
21472+#endif
21473+
21474+#ifdef CONFIG_PARAVIRT
21475+ PV_RESTORE_REGS(CLBR_RDI)
21476+#endif
21477+
21478+ popq %rdi
21479+ pax_force_retaddr
21480+ retq
21481+
21482+#ifdef CONFIG_PAX_KERNEXEC
21483+2: ljmpq __KERNEL_CS,1b
21484+3: ljmpq __KERNEXEC_KERNEL_CS,4f
21485+4: SET_RDI_INTO_CR0
21486+ jmp 1b
21487+#endif
21488+ENDPROC(pax_enter_kernel)
21489+
21490+ENTRY(pax_exit_kernel)
21491+ pushq %rdi
21492+
21493+#ifdef CONFIG_PARAVIRT
21494+ PV_SAVE_REGS(CLBR_RDI)
21495+#endif
21496+
21497+#ifdef CONFIG_PAX_KERNEXEC
21498+ mov %cs,%rdi
21499+ cmp $__KERNEXEC_KERNEL_CS,%edi
21500+ jz 2f
21501+ GET_CR0_INTO_RDI
21502+ bts $16,%rdi
21503+ jnc 4f
21504+1:
21505+#endif
21506+
21507+#ifdef CONFIG_PAX_MEMORY_UDEREF
21508+ 661: jmp 111f
21509+ .pushsection .altinstr_replacement, "a"
21510+ 662: ASM_NOP2
21511+ .popsection
21512+ .pushsection .altinstructions, "a"
21513+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
21514+ .popsection
21515+ mov %ss,%edi
21516+ cmp $__UDEREF_KERNEL_DS,%edi
21517+ jnz 111f
21518+ GET_CR3_INTO_RDI
21519+ cmp $0,%dil
21520+ jz 112f
21521+ ud2
21522+112: add $4097,%rdi
21523+ bts $63,%rdi
21524+ SET_RDI_INTO_CR3
21525+ mov $__KERNEL_DS,%edi
21526+ mov %edi,%ss
21527+111:
21528+#endif
21529+
21530+#ifdef CONFIG_PARAVIRT
21531+ PV_RESTORE_REGS(CLBR_RDI);
21532+#endif
21533+
21534+ popq %rdi
21535+ pax_force_retaddr
21536+ retq
21537+
21538+#ifdef CONFIG_PAX_KERNEXEC
21539+2: GET_CR0_INTO_RDI
21540+ btr $16,%rdi
21541+ jnc 4f
21542+ ljmpq __KERNEL_CS,3f
21543+3: SET_RDI_INTO_CR0
21544+ jmp 1b
21545+4: ud2
21546+ jmp 4b
21547+#endif
21548+ENDPROC(pax_exit_kernel)
21549+#endif
21550+
21551+ .macro pax_enter_kernel_user
21552+ pax_set_fptr_mask
21553+#ifdef CONFIG_PAX_MEMORY_UDEREF
21554+ call pax_enter_kernel_user
21555+#endif
21556+ .endm
21557+
21558+ .macro pax_exit_kernel_user
21559+#ifdef CONFIG_PAX_MEMORY_UDEREF
21560+ call pax_exit_kernel_user
21561+#endif
21562+#ifdef CONFIG_PAX_RANDKSTACK
21563+ pushq %rax
21564+ pushq %r11
21565+ call pax_randomize_kstack
21566+ popq %r11
21567+ popq %rax
21568+#endif
21569+ .endm
21570+
21571+#ifdef CONFIG_PAX_MEMORY_UDEREF
21572+ENTRY(pax_enter_kernel_user)
21573+ pushq %rdi
21574+ pushq %rbx
21575+
21576+#ifdef CONFIG_PARAVIRT
21577+ PV_SAVE_REGS(CLBR_RDI)
21578+#endif
21579+
21580+ 661: jmp 111f
21581+ .pushsection .altinstr_replacement, "a"
21582+ 662: ASM_NOP2
21583+ .popsection
21584+ .pushsection .altinstructions, "a"
21585+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
21586+ .popsection
21587+ GET_CR3_INTO_RDI
21588+ cmp $1,%dil
21589+ jnz 4f
21590+ sub $4097,%rdi
21591+ bts $63,%rdi
21592+ SET_RDI_INTO_CR3
21593+ jmp 3f
21594+111:
21595+
21596+ GET_CR3_INTO_RDI
21597+ mov %rdi,%rbx
21598+ add $__START_KERNEL_map,%rbx
21599+ sub phys_base(%rip),%rbx
21600+
21601+#ifdef CONFIG_PARAVIRT
21602+ cmpl $0, pv_info+PARAVIRT_enabled
21603+ jz 1f
21604+ pushq %rdi
21605+ i = 0
21606+ .rept USER_PGD_PTRS
21607+ mov i*8(%rbx),%rsi
21608+ mov $0,%sil
21609+ lea i*8(%rbx),%rdi
21610+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
21611+ i = i + 1
21612+ .endr
21613+ popq %rdi
21614+ jmp 2f
21615+1:
21616+#endif
21617+
21618+ i = 0
21619+ .rept USER_PGD_PTRS
21620+ movb $0,i*8(%rbx)
21621+ i = i + 1
21622+ .endr
21623+
21624+2: SET_RDI_INTO_CR3
21625+
21626+#ifdef CONFIG_PAX_KERNEXEC
21627+ GET_CR0_INTO_RDI
21628+ bts $16,%rdi
21629+ SET_RDI_INTO_CR0
21630+#endif
21631+
21632+3:
21633+
21634+#ifdef CONFIG_PARAVIRT
21635+ PV_RESTORE_REGS(CLBR_RDI)
21636+#endif
21637+
21638+ popq %rbx
21639+ popq %rdi
21640+ pax_force_retaddr
21641+ retq
21642+4: ud2
21643+ENDPROC(pax_enter_kernel_user)
21644+
21645+ENTRY(pax_exit_kernel_user)
21646+ pushq %rdi
21647+ pushq %rbx
21648+
21649+#ifdef CONFIG_PARAVIRT
21650+ PV_SAVE_REGS(CLBR_RDI)
21651+#endif
21652+
21653+ GET_CR3_INTO_RDI
21654+ 661: jmp 1f
21655+ .pushsection .altinstr_replacement, "a"
21656+ 662: ASM_NOP2
21657+ .popsection
21658+ .pushsection .altinstructions, "a"
21659+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
21660+ .popsection
21661+ cmp $0,%dil
21662+ jnz 3f
21663+ add $4097,%rdi
21664+ bts $63,%rdi
21665+ SET_RDI_INTO_CR3
21666+ jmp 2f
21667+1:
21668+
21669+ mov %rdi,%rbx
21670+
21671+#ifdef CONFIG_PAX_KERNEXEC
21672+ GET_CR0_INTO_RDI
21673+ btr $16,%rdi
21674+ jnc 3f
21675+ SET_RDI_INTO_CR0
21676+#endif
21677+
21678+ add $__START_KERNEL_map,%rbx
21679+ sub phys_base(%rip),%rbx
21680+
21681+#ifdef CONFIG_PARAVIRT
21682+ cmpl $0, pv_info+PARAVIRT_enabled
21683+ jz 1f
21684+ i = 0
21685+ .rept USER_PGD_PTRS
21686+ mov i*8(%rbx),%rsi
21687+ mov $0x67,%sil
21688+ lea i*8(%rbx),%rdi
21689+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
21690+ i = i + 1
21691+ .endr
21692+ jmp 2f
21693+1:
21694+#endif
21695+
21696+ i = 0
21697+ .rept USER_PGD_PTRS
21698+ movb $0x67,i*8(%rbx)
21699+ i = i + 1
21700+ .endr
21701+2:
21702+
21703+#ifdef CONFIG_PARAVIRT
21704+ PV_RESTORE_REGS(CLBR_RDI)
21705+#endif
21706+
21707+ popq %rbx
21708+ popq %rdi
21709+ pax_force_retaddr
21710+ retq
21711+3: ud2
21712+ENDPROC(pax_exit_kernel_user)
21713+#endif
21714+
21715+ .macro pax_enter_kernel_nmi
21716+ pax_set_fptr_mask
21717+
21718+#ifdef CONFIG_PAX_KERNEXEC
21719+ GET_CR0_INTO_RDI
21720+ bts $16,%rdi
21721+ jc 110f
21722+ SET_RDI_INTO_CR0
21723+ or $2,%ebx
21724+110:
21725+#endif
21726+
21727+#ifdef CONFIG_PAX_MEMORY_UDEREF
21728+ 661: jmp 111f
21729+ .pushsection .altinstr_replacement, "a"
21730+ 662: ASM_NOP2
21731+ .popsection
21732+ .pushsection .altinstructions, "a"
21733+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
21734+ .popsection
21735+ GET_CR3_INTO_RDI
21736+ cmp $0,%dil
21737+ jz 111f
21738+ sub $4097,%rdi
21739+ or $4,%ebx
21740+ bts $63,%rdi
21741+ SET_RDI_INTO_CR3
21742+ mov $__UDEREF_KERNEL_DS,%edi
21743+ mov %edi,%ss
21744+111:
21745+#endif
21746+ .endm
21747+
21748+ .macro pax_exit_kernel_nmi
21749+#ifdef CONFIG_PAX_KERNEXEC
21750+ btr $1,%ebx
21751+ jnc 110f
21752+ GET_CR0_INTO_RDI
21753+ btr $16,%rdi
21754+ SET_RDI_INTO_CR0
21755+110:
21756+#endif
21757+
21758+#ifdef CONFIG_PAX_MEMORY_UDEREF
21759+ btr $2,%ebx
21760+ jnc 111f
21761+ GET_CR3_INTO_RDI
21762+ add $4097,%rdi
21763+ bts $63,%rdi
21764+ SET_RDI_INTO_CR3
21765+ mov $__KERNEL_DS,%edi
21766+ mov %edi,%ss
21767+111:
21768+#endif
21769+ .endm
21770+
21771+ .macro pax_erase_kstack
21772+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
21773+ call pax_erase_kstack
21774+#endif
21775+ .endm
21776+
21777+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
21778+ENTRY(pax_erase_kstack)
21779+ pushq %rdi
21780+ pushq %rcx
21781+ pushq %rax
21782+ pushq %r11
21783+
21784+ GET_THREAD_INFO(%r11)
21785+ mov TI_lowest_stack(%r11), %rdi
21786+ mov $-0xBEEF, %rax
21787+ std
21788+
21789+1: mov %edi, %ecx
21790+ and $THREAD_SIZE_asm - 1, %ecx
21791+ shr $3, %ecx
21792+ repne scasq
21793+ jecxz 2f
21794+
21795+ cmp $2*8, %ecx
21796+ jc 2f
21797+
21798+ mov $2*8, %ecx
21799+ repe scasq
21800+ jecxz 2f
21801+ jne 1b
21802+
21803+2: cld
21804+ mov %esp, %ecx
21805+ sub %edi, %ecx
21806+
21807+ cmp $THREAD_SIZE_asm, %rcx
21808+ jb 3f
21809+ ud2
21810+3:
21811+
21812+ shr $3, %ecx
21813+ rep stosq
21814+
21815+ mov TI_task_thread_sp0(%r11), %rdi
21816+ sub $256, %rdi
21817+ mov %rdi, TI_lowest_stack(%r11)
21818+
21819+ popq %r11
21820+ popq %rax
21821+ popq %rcx
21822+ popq %rdi
21823+ pax_force_retaddr
21824+ ret
21825+ENDPROC(pax_erase_kstack)
21826+#endif
21827
21828 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
21829 #ifdef CONFIG_TRACE_IRQFLAGS
21830@@ -375,8 +808,8 @@ ENDPROC(native_usergs_sysret64)
21831 .endm
21832
21833 .macro UNFAKE_STACK_FRAME
21834- addq $8*6, %rsp
21835- CFI_ADJUST_CFA_OFFSET -(6*8)
21836+ addq $8*6 + ARG_SKIP, %rsp
21837+ CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
21838 .endm
21839
21840 /*
21841@@ -463,7 +896,7 @@ ENDPROC(native_usergs_sysret64)
21842 movq %rsp, %rsi
21843
21844 leaq -RBP(%rsp),%rdi /* arg1 for handler */
21845- testl $3, CS-RBP(%rsi)
21846+ testb $3, CS-RBP(%rsi)
21847 je 1f
21848 SWAPGS
21849 /*
21850@@ -514,9 +947,10 @@ ENTRY(save_paranoid)
21851 js 1f /* negative -> in kernel */
21852 SWAPGS
21853 xorl %ebx,%ebx
21854-1: ret
21855+1: pax_force_retaddr_bts
21856+ ret
21857 CFI_ENDPROC
21858-END(save_paranoid)
21859+ENDPROC(save_paranoid)
21860 .popsection
21861
21862 /*
21863@@ -538,7 +972,7 @@ ENTRY(ret_from_fork)
21864
21865 RESTORE_REST
21866
21867- testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
21868+ testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
21869 jz 1f
21870
21871 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
21872@@ -556,7 +990,7 @@ ENTRY(ret_from_fork)
21873 RESTORE_REST
21874 jmp int_ret_from_sys_call
21875 CFI_ENDPROC
21876-END(ret_from_fork)
21877+ENDPROC(ret_from_fork)
21878
21879 /*
21880 * System call entry. Up to 6 arguments in registers are supported.
21881@@ -593,7 +1027,7 @@ END(ret_from_fork)
21882 ENTRY(system_call)
21883 CFI_STARTPROC simple
21884 CFI_SIGNAL_FRAME
21885- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
21886+ CFI_DEF_CFA rsp,0
21887 CFI_REGISTER rip,rcx
21888 /*CFI_REGISTER rflags,r11*/
21889 SWAPGS_UNSAFE_STACK
21890@@ -606,16 +1040,23 @@ GLOBAL(system_call_after_swapgs)
21891
21892 movq %rsp,PER_CPU_VAR(old_rsp)
21893 movq PER_CPU_VAR(kernel_stack),%rsp
21894+ SAVE_ARGS 8*6,0
21895+ pax_enter_kernel_user
21896+
21897+#ifdef CONFIG_PAX_RANDKSTACK
21898+ pax_erase_kstack
21899+#endif
21900+
21901 /*
21902 * No need to follow this irqs off/on section - it's straight
21903 * and short:
21904 */
21905 ENABLE_INTERRUPTS(CLBR_NONE)
21906- SAVE_ARGS 8,0
21907 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
21908 movq %rcx,RIP-ARGOFFSET(%rsp)
21909 CFI_REL_OFFSET rip,RIP-ARGOFFSET
21910- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
21911+ GET_THREAD_INFO(%rcx)
21912+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
21913 jnz tracesys
21914 system_call_fastpath:
21915 #if __SYSCALL_MASK == ~0
21916@@ -625,7 +1066,7 @@ system_call_fastpath:
21917 cmpl $__NR_syscall_max,%eax
21918 #endif
21919 ja badsys
21920- movq %r10,%rcx
21921+ movq R10-ARGOFFSET(%rsp),%rcx
21922 call *sys_call_table(,%rax,8) # XXX: rip relative
21923 movq %rax,RAX-ARGOFFSET(%rsp)
21924 /*
21925@@ -639,10 +1080,13 @@ sysret_check:
21926 LOCKDEP_SYS_EXIT
21927 DISABLE_INTERRUPTS(CLBR_NONE)
21928 TRACE_IRQS_OFF
21929- movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
21930+ GET_THREAD_INFO(%rcx)
21931+ movl TI_flags(%rcx),%edx
21932 andl %edi,%edx
21933 jnz sysret_careful
21934 CFI_REMEMBER_STATE
21935+ pax_exit_kernel_user
21936+ pax_erase_kstack
21937 /*
21938 * sysretq will re-enable interrupts:
21939 */
21940@@ -694,14 +1138,18 @@ badsys:
21941 * jump back to the normal fast path.
21942 */
21943 auditsys:
21944- movq %r10,%r9 /* 6th arg: 4th syscall arg */
21945+ movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
21946 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
21947 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
21948 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
21949 movq %rax,%rsi /* 2nd arg: syscall number */
21950 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
21951 call __audit_syscall_entry
21952+
21953+ pax_erase_kstack
21954+
21955 LOAD_ARGS 0 /* reload call-clobbered registers */
21956+ pax_set_fptr_mask
21957 jmp system_call_fastpath
21958
21959 /*
21960@@ -722,7 +1170,7 @@ sysret_audit:
21961 /* Do syscall tracing */
21962 tracesys:
21963 #ifdef CONFIG_AUDITSYSCALL
21964- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
21965+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
21966 jz auditsys
21967 #endif
21968 SAVE_REST
21969@@ -730,12 +1178,16 @@ tracesys:
21970 FIXUP_TOP_OF_STACK %rdi
21971 movq %rsp,%rdi
21972 call syscall_trace_enter
21973+
21974+ pax_erase_kstack
21975+
21976 /*
21977 * Reload arg registers from stack in case ptrace changed them.
21978 * We don't reload %rax because syscall_trace_enter() returned
21979 * the value it wants us to use in the table lookup.
21980 */
21981 LOAD_ARGS ARGOFFSET, 1
21982+ pax_set_fptr_mask
21983 RESTORE_REST
21984 #if __SYSCALL_MASK == ~0
21985 cmpq $__NR_syscall_max,%rax
21986@@ -744,7 +1196,7 @@ tracesys:
21987 cmpl $__NR_syscall_max,%eax
21988 #endif
21989 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
21990- movq %r10,%rcx /* fixup for C */
21991+ movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
21992 call *sys_call_table(,%rax,8)
21993 movq %rax,RAX-ARGOFFSET(%rsp)
21994 /* Use IRET because user could have changed frame */
21995@@ -765,7 +1217,9 @@ GLOBAL(int_with_check)
21996 andl %edi,%edx
21997 jnz int_careful
21998 andl $~TS_COMPAT,TI_status(%rcx)
21999- jmp retint_swapgs
22000+ pax_exit_kernel_user
22001+ pax_erase_kstack
22002+ jmp retint_swapgs_pax
22003
22004 /* Either reschedule or signal or syscall exit tracking needed. */
22005 /* First do a reschedule test. */
22006@@ -811,7 +1265,7 @@ int_restore_rest:
22007 TRACE_IRQS_OFF
22008 jmp int_with_check
22009 CFI_ENDPROC
22010-END(system_call)
22011+ENDPROC(system_call)
22012
22013 .macro FORK_LIKE func
22014 ENTRY(stub_\func)
22015@@ -824,9 +1278,10 @@ ENTRY(stub_\func)
22016 DEFAULT_FRAME 0 8 /* offset 8: return address */
22017 call sys_\func
22018 RESTORE_TOP_OF_STACK %r11, 8
22019+ pax_force_retaddr
22020 ret $REST_SKIP /* pop extended registers */
22021 CFI_ENDPROC
22022-END(stub_\func)
22023+ENDPROC(stub_\func)
22024 .endm
22025
22026 .macro FIXED_FRAME label,func
22027@@ -836,9 +1291,10 @@ ENTRY(\label)
22028 FIXUP_TOP_OF_STACK %r11, 8-ARGOFFSET
22029 call \func
22030 RESTORE_TOP_OF_STACK %r11, 8-ARGOFFSET
22031+ pax_force_retaddr
22032 ret
22033 CFI_ENDPROC
22034-END(\label)
22035+ENDPROC(\label)
22036 .endm
22037
22038 FORK_LIKE clone
22039@@ -855,9 +1311,10 @@ ENTRY(ptregscall_common)
22040 movq_cfi_restore R12+8, r12
22041 movq_cfi_restore RBP+8, rbp
22042 movq_cfi_restore RBX+8, rbx
22043+ pax_force_retaddr
22044 ret $REST_SKIP /* pop extended registers */
22045 CFI_ENDPROC
22046-END(ptregscall_common)
22047+ENDPROC(ptregscall_common)
22048
22049 ENTRY(stub_execve)
22050 CFI_STARTPROC
22051@@ -870,7 +1327,7 @@ ENTRY(stub_execve)
22052 RESTORE_REST
22053 jmp int_ret_from_sys_call
22054 CFI_ENDPROC
22055-END(stub_execve)
22056+ENDPROC(stub_execve)
22057
22058 /*
22059 * sigreturn is special because it needs to restore all registers on return.
22060@@ -887,7 +1344,7 @@ ENTRY(stub_rt_sigreturn)
22061 RESTORE_REST
22062 jmp int_ret_from_sys_call
22063 CFI_ENDPROC
22064-END(stub_rt_sigreturn)
22065+ENDPROC(stub_rt_sigreturn)
22066
22067 #ifdef CONFIG_X86_X32_ABI
22068 ENTRY(stub_x32_rt_sigreturn)
22069@@ -901,7 +1358,7 @@ ENTRY(stub_x32_rt_sigreturn)
22070 RESTORE_REST
22071 jmp int_ret_from_sys_call
22072 CFI_ENDPROC
22073-END(stub_x32_rt_sigreturn)
22074+ENDPROC(stub_x32_rt_sigreturn)
22075
22076 ENTRY(stub_x32_execve)
22077 CFI_STARTPROC
22078@@ -915,7 +1372,7 @@ ENTRY(stub_x32_execve)
22079 RESTORE_REST
22080 jmp int_ret_from_sys_call
22081 CFI_ENDPROC
22082-END(stub_x32_execve)
22083+ENDPROC(stub_x32_execve)
22084
22085 #endif
22086
22087@@ -952,7 +1409,7 @@ vector=vector+1
22088 2: jmp common_interrupt
22089 .endr
22090 CFI_ENDPROC
22091-END(irq_entries_start)
22092+ENDPROC(irq_entries_start)
22093
22094 .previous
22095 END(interrupt)
22096@@ -972,6 +1429,16 @@ END(interrupt)
22097 subq $ORIG_RAX-RBP, %rsp
22098 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
22099 SAVE_ARGS_IRQ
22100+#ifdef CONFIG_PAX_MEMORY_UDEREF
22101+ testb $3, CS(%rdi)
22102+ jnz 1f
22103+ pax_enter_kernel
22104+ jmp 2f
22105+1: pax_enter_kernel_user
22106+2:
22107+#else
22108+ pax_enter_kernel
22109+#endif
22110 call \func
22111 .endm
22112
22113@@ -1004,7 +1471,7 @@ ret_from_intr:
22114
22115 exit_intr:
22116 GET_THREAD_INFO(%rcx)
22117- testl $3,CS-ARGOFFSET(%rsp)
22118+ testb $3,CS-ARGOFFSET(%rsp)
22119 je retint_kernel
22120
22121 /* Interrupt came from user space */
22122@@ -1026,12 +1493,16 @@ retint_swapgs: /* return to user-space */
22123 * The iretq could re-enable interrupts:
22124 */
22125 DISABLE_INTERRUPTS(CLBR_ANY)
22126+ pax_exit_kernel_user
22127+retint_swapgs_pax:
22128 TRACE_IRQS_IRETQ
22129 SWAPGS
22130 jmp restore_args
22131
22132 retint_restore_args: /* return to kernel space */
22133 DISABLE_INTERRUPTS(CLBR_ANY)
22134+ pax_exit_kernel
22135+ pax_force_retaddr (RIP-ARGOFFSET)
22136 /*
22137 * The iretq could re-enable interrupts:
22138 */
22139@@ -1114,7 +1585,7 @@ ENTRY(retint_kernel)
22140 #endif
22141
22142 CFI_ENDPROC
22143-END(common_interrupt)
22144+ENDPROC(common_interrupt)
22145 /*
22146 * End of kprobes section
22147 */
22148@@ -1132,7 +1603,7 @@ ENTRY(\sym)
22149 interrupt \do_sym
22150 jmp ret_from_intr
22151 CFI_ENDPROC
22152-END(\sym)
22153+ENDPROC(\sym)
22154 .endm
22155
22156 #ifdef CONFIG_TRACING
22157@@ -1215,12 +1686,22 @@ ENTRY(\sym)
22158 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
22159 call error_entry
22160 DEFAULT_FRAME 0
22161+#ifdef CONFIG_PAX_MEMORY_UDEREF
22162+ testb $3, CS(%rsp)
22163+ jnz 1f
22164+ pax_enter_kernel
22165+ jmp 2f
22166+1: pax_enter_kernel_user
22167+2:
22168+#else
22169+ pax_enter_kernel
22170+#endif
22171 movq %rsp,%rdi /* pt_regs pointer */
22172 xorl %esi,%esi /* no error code */
22173 call \do_sym
22174 jmp error_exit /* %ebx: no swapgs flag */
22175 CFI_ENDPROC
22176-END(\sym)
22177+ENDPROC(\sym)
22178 .endm
22179
22180 .macro paranoidzeroentry sym do_sym
22181@@ -1233,15 +1714,25 @@ ENTRY(\sym)
22182 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
22183 call save_paranoid
22184 TRACE_IRQS_OFF
22185+#ifdef CONFIG_PAX_MEMORY_UDEREF
22186+ testb $3, CS(%rsp)
22187+ jnz 1f
22188+ pax_enter_kernel
22189+ jmp 2f
22190+1: pax_enter_kernel_user
22191+2:
22192+#else
22193+ pax_enter_kernel
22194+#endif
22195 movq %rsp,%rdi /* pt_regs pointer */
22196 xorl %esi,%esi /* no error code */
22197 call \do_sym
22198 jmp paranoid_exit /* %ebx: no swapgs flag */
22199 CFI_ENDPROC
22200-END(\sym)
22201+ENDPROC(\sym)
22202 .endm
22203
22204-#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
22205+#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
22206 .macro paranoidzeroentry_ist sym do_sym ist
22207 ENTRY(\sym)
22208 INTR_FRAME
22209@@ -1252,14 +1743,30 @@ ENTRY(\sym)
22210 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
22211 call save_paranoid
22212 TRACE_IRQS_OFF_DEBUG
22213+#ifdef CONFIG_PAX_MEMORY_UDEREF
22214+ testb $3, CS(%rsp)
22215+ jnz 1f
22216+ pax_enter_kernel
22217+ jmp 2f
22218+1: pax_enter_kernel_user
22219+2:
22220+#else
22221+ pax_enter_kernel
22222+#endif
22223 movq %rsp,%rdi /* pt_regs pointer */
22224 xorl %esi,%esi /* no error code */
22225+#ifdef CONFIG_SMP
22226+ imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
22227+ lea init_tss(%r12), %r12
22228+#else
22229+ lea init_tss(%rip), %r12
22230+#endif
22231 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
22232 call \do_sym
22233 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
22234 jmp paranoid_exit /* %ebx: no swapgs flag */
22235 CFI_ENDPROC
22236-END(\sym)
22237+ENDPROC(\sym)
22238 .endm
22239
22240 .macro errorentry sym do_sym
22241@@ -1271,13 +1778,23 @@ ENTRY(\sym)
22242 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
22243 call error_entry
22244 DEFAULT_FRAME 0
22245+#ifdef CONFIG_PAX_MEMORY_UDEREF
22246+ testb $3, CS(%rsp)
22247+ jnz 1f
22248+ pax_enter_kernel
22249+ jmp 2f
22250+1: pax_enter_kernel_user
22251+2:
22252+#else
22253+ pax_enter_kernel
22254+#endif
22255 movq %rsp,%rdi /* pt_regs pointer */
22256 movq ORIG_RAX(%rsp),%rsi /* get error code */
22257 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
22258 call \do_sym
22259 jmp error_exit /* %ebx: no swapgs flag */
22260 CFI_ENDPROC
22261-END(\sym)
22262+ENDPROC(\sym)
22263 .endm
22264
22265 /* error code is on the stack already */
22266@@ -1291,13 +1808,23 @@ ENTRY(\sym)
22267 call save_paranoid
22268 DEFAULT_FRAME 0
22269 TRACE_IRQS_OFF
22270+#ifdef CONFIG_PAX_MEMORY_UDEREF
22271+ testb $3, CS(%rsp)
22272+ jnz 1f
22273+ pax_enter_kernel
22274+ jmp 2f
22275+1: pax_enter_kernel_user
22276+2:
22277+#else
22278+ pax_enter_kernel
22279+#endif
22280 movq %rsp,%rdi /* pt_regs pointer */
22281 movq ORIG_RAX(%rsp),%rsi /* get error code */
22282 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
22283 call \do_sym
22284 jmp paranoid_exit /* %ebx: no swapgs flag */
22285 CFI_ENDPROC
22286-END(\sym)
22287+ENDPROC(\sym)
22288 .endm
22289
22290 zeroentry divide_error do_divide_error
22291@@ -1327,9 +1854,10 @@ gs_change:
22292 2: mfence /* workaround */
22293 SWAPGS
22294 popfq_cfi
22295+ pax_force_retaddr
22296 ret
22297 CFI_ENDPROC
22298-END(native_load_gs_index)
22299+ENDPROC(native_load_gs_index)
22300
22301 _ASM_EXTABLE(gs_change,bad_gs)
22302 .section .fixup,"ax"
22303@@ -1357,9 +1885,10 @@ ENTRY(call_softirq)
22304 CFI_DEF_CFA_REGISTER rsp
22305 CFI_ADJUST_CFA_OFFSET -8
22306 decl PER_CPU_VAR(irq_count)
22307+ pax_force_retaddr
22308 ret
22309 CFI_ENDPROC
22310-END(call_softirq)
22311+ENDPROC(call_softirq)
22312
22313 #ifdef CONFIG_XEN
22314 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
22315@@ -1397,7 +1926,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
22316 decl PER_CPU_VAR(irq_count)
22317 jmp error_exit
22318 CFI_ENDPROC
22319-END(xen_do_hypervisor_callback)
22320+ENDPROC(xen_do_hypervisor_callback)
22321
22322 /*
22323 * Hypervisor uses this for application faults while it executes.
22324@@ -1456,7 +1985,7 @@ ENTRY(xen_failsafe_callback)
22325 SAVE_ALL
22326 jmp error_exit
22327 CFI_ENDPROC
22328-END(xen_failsafe_callback)
22329+ENDPROC(xen_failsafe_callback)
22330
22331 apicinterrupt3 HYPERVISOR_CALLBACK_VECTOR \
22332 xen_hvm_callback_vector xen_evtchn_do_upcall
22333@@ -1508,18 +2037,33 @@ ENTRY(paranoid_exit)
22334 DEFAULT_FRAME
22335 DISABLE_INTERRUPTS(CLBR_NONE)
22336 TRACE_IRQS_OFF_DEBUG
22337- testl %ebx,%ebx /* swapgs needed? */
22338+ testl $1,%ebx /* swapgs needed? */
22339 jnz paranoid_restore
22340- testl $3,CS(%rsp)
22341+ testb $3,CS(%rsp)
22342 jnz paranoid_userspace
22343+#ifdef CONFIG_PAX_MEMORY_UDEREF
22344+ pax_exit_kernel
22345+ TRACE_IRQS_IRETQ 0
22346+ SWAPGS_UNSAFE_STACK
22347+ RESTORE_ALL 8
22348+ pax_force_retaddr_bts
22349+ jmp irq_return
22350+#endif
22351 paranoid_swapgs:
22352+#ifdef CONFIG_PAX_MEMORY_UDEREF
22353+ pax_exit_kernel_user
22354+#else
22355+ pax_exit_kernel
22356+#endif
22357 TRACE_IRQS_IRETQ 0
22358 SWAPGS_UNSAFE_STACK
22359 RESTORE_ALL 8
22360 jmp irq_return
22361 paranoid_restore:
22362+ pax_exit_kernel
22363 TRACE_IRQS_IRETQ_DEBUG 0
22364 RESTORE_ALL 8
22365+ pax_force_retaddr_bts
22366 jmp irq_return
22367 paranoid_userspace:
22368 GET_THREAD_INFO(%rcx)
22369@@ -1548,7 +2092,7 @@ paranoid_schedule:
22370 TRACE_IRQS_OFF
22371 jmp paranoid_userspace
22372 CFI_ENDPROC
22373-END(paranoid_exit)
22374+ENDPROC(paranoid_exit)
22375
22376 /*
22377 * Exception entry point. This expects an error code/orig_rax on the stack.
22378@@ -1575,12 +2119,13 @@ ENTRY(error_entry)
22379 movq_cfi r14, R14+8
22380 movq_cfi r15, R15+8
22381 xorl %ebx,%ebx
22382- testl $3,CS+8(%rsp)
22383+ testb $3,CS+8(%rsp)
22384 je error_kernelspace
22385 error_swapgs:
22386 SWAPGS
22387 error_sti:
22388 TRACE_IRQS_OFF
22389+ pax_force_retaddr_bts
22390 ret
22391
22392 /*
22393@@ -1607,7 +2152,7 @@ bstep_iret:
22394 movq %rcx,RIP+8(%rsp)
22395 jmp error_swapgs
22396 CFI_ENDPROC
22397-END(error_entry)
22398+ENDPROC(error_entry)
22399
22400
22401 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
22402@@ -1618,7 +2163,7 @@ ENTRY(error_exit)
22403 DISABLE_INTERRUPTS(CLBR_NONE)
22404 TRACE_IRQS_OFF
22405 GET_THREAD_INFO(%rcx)
22406- testl %eax,%eax
22407+ testl $1,%eax
22408 jne retint_kernel
22409 LOCKDEP_SYS_EXIT_IRQ
22410 movl TI_flags(%rcx),%edx
22411@@ -1627,7 +2172,7 @@ ENTRY(error_exit)
22412 jnz retint_careful
22413 jmp retint_swapgs
22414 CFI_ENDPROC
22415-END(error_exit)
22416+ENDPROC(error_exit)
22417
22418 /*
22419 * Test if a given stack is an NMI stack or not.
22420@@ -1685,9 +2230,11 @@ ENTRY(nmi)
22421 * If %cs was not the kernel segment, then the NMI triggered in user
22422 * space, which means it is definitely not nested.
22423 */
22424+ cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
22425+ je 1f
22426 cmpl $__KERNEL_CS, 16(%rsp)
22427 jne first_nmi
22428-
22429+1:
22430 /*
22431 * Check the special variable on the stack to see if NMIs are
22432 * executing.
22433@@ -1721,8 +2268,7 @@ nested_nmi:
22434
22435 1:
22436 /* Set up the interrupted NMIs stack to jump to repeat_nmi */
22437- leaq -1*8(%rsp), %rdx
22438- movq %rdx, %rsp
22439+ subq $8, %rsp
22440 CFI_ADJUST_CFA_OFFSET 1*8
22441 leaq -10*8(%rsp), %rdx
22442 pushq_cfi $__KERNEL_DS
22443@@ -1740,6 +2286,7 @@ nested_nmi_out:
22444 CFI_RESTORE rdx
22445
22446 /* No need to check faults here */
22447+# pax_force_retaddr_bts
22448 INTERRUPT_RETURN
22449
22450 CFI_RESTORE_STATE
22451@@ -1856,6 +2403,8 @@ end_repeat_nmi:
22452 */
22453 movq %cr2, %r12
22454
22455+ pax_enter_kernel_nmi
22456+
22457 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
22458 movq %rsp,%rdi
22459 movq $-1,%rsi
22460@@ -1868,26 +2417,31 @@ end_repeat_nmi:
22461 movq %r12, %cr2
22462 1:
22463
22464- testl %ebx,%ebx /* swapgs needed? */
22465+ testl $1,%ebx /* swapgs needed? */
22466 jnz nmi_restore
22467 nmi_swapgs:
22468 SWAPGS_UNSAFE_STACK
22469 nmi_restore:
22470+ pax_exit_kernel_nmi
22471 /* Pop the extra iret frame at once */
22472 RESTORE_ALL 6*8
22473+ testb $3, 8(%rsp)
22474+ jnz 1f
22475+ pax_force_retaddr_bts
22476+1:
22477
22478 /* Clear the NMI executing stack variable */
22479 movq $0, 5*8(%rsp)
22480 jmp irq_return
22481 CFI_ENDPROC
22482-END(nmi)
22483+ENDPROC(nmi)
22484
22485 ENTRY(ignore_sysret)
22486 CFI_STARTPROC
22487 mov $-ENOSYS,%eax
22488 sysret
22489 CFI_ENDPROC
22490-END(ignore_sysret)
22491+ENDPROC(ignore_sysret)
22492
22493 /*
22494 * End of kprobes section
22495diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
22496index 42a392a..fbbd930 100644
22497--- a/arch/x86/kernel/ftrace.c
22498+++ b/arch/x86/kernel/ftrace.c
22499@@ -105,6 +105,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
22500 {
22501 unsigned char replaced[MCOUNT_INSN_SIZE];
22502
22503+ ip = ktla_ktva(ip);
22504+
22505 /*
22506 * Note: Due to modules and __init, code can
22507 * disappear and change, we need to protect against faulting
22508@@ -227,7 +229,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
22509 unsigned char old[MCOUNT_INSN_SIZE], *new;
22510 int ret;
22511
22512- memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
22513+ memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
22514 new = ftrace_call_replace(ip, (unsigned long)func);
22515
22516 /* See comment above by declaration of modifying_ftrace_code */
22517@@ -238,7 +240,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
22518 /* Also update the regs callback function */
22519 if (!ret) {
22520 ip = (unsigned long)(&ftrace_regs_call);
22521- memcpy(old, &ftrace_regs_call, MCOUNT_INSN_SIZE);
22522+ memcpy(old, ktla_ktva((void *)&ftrace_regs_call), MCOUNT_INSN_SIZE);
22523 new = ftrace_call_replace(ip, (unsigned long)func);
22524 ret = ftrace_modify_code(ip, old, new);
22525 }
22526@@ -279,7 +281,7 @@ static int ftrace_write(unsigned long ip, const char *val, int size)
22527 * kernel identity mapping to modify code.
22528 */
22529 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
22530- ip = (unsigned long)__va(__pa_symbol(ip));
22531+ ip = (unsigned long)__va(__pa_symbol(ktla_ktva(ip)));
22532
22533 return probe_kernel_write((void *)ip, val, size);
22534 }
22535@@ -289,7 +291,7 @@ static int add_break(unsigned long ip, const char *old)
22536 unsigned char replaced[MCOUNT_INSN_SIZE];
22537 unsigned char brk = BREAKPOINT_INSTRUCTION;
22538
22539- if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
22540+ if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
22541 return -EFAULT;
22542
22543 /* Make sure it is what we expect it to be */
22544@@ -637,7 +639,7 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
22545 return ret;
22546
22547 fail_update:
22548- probe_kernel_write((void *)ip, &old_code[0], 1);
22549+ probe_kernel_write((void *)ktla_ktva(ip), &old_code[0], 1);
22550 goto out;
22551 }
22552
22553@@ -670,6 +672,8 @@ static int ftrace_mod_jmp(unsigned long ip,
22554 {
22555 unsigned char code[MCOUNT_INSN_SIZE];
22556
22557+ ip = ktla_ktva(ip);
22558+
22559 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
22560 return -EFAULT;
22561
22562diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
22563index 1be8e43..d9b9ef6 100644
22564--- a/arch/x86/kernel/head64.c
22565+++ b/arch/x86/kernel/head64.c
22566@@ -67,12 +67,12 @@ again:
22567 pgd = *pgd_p;
22568
22569 /*
22570- * The use of __START_KERNEL_map rather than __PAGE_OFFSET here is
22571- * critical -- __PAGE_OFFSET would point us back into the dynamic
22572+ * The use of __early_va rather than __va here is critical:
22573+ * __va would point us back into the dynamic
22574 * range and we might end up looping forever...
22575 */
22576 if (pgd)
22577- pud_p = (pudval_t *)((pgd & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
22578+ pud_p = (pudval_t *)(__early_va(pgd & PTE_PFN_MASK));
22579 else {
22580 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
22581 reset_early_page_tables();
22582@@ -82,13 +82,13 @@ again:
22583 pud_p = (pudval_t *)early_dynamic_pgts[next_early_pgt++];
22584 for (i = 0; i < PTRS_PER_PUD; i++)
22585 pud_p[i] = 0;
22586- *pgd_p = (pgdval_t)pud_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
22587+ *pgd_p = (pgdval_t)__pa(pud_p) + _KERNPG_TABLE;
22588 }
22589 pud_p += pud_index(address);
22590 pud = *pud_p;
22591
22592 if (pud)
22593- pmd_p = (pmdval_t *)((pud & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
22594+ pmd_p = (pmdval_t *)(__early_va(pud & PTE_PFN_MASK));
22595 else {
22596 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
22597 reset_early_page_tables();
22598@@ -98,7 +98,7 @@ again:
22599 pmd_p = (pmdval_t *)early_dynamic_pgts[next_early_pgt++];
22600 for (i = 0; i < PTRS_PER_PMD; i++)
22601 pmd_p[i] = 0;
22602- *pud_p = (pudval_t)pmd_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
22603+ *pud_p = (pudval_t)__pa(pmd_p) + _KERNPG_TABLE;
22604 }
22605 pmd = (physaddr & PMD_MASK) + early_pmd_flags;
22606 pmd_p[pmd_index(address)] = pmd;
22607@@ -175,7 +175,6 @@ asmlinkage void __init x86_64_start_kernel(char * real_mode_data)
22608 if (console_loglevel == 10)
22609 early_printk("Kernel alive\n");
22610
22611- clear_page(init_level4_pgt);
22612 /* set init_level4_pgt kernel high mapping*/
22613 init_level4_pgt[511] = early_level4_pgt[511];
22614
22615diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
22616index 81ba276..30c5411 100644
22617--- a/arch/x86/kernel/head_32.S
22618+++ b/arch/x86/kernel/head_32.S
22619@@ -26,6 +26,12 @@
22620 /* Physical address */
22621 #define pa(X) ((X) - __PAGE_OFFSET)
22622
22623+#ifdef CONFIG_PAX_KERNEXEC
22624+#define ta(X) (X)
22625+#else
22626+#define ta(X) ((X) - __PAGE_OFFSET)
22627+#endif
22628+
22629 /*
22630 * References to members of the new_cpu_data structure.
22631 */
22632@@ -55,11 +61,7 @@
22633 * and small than max_low_pfn, otherwise will waste some page table entries
22634 */
22635
22636-#if PTRS_PER_PMD > 1
22637-#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
22638-#else
22639-#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
22640-#endif
22641+#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
22642
22643 /* Number of possible pages in the lowmem region */
22644 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
22645@@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
22646 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
22647
22648 /*
22649+ * Real beginning of normal "text" segment
22650+ */
22651+ENTRY(stext)
22652+ENTRY(_stext)
22653+
22654+/*
22655 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
22656 * %esi points to the real-mode code as a 32-bit pointer.
22657 * CS and DS must be 4 GB flat segments, but we don't depend on
22658@@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
22659 * can.
22660 */
22661 __HEAD
22662+
22663+#ifdef CONFIG_PAX_KERNEXEC
22664+ jmp startup_32
22665+/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
22666+.fill PAGE_SIZE-5,1,0xcc
22667+#endif
22668+
22669 ENTRY(startup_32)
22670 movl pa(stack_start),%ecx
22671
22672@@ -106,6 +121,59 @@ ENTRY(startup_32)
22673 2:
22674 leal -__PAGE_OFFSET(%ecx),%esp
22675
22676+#ifdef CONFIG_SMP
22677+ movl $pa(cpu_gdt_table),%edi
22678+ movl $__per_cpu_load,%eax
22679+ movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
22680+ rorl $16,%eax
22681+ movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
22682+ movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
22683+ movl $__per_cpu_end - 1,%eax
22684+ subl $__per_cpu_start,%eax
22685+ movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
22686+#endif
22687+
22688+#ifdef CONFIG_PAX_MEMORY_UDEREF
22689+ movl $NR_CPUS,%ecx
22690+ movl $pa(cpu_gdt_table),%edi
22691+1:
22692+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
22693+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
22694+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
22695+ addl $PAGE_SIZE_asm,%edi
22696+ loop 1b
22697+#endif
22698+
22699+#ifdef CONFIG_PAX_KERNEXEC
22700+ movl $pa(boot_gdt),%edi
22701+ movl $__LOAD_PHYSICAL_ADDR,%eax
22702+ movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
22703+ rorl $16,%eax
22704+ movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
22705+ movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
22706+ rorl $16,%eax
22707+
22708+ ljmp $(__BOOT_CS),$1f
22709+1:
22710+
22711+ movl $NR_CPUS,%ecx
22712+ movl $pa(cpu_gdt_table),%edi
22713+ addl $__PAGE_OFFSET,%eax
22714+1:
22715+ movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
22716+ movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
22717+ movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
22718+ movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
22719+ rorl $16,%eax
22720+ movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
22721+ movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
22722+ movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
22723+ movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
22724+ rorl $16,%eax
22725+ addl $PAGE_SIZE_asm,%edi
22726+ loop 1b
22727+#endif
22728+
22729 /*
22730 * Clear BSS first so that there are no surprises...
22731 */
22732@@ -201,8 +269,11 @@ ENTRY(startup_32)
22733 movl %eax, pa(max_pfn_mapped)
22734
22735 /* Do early initialization of the fixmap area */
22736- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
22737- movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
22738+#ifdef CONFIG_COMPAT_VDSO
22739+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
22740+#else
22741+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
22742+#endif
22743 #else /* Not PAE */
22744
22745 page_pde_offset = (__PAGE_OFFSET >> 20);
22746@@ -232,8 +303,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
22747 movl %eax, pa(max_pfn_mapped)
22748
22749 /* Do early initialization of the fixmap area */
22750- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
22751- movl %eax,pa(initial_page_table+0xffc)
22752+#ifdef CONFIG_COMPAT_VDSO
22753+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
22754+#else
22755+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
22756+#endif
22757 #endif
22758
22759 #ifdef CONFIG_PARAVIRT
22760@@ -247,9 +321,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
22761 cmpl $num_subarch_entries, %eax
22762 jae bad_subarch
22763
22764- movl pa(subarch_entries)(,%eax,4), %eax
22765- subl $__PAGE_OFFSET, %eax
22766- jmp *%eax
22767+ jmp *pa(subarch_entries)(,%eax,4)
22768
22769 bad_subarch:
22770 WEAK(lguest_entry)
22771@@ -261,10 +333,10 @@ WEAK(xen_entry)
22772 __INITDATA
22773
22774 subarch_entries:
22775- .long default_entry /* normal x86/PC */
22776- .long lguest_entry /* lguest hypervisor */
22777- .long xen_entry /* Xen hypervisor */
22778- .long default_entry /* Moorestown MID */
22779+ .long ta(default_entry) /* normal x86/PC */
22780+ .long ta(lguest_entry) /* lguest hypervisor */
22781+ .long ta(xen_entry) /* Xen hypervisor */
22782+ .long ta(default_entry) /* Moorestown MID */
22783 num_subarch_entries = (. - subarch_entries) / 4
22784 .previous
22785 #else
22786@@ -354,6 +426,7 @@ default_entry:
22787 movl pa(mmu_cr4_features),%eax
22788 movl %eax,%cr4
22789
22790+#ifdef CONFIG_X86_PAE
22791 testb $X86_CR4_PAE, %al # check if PAE is enabled
22792 jz enable_paging
22793
22794@@ -382,6 +455,9 @@ default_entry:
22795 /* Make changes effective */
22796 wrmsr
22797
22798+ btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
22799+#endif
22800+
22801 enable_paging:
22802
22803 /*
22804@@ -449,14 +525,20 @@ is486:
22805 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
22806 movl %eax,%ss # after changing gdt.
22807
22808- movl $(__USER_DS),%eax # DS/ES contains default USER segment
22809+# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
22810 movl %eax,%ds
22811 movl %eax,%es
22812
22813 movl $(__KERNEL_PERCPU), %eax
22814 movl %eax,%fs # set this cpu's percpu
22815
22816+#ifdef CONFIG_CC_STACKPROTECTOR
22817 movl $(__KERNEL_STACK_CANARY),%eax
22818+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
22819+ movl $(__USER_DS),%eax
22820+#else
22821+ xorl %eax,%eax
22822+#endif
22823 movl %eax,%gs
22824
22825 xorl %eax,%eax # Clear LDT
22826@@ -512,8 +594,11 @@ setup_once:
22827 * relocation. Manually set base address in stack canary
22828 * segment descriptor.
22829 */
22830- movl $gdt_page,%eax
22831+ movl $cpu_gdt_table,%eax
22832 movl $stack_canary,%ecx
22833+#ifdef CONFIG_SMP
22834+ addl $__per_cpu_load,%ecx
22835+#endif
22836 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
22837 shrl $16, %ecx
22838 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
22839@@ -544,7 +629,7 @@ ENDPROC(early_idt_handlers)
22840 /* This is global to keep gas from relaxing the jumps */
22841 ENTRY(early_idt_handler)
22842 cld
22843- cmpl $2,%ss:early_recursion_flag
22844+ cmpl $1,%ss:early_recursion_flag
22845 je hlt_loop
22846 incl %ss:early_recursion_flag
22847
22848@@ -582,8 +667,8 @@ ENTRY(early_idt_handler)
22849 pushl (20+6*4)(%esp) /* trapno */
22850 pushl $fault_msg
22851 call printk
22852-#endif
22853 call dump_stack
22854+#endif
22855 hlt_loop:
22856 hlt
22857 jmp hlt_loop
22858@@ -602,8 +687,11 @@ ENDPROC(early_idt_handler)
22859 /* This is the default interrupt "handler" :-) */
22860 ALIGN
22861 ignore_int:
22862- cld
22863 #ifdef CONFIG_PRINTK
22864+ cmpl $2,%ss:early_recursion_flag
22865+ je hlt_loop
22866+ incl %ss:early_recursion_flag
22867+ cld
22868 pushl %eax
22869 pushl %ecx
22870 pushl %edx
22871@@ -612,9 +700,6 @@ ignore_int:
22872 movl $(__KERNEL_DS),%eax
22873 movl %eax,%ds
22874 movl %eax,%es
22875- cmpl $2,early_recursion_flag
22876- je hlt_loop
22877- incl early_recursion_flag
22878 pushl 16(%esp)
22879 pushl 24(%esp)
22880 pushl 32(%esp)
22881@@ -648,29 +733,34 @@ ENTRY(setup_once_ref)
22882 /*
22883 * BSS section
22884 */
22885-__PAGE_ALIGNED_BSS
22886- .align PAGE_SIZE
22887 #ifdef CONFIG_X86_PAE
22888+.section .initial_pg_pmd,"a",@progbits
22889 initial_pg_pmd:
22890 .fill 1024*KPMDS,4,0
22891 #else
22892+.section .initial_page_table,"a",@progbits
22893 ENTRY(initial_page_table)
22894 .fill 1024,4,0
22895 #endif
22896+.section .initial_pg_fixmap,"a",@progbits
22897 initial_pg_fixmap:
22898 .fill 1024,4,0
22899+.section .empty_zero_page,"a",@progbits
22900 ENTRY(empty_zero_page)
22901 .fill 4096,1,0
22902+.section .swapper_pg_dir,"a",@progbits
22903 ENTRY(swapper_pg_dir)
22904+#ifdef CONFIG_X86_PAE
22905+ .fill 4,8,0
22906+#else
22907 .fill 1024,4,0
22908+#endif
22909
22910 /*
22911 * This starts the data section.
22912 */
22913 #ifdef CONFIG_X86_PAE
22914-__PAGE_ALIGNED_DATA
22915- /* Page-aligned for the benefit of paravirt? */
22916- .align PAGE_SIZE
22917+.section .initial_page_table,"a",@progbits
22918 ENTRY(initial_page_table)
22919 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
22920 # if KPMDS == 3
22921@@ -689,12 +779,20 @@ ENTRY(initial_page_table)
22922 # error "Kernel PMDs should be 1, 2 or 3"
22923 # endif
22924 .align PAGE_SIZE /* needs to be page-sized too */
22925+
22926+#ifdef CONFIG_PAX_PER_CPU_PGD
22927+ENTRY(cpu_pgd)
22928+ .rept 2*NR_CPUS
22929+ .fill 4,8,0
22930+ .endr
22931+#endif
22932+
22933 #endif
22934
22935 .data
22936 .balign 4
22937 ENTRY(stack_start)
22938- .long init_thread_union+THREAD_SIZE
22939+ .long init_thread_union+THREAD_SIZE-8
22940
22941 __INITRODATA
22942 int_msg:
22943@@ -722,7 +820,7 @@ fault_msg:
22944 * segment size, and 32-bit linear address value:
22945 */
22946
22947- .data
22948+.section .rodata,"a",@progbits
22949 .globl boot_gdt_descr
22950 .globl idt_descr
22951
22952@@ -731,7 +829,7 @@ fault_msg:
22953 .word 0 # 32 bit align gdt_desc.address
22954 boot_gdt_descr:
22955 .word __BOOT_DS+7
22956- .long boot_gdt - __PAGE_OFFSET
22957+ .long pa(boot_gdt)
22958
22959 .word 0 # 32-bit align idt_desc.address
22960 idt_descr:
22961@@ -742,7 +840,7 @@ idt_descr:
22962 .word 0 # 32 bit align gdt_desc.address
22963 ENTRY(early_gdt_descr)
22964 .word GDT_ENTRIES*8-1
22965- .long gdt_page /* Overwritten for secondary CPUs */
22966+ .long cpu_gdt_table /* Overwritten for secondary CPUs */
22967
22968 /*
22969 * The boot_gdt must mirror the equivalent in setup.S and is
22970@@ -751,5 +849,65 @@ ENTRY(early_gdt_descr)
22971 .align L1_CACHE_BYTES
22972 ENTRY(boot_gdt)
22973 .fill GDT_ENTRY_BOOT_CS,8,0
22974- .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
22975- .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
22976+ .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
22977+ .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
22978+
22979+ .align PAGE_SIZE_asm
22980+ENTRY(cpu_gdt_table)
22981+ .rept NR_CPUS
22982+ .quad 0x0000000000000000 /* NULL descriptor */
22983+ .quad 0x0000000000000000 /* 0x0b reserved */
22984+ .quad 0x0000000000000000 /* 0x13 reserved */
22985+ .quad 0x0000000000000000 /* 0x1b reserved */
22986+
22987+#ifdef CONFIG_PAX_KERNEXEC
22988+ .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
22989+#else
22990+ .quad 0x0000000000000000 /* 0x20 unused */
22991+#endif
22992+
22993+ .quad 0x0000000000000000 /* 0x28 unused */
22994+ .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
22995+ .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
22996+ .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
22997+ .quad 0x0000000000000000 /* 0x4b reserved */
22998+ .quad 0x0000000000000000 /* 0x53 reserved */
22999+ .quad 0x0000000000000000 /* 0x5b reserved */
23000+
23001+ .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
23002+ .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
23003+ .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
23004+ .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
23005+
23006+ .quad 0x0000000000000000 /* 0x80 TSS descriptor */
23007+ .quad 0x0000000000000000 /* 0x88 LDT descriptor */
23008+
23009+ /*
23010+ * Segments used for calling PnP BIOS have byte granularity.
23011+ * The code segments and data segments have fixed 64k limits,
23012+ * the transfer segment sizes are set at run time.
23013+ */
23014+ .quad 0x00409b000000ffff /* 0x90 32-bit code */
23015+ .quad 0x00009b000000ffff /* 0x98 16-bit code */
23016+ .quad 0x000093000000ffff /* 0xa0 16-bit data */
23017+ .quad 0x0000930000000000 /* 0xa8 16-bit data */
23018+ .quad 0x0000930000000000 /* 0xb0 16-bit data */
23019+
23020+ /*
23021+ * The APM segments have byte granularity and their bases
23022+ * are set at run time. All have 64k limits.
23023+ */
23024+ .quad 0x00409b000000ffff /* 0xb8 APM CS code */
23025+ .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
23026+ .quad 0x004093000000ffff /* 0xc8 APM DS data */
23027+
23028+ .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
23029+ .quad 0x0040930000000000 /* 0xd8 - PERCPU */
23030+ .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
23031+ .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
23032+ .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
23033+ .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
23034+
23035+ /* Be sure this is zeroed to avoid false validations in Xen */
23036+ .fill PAGE_SIZE_asm - GDT_SIZE,1,0
23037+ .endr
23038diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
23039index e1aabdb..fee4fee 100644
23040--- a/arch/x86/kernel/head_64.S
23041+++ b/arch/x86/kernel/head_64.S
23042@@ -20,6 +20,8 @@
23043 #include <asm/processor-flags.h>
23044 #include <asm/percpu.h>
23045 #include <asm/nops.h>
23046+#include <asm/cpufeature.h>
23047+#include <asm/alternative-asm.h>
23048
23049 #ifdef CONFIG_PARAVIRT
23050 #include <asm/asm-offsets.h>
23051@@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
23052 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
23053 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
23054 L3_START_KERNEL = pud_index(__START_KERNEL_map)
23055+L4_VMALLOC_START = pgd_index(VMALLOC_START)
23056+L3_VMALLOC_START = pud_index(VMALLOC_START)
23057+L4_VMALLOC_END = pgd_index(VMALLOC_END)
23058+L3_VMALLOC_END = pud_index(VMALLOC_END)
23059+L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
23060+L3_VMEMMAP_START = pud_index(VMEMMAP_START)
23061
23062 .text
23063 __HEAD
23064@@ -89,11 +97,24 @@ startup_64:
23065 * Fixup the physical addresses in the page table
23066 */
23067 addq %rbp, early_level4_pgt + (L4_START_KERNEL*8)(%rip)
23068+ addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
23069+ addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
23070+ addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
23071+ addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
23072+ addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
23073
23074- addq %rbp, level3_kernel_pgt + (510*8)(%rip)
23075- addq %rbp, level3_kernel_pgt + (511*8)(%rip)
23076+ addq %rbp, level3_ident_pgt + (0*8)(%rip)
23077+#ifndef CONFIG_XEN
23078+ addq %rbp, level3_ident_pgt + (1*8)(%rip)
23079+#endif
23080+
23081+ addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
23082+
23083+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
23084+ addq %rbp, level3_kernel_pgt + ((L3_START_KERNEL+1)*8)(%rip)
23085
23086 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
23087+ addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
23088
23089 /*
23090 * Set up the identity mapping for the switchover. These
23091@@ -177,8 +198,8 @@ ENTRY(secondary_startup_64)
23092 movq $(init_level4_pgt - __START_KERNEL_map), %rax
23093 1:
23094
23095- /* Enable PAE mode and PGE */
23096- movl $(X86_CR4_PAE | X86_CR4_PGE), %ecx
23097+ /* Enable PAE mode and PSE/PGE */
23098+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %ecx
23099 movq %rcx, %cr4
23100
23101 /* Setup early boot stage 4 level pagetables. */
23102@@ -199,10 +220,19 @@ ENTRY(secondary_startup_64)
23103 movl $MSR_EFER, %ecx
23104 rdmsr
23105 btsl $_EFER_SCE, %eax /* Enable System Call */
23106- btl $20,%edi /* No Execute supported? */
23107+ btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
23108 jnc 1f
23109 btsl $_EFER_NX, %eax
23110 btsq $_PAGE_BIT_NX,early_pmd_flags(%rip)
23111+#ifndef CONFIG_EFI
23112+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_PAGE_OFFSET(%rip)
23113+#endif
23114+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_START(%rip)
23115+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_END(%rip)
23116+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMEMMAP_START(%rip)
23117+ btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*506(%rip)
23118+ btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*507(%rip)
23119+ btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
23120 1: wrmsr /* Make changes effective */
23121
23122 /* Setup cr0 */
23123@@ -282,6 +312,7 @@ ENTRY(secondary_startup_64)
23124 * REX.W + FF /5 JMP m16:64 Jump far, absolute indirect,
23125 * address given in m16:64.
23126 */
23127+ pax_set_fptr_mask
23128 movq initial_code(%rip),%rax
23129 pushq $0 # fake return address to stop unwinder
23130 pushq $__KERNEL_CS # set correct cs
23131@@ -388,7 +419,7 @@ ENTRY(early_idt_handler)
23132 call dump_stack
23133 #ifdef CONFIG_KALLSYMS
23134 leaq early_idt_ripmsg(%rip),%rdi
23135- movq 40(%rsp),%rsi # %rip again
23136+ movq 88(%rsp),%rsi # %rip again
23137 call __print_symbol
23138 #endif
23139 #endif /* EARLY_PRINTK */
23140@@ -416,6 +447,7 @@ ENDPROC(early_idt_handler)
23141 early_recursion_flag:
23142 .long 0
23143
23144+ .section .rodata,"a",@progbits
23145 #ifdef CONFIG_EARLY_PRINTK
23146 early_idt_msg:
23147 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
23148@@ -443,29 +475,52 @@ NEXT_PAGE(early_level4_pgt)
23149 NEXT_PAGE(early_dynamic_pgts)
23150 .fill 512*EARLY_DYNAMIC_PAGE_TABLES,8,0
23151
23152- .data
23153+ .section .rodata,"a",@progbits
23154
23155-#ifndef CONFIG_XEN
23156 NEXT_PAGE(init_level4_pgt)
23157- .fill 512,8,0
23158-#else
23159-NEXT_PAGE(init_level4_pgt)
23160- .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
23161 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
23162 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
23163+ .org init_level4_pgt + L4_VMALLOC_START*8, 0
23164+ .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
23165+ .org init_level4_pgt + L4_VMALLOC_END*8, 0
23166+ .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
23167+ .org init_level4_pgt + L4_VMEMMAP_START*8, 0
23168+ .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
23169 .org init_level4_pgt + L4_START_KERNEL*8, 0
23170 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
23171 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
23172
23173+#ifdef CONFIG_PAX_PER_CPU_PGD
23174+NEXT_PAGE(cpu_pgd)
23175+ .rept 2*NR_CPUS
23176+ .fill 512,8,0
23177+ .endr
23178+#endif
23179+
23180 NEXT_PAGE(level3_ident_pgt)
23181 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
23182+#ifdef CONFIG_XEN
23183 .fill 511, 8, 0
23184+#else
23185+ .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
23186+ .fill 510,8,0
23187+#endif
23188+
23189+NEXT_PAGE(level3_vmalloc_start_pgt)
23190+ .fill 512,8,0
23191+
23192+NEXT_PAGE(level3_vmalloc_end_pgt)
23193+ .fill 512,8,0
23194+
23195+NEXT_PAGE(level3_vmemmap_pgt)
23196+ .fill L3_VMEMMAP_START,8,0
23197+ .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
23198+
23199 NEXT_PAGE(level2_ident_pgt)
23200- /* Since I easily can, map the first 1G.
23201+ /* Since I easily can, map the first 2G.
23202 * Don't set NX because code runs from these pages.
23203 */
23204- PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
23205-#endif
23206+ PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
23207
23208 NEXT_PAGE(level3_kernel_pgt)
23209 .fill L3_START_KERNEL,8,0
23210@@ -473,6 +528,9 @@ NEXT_PAGE(level3_kernel_pgt)
23211 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
23212 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
23213
23214+NEXT_PAGE(level2_vmemmap_pgt)
23215+ .fill 512,8,0
23216+
23217 NEXT_PAGE(level2_kernel_pgt)
23218 /*
23219 * 512 MB kernel mapping. We spend a full page on this pagetable
23220@@ -490,28 +548,64 @@ NEXT_PAGE(level2_kernel_pgt)
23221 NEXT_PAGE(level2_fixmap_pgt)
23222 .fill 506,8,0
23223 .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
23224- /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
23225- .fill 5,8,0
23226+ .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
23227+ /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
23228+ .fill 4,8,0
23229
23230 NEXT_PAGE(level1_fixmap_pgt)
23231 .fill 512,8,0
23232
23233+NEXT_PAGE(level1_vsyscall_pgt)
23234+ .fill 512,8,0
23235+
23236 #undef PMDS
23237
23238- .data
23239+ .align PAGE_SIZE
23240+ENTRY(cpu_gdt_table)
23241+ .rept NR_CPUS
23242+ .quad 0x0000000000000000 /* NULL descriptor */
23243+ .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
23244+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
23245+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
23246+ .quad 0x00cffb000000ffff /* __USER32_CS */
23247+ .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
23248+ .quad 0x00affb000000ffff /* __USER_CS */
23249+
23250+#ifdef CONFIG_PAX_KERNEXEC
23251+ .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
23252+#else
23253+ .quad 0x0 /* unused */
23254+#endif
23255+
23256+ .quad 0,0 /* TSS */
23257+ .quad 0,0 /* LDT */
23258+ .quad 0,0,0 /* three TLS descriptors */
23259+ .quad 0x0000f40000000000 /* node/CPU stored in limit */
23260+ /* asm/segment.h:GDT_ENTRIES must match this */
23261+
23262+#ifdef CONFIG_PAX_MEMORY_UDEREF
23263+ .quad 0x00cf93000000ffff /* __UDEREF_KERNEL_DS */
23264+#else
23265+ .quad 0x0 /* unused */
23266+#endif
23267+
23268+ /* zero the remaining page */
23269+ .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
23270+ .endr
23271+
23272 .align 16
23273 .globl early_gdt_descr
23274 early_gdt_descr:
23275 .word GDT_ENTRIES*8-1
23276 early_gdt_descr_base:
23277- .quad INIT_PER_CPU_VAR(gdt_page)
23278+ .quad cpu_gdt_table
23279
23280 ENTRY(phys_base)
23281 /* This must match the first entry in level2_kernel_pgt */
23282 .quad 0x0000000000000000
23283
23284 #include "../../x86/xen/xen-head.S"
23285-
23286- __PAGE_ALIGNED_BSS
23287+
23288+ .section .rodata,"a",@progbits
23289 NEXT_PAGE(empty_zero_page)
23290 .skip PAGE_SIZE
23291diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
23292index 0fa6912..b37438b 100644
23293--- a/arch/x86/kernel/i386_ksyms_32.c
23294+++ b/arch/x86/kernel/i386_ksyms_32.c
23295@@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
23296 EXPORT_SYMBOL(cmpxchg8b_emu);
23297 #endif
23298
23299+EXPORT_SYMBOL_GPL(cpu_gdt_table);
23300+
23301 /* Networking helper routines. */
23302 EXPORT_SYMBOL(csum_partial_copy_generic);
23303+EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
23304+EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
23305
23306 EXPORT_SYMBOL(__get_user_1);
23307 EXPORT_SYMBOL(__get_user_2);
23308@@ -37,3 +41,11 @@ EXPORT_SYMBOL(strstr);
23309
23310 EXPORT_SYMBOL(csum_partial);
23311 EXPORT_SYMBOL(empty_zero_page);
23312+
23313+#ifdef CONFIG_PAX_KERNEXEC
23314+EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
23315+#endif
23316+
23317+#ifdef CONFIG_PAX_PER_CPU_PGD
23318+EXPORT_SYMBOL(cpu_pgd);
23319+#endif
23320diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
23321index 5d576ab..1403a03 100644
23322--- a/arch/x86/kernel/i387.c
23323+++ b/arch/x86/kernel/i387.c
23324@@ -51,7 +51,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
23325 static inline bool interrupted_user_mode(void)
23326 {
23327 struct pt_regs *regs = get_irq_regs();
23328- return regs && user_mode_vm(regs);
23329+ return regs && user_mode(regs);
23330 }
23331
23332 /*
23333diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
23334index 9a5c460..84868423 100644
23335--- a/arch/x86/kernel/i8259.c
23336+++ b/arch/x86/kernel/i8259.c
23337@@ -110,7 +110,7 @@ static int i8259A_irq_pending(unsigned int irq)
23338 static void make_8259A_irq(unsigned int irq)
23339 {
23340 disable_irq_nosync(irq);
23341- io_apic_irqs &= ~(1<<irq);
23342+ io_apic_irqs &= ~(1UL<<irq);
23343 irq_set_chip_and_handler_name(irq, &i8259A_chip, handle_level_irq,
23344 i8259A_chip.name);
23345 enable_irq(irq);
23346@@ -209,7 +209,7 @@ spurious_8259A_irq:
23347 "spurious 8259A interrupt: IRQ%d.\n", irq);
23348 spurious_irq_mask |= irqmask;
23349 }
23350- atomic_inc(&irq_err_count);
23351+ atomic_inc_unchecked(&irq_err_count);
23352 /*
23353 * Theoretically we do not have to handle this IRQ,
23354 * but in Linux this does not cause problems and is
23355@@ -333,14 +333,16 @@ static void init_8259A(int auto_eoi)
23356 /* (slave's support for AEOI in flat mode is to be investigated) */
23357 outb_pic(SLAVE_ICW4_DEFAULT, PIC_SLAVE_IMR);
23358
23359+ pax_open_kernel();
23360 if (auto_eoi)
23361 /*
23362 * In AEOI mode we just have to mask the interrupt
23363 * when acking.
23364 */
23365- i8259A_chip.irq_mask_ack = disable_8259A_irq;
23366+ *(void **)&i8259A_chip.irq_mask_ack = disable_8259A_irq;
23367 else
23368- i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
23369+ *(void **)&i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
23370+ pax_close_kernel();
23371
23372 udelay(100); /* wait for 8259A to initialize */
23373
23374diff --git a/arch/x86/kernel/io_delay.c b/arch/x86/kernel/io_delay.c
23375index a979b5b..1d6db75 100644
23376--- a/arch/x86/kernel/io_delay.c
23377+++ b/arch/x86/kernel/io_delay.c
23378@@ -58,7 +58,7 @@ static int __init dmi_io_delay_0xed_port(const struct dmi_system_id *id)
23379 * Quirk table for systems that misbehave (lock up, etc.) if port
23380 * 0x80 is used:
23381 */
23382-static struct dmi_system_id __initdata io_delay_0xed_port_dmi_table[] = {
23383+static const struct dmi_system_id __initconst io_delay_0xed_port_dmi_table[] = {
23384 {
23385 .callback = dmi_io_delay_0xed_port,
23386 .ident = "Compaq Presario V6000",
23387diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
23388index 4ddaf66..6292f4e 100644
23389--- a/arch/x86/kernel/ioport.c
23390+++ b/arch/x86/kernel/ioport.c
23391@@ -6,6 +6,7 @@
23392 #include <linux/sched.h>
23393 #include <linux/kernel.h>
23394 #include <linux/capability.h>
23395+#include <linux/security.h>
23396 #include <linux/errno.h>
23397 #include <linux/types.h>
23398 #include <linux/ioport.h>
23399@@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
23400
23401 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
23402 return -EINVAL;
23403+#ifdef CONFIG_GRKERNSEC_IO
23404+ if (turn_on && grsec_disable_privio) {
23405+ gr_handle_ioperm();
23406+ return -EPERM;
23407+ }
23408+#endif
23409 if (turn_on && !capable(CAP_SYS_RAWIO))
23410 return -EPERM;
23411
23412@@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
23413 * because the ->io_bitmap_max value must match the bitmap
23414 * contents:
23415 */
23416- tss = &per_cpu(init_tss, get_cpu());
23417+ tss = init_tss + get_cpu();
23418
23419 if (turn_on)
23420 bitmap_clear(t->io_bitmap_ptr, from, num);
23421@@ -103,6 +110,12 @@ SYSCALL_DEFINE1(iopl, unsigned int, level)
23422 return -EINVAL;
23423 /* Trying to gain more privileges? */
23424 if (level > old) {
23425+#ifdef CONFIG_GRKERNSEC_IO
23426+ if (grsec_disable_privio) {
23427+ gr_handle_iopl();
23428+ return -EPERM;
23429+ }
23430+#endif
23431 if (!capable(CAP_SYS_RAWIO))
23432 return -EPERM;
23433 }
23434diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
23435index 22d0687..e07b2a5 100644
23436--- a/arch/x86/kernel/irq.c
23437+++ b/arch/x86/kernel/irq.c
23438@@ -21,7 +21,7 @@
23439 #define CREATE_TRACE_POINTS
23440 #include <asm/trace/irq_vectors.h>
23441
23442-atomic_t irq_err_count;
23443+atomic_unchecked_t irq_err_count;
23444
23445 /* Function pointer for generic interrupt vector handling */
23446 void (*x86_platform_ipi_callback)(void) = NULL;
23447@@ -125,9 +125,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
23448 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
23449 seq_printf(p, " Machine check polls\n");
23450 #endif
23451- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
23452+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
23453 #if defined(CONFIG_X86_IO_APIC)
23454- seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
23455+ seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
23456 #endif
23457 return 0;
23458 }
23459@@ -167,7 +167,7 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
23460
23461 u64 arch_irq_stat(void)
23462 {
23463- u64 sum = atomic_read(&irq_err_count);
23464+ u64 sum = atomic_read_unchecked(&irq_err_count);
23465 return sum;
23466 }
23467
23468diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
23469index 4186755..784efa0 100644
23470--- a/arch/x86/kernel/irq_32.c
23471+++ b/arch/x86/kernel/irq_32.c
23472@@ -39,7 +39,7 @@ static int check_stack_overflow(void)
23473 __asm__ __volatile__("andl %%esp,%0" :
23474 "=r" (sp) : "0" (THREAD_SIZE - 1));
23475
23476- return sp < (sizeof(struct thread_info) + STACK_WARN);
23477+ return sp < STACK_WARN;
23478 }
23479
23480 static void print_stack_overflow(void)
23481@@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
23482 * per-CPU IRQ handling contexts (thread information and stack)
23483 */
23484 union irq_ctx {
23485- struct thread_info tinfo;
23486- u32 stack[THREAD_SIZE/sizeof(u32)];
23487+ unsigned long previous_esp;
23488+ u32 stack[THREAD_SIZE/sizeof(u32)];
23489 } __attribute__((aligned(THREAD_SIZE)));
23490
23491 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
23492@@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
23493 static inline int
23494 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
23495 {
23496- union irq_ctx *curctx, *irqctx;
23497+ union irq_ctx *irqctx;
23498 u32 *isp, arg1, arg2;
23499
23500- curctx = (union irq_ctx *) current_thread_info();
23501 irqctx = __this_cpu_read(hardirq_ctx);
23502
23503 /*
23504@@ -92,16 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
23505 * handler) we can't do that and just have to keep using the
23506 * current stack (which is the irq stack already after all)
23507 */
23508- if (unlikely(curctx == irqctx))
23509+ if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
23510 return 0;
23511
23512 /* build the stack frame on the IRQ stack */
23513- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
23514- irqctx->tinfo.task = curctx->tinfo.task;
23515- irqctx->tinfo.previous_esp = current_stack_pointer;
23516+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
23517+ irqctx->previous_esp = current_stack_pointer;
23518
23519- /* Copy the preempt_count so that the [soft]irq checks work. */
23520- irqctx->tinfo.preempt_count = curctx->tinfo.preempt_count;
23521+#ifdef CONFIG_PAX_MEMORY_UDEREF
23522+ __set_fs(MAKE_MM_SEG(0));
23523+#endif
23524
23525 if (unlikely(overflow))
23526 call_on_stack(print_stack_overflow, isp);
23527@@ -113,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
23528 : "0" (irq), "1" (desc), "2" (isp),
23529 "D" (desc->handle_irq)
23530 : "memory", "cc", "ecx");
23531+
23532+#ifdef CONFIG_PAX_MEMORY_UDEREF
23533+ __set_fs(current_thread_info()->addr_limit);
23534+#endif
23535+
23536 return 1;
23537 }
23538
23539@@ -121,29 +125,14 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
23540 */
23541 void irq_ctx_init(int cpu)
23542 {
23543- union irq_ctx *irqctx;
23544-
23545 if (per_cpu(hardirq_ctx, cpu))
23546 return;
23547
23548- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
23549- THREADINFO_GFP,
23550- THREAD_SIZE_ORDER));
23551- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
23552- irqctx->tinfo.cpu = cpu;
23553- irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
23554- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
23555+ per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
23556+ per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
23557
23558- per_cpu(hardirq_ctx, cpu) = irqctx;
23559-
23560- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
23561- THREADINFO_GFP,
23562- THREAD_SIZE_ORDER));
23563- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
23564- irqctx->tinfo.cpu = cpu;
23565- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
23566-
23567- per_cpu(softirq_ctx, cpu) = irqctx;
23568+ printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
23569+ cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
23570
23571 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
23572 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
23573@@ -152,7 +141,6 @@ void irq_ctx_init(int cpu)
23574 asmlinkage void do_softirq(void)
23575 {
23576 unsigned long flags;
23577- struct thread_info *curctx;
23578 union irq_ctx *irqctx;
23579 u32 *isp;
23580
23581@@ -162,15 +150,22 @@ asmlinkage void do_softirq(void)
23582 local_irq_save(flags);
23583
23584 if (local_softirq_pending()) {
23585- curctx = current_thread_info();
23586 irqctx = __this_cpu_read(softirq_ctx);
23587- irqctx->tinfo.task = curctx->task;
23588- irqctx->tinfo.previous_esp = current_stack_pointer;
23589+ irqctx->previous_esp = current_stack_pointer;
23590
23591 /* build the stack frame on the softirq stack */
23592- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
23593+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
23594+
23595+#ifdef CONFIG_PAX_MEMORY_UDEREF
23596+ __set_fs(MAKE_MM_SEG(0));
23597+#endif
23598
23599 call_on_stack(__do_softirq, isp);
23600+
23601+#ifdef CONFIG_PAX_MEMORY_UDEREF
23602+ __set_fs(current_thread_info()->addr_limit);
23603+#endif
23604+
23605 /*
23606 * Shouldn't happen, we returned above if in_interrupt():
23607 */
23608@@ -191,7 +186,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
23609 if (unlikely(!desc))
23610 return false;
23611
23612- if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
23613+ if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
23614 if (unlikely(overflow))
23615 print_stack_overflow();
23616 desc->handle_irq(irq, desc);
23617diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
23618index d04d3ec..ea4b374 100644
23619--- a/arch/x86/kernel/irq_64.c
23620+++ b/arch/x86/kernel/irq_64.c
23621@@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
23622 u64 estack_top, estack_bottom;
23623 u64 curbase = (u64)task_stack_page(current);
23624
23625- if (user_mode_vm(regs))
23626+ if (user_mode(regs))
23627 return;
23628
23629 if (regs->sp >= curbase + sizeof(struct thread_info) +
23630diff --git a/arch/x86/kernel/jump_label.c b/arch/x86/kernel/jump_label.c
23631index ee11b7d..4df4d0c 100644
23632--- a/arch/x86/kernel/jump_label.c
23633+++ b/arch/x86/kernel/jump_label.c
23634@@ -49,7 +49,7 @@ static void __jump_label_transform(struct jump_entry *entry,
23635 * We are enabling this jump label. If it is not a nop
23636 * then something must have gone wrong.
23637 */
23638- if (unlikely(memcmp((void *)entry->code, ideal_nop, 5) != 0))
23639+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), ideal_nop, 5) != 0))
23640 bug_at((void *)entry->code, __LINE__);
23641
23642 code.jump = 0xe9;
23643@@ -64,13 +64,13 @@ static void __jump_label_transform(struct jump_entry *entry,
23644 */
23645 if (init) {
23646 const unsigned char default_nop[] = { STATIC_KEY_INIT_NOP };
23647- if (unlikely(memcmp((void *)entry->code, default_nop, 5) != 0))
23648+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5) != 0))
23649 bug_at((void *)entry->code, __LINE__);
23650 } else {
23651 code.jump = 0xe9;
23652 code.offset = entry->target -
23653 (entry->code + JUMP_LABEL_NOP_SIZE);
23654- if (unlikely(memcmp((void *)entry->code, &code, 5) != 0))
23655+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), &code, 5) != 0))
23656 bug_at((void *)entry->code, __LINE__);
23657 }
23658 memcpy(&code, ideal_nops[NOP_ATOMIC5], JUMP_LABEL_NOP_SIZE);
23659diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
23660index 836f832..a8bda67 100644
23661--- a/arch/x86/kernel/kgdb.c
23662+++ b/arch/x86/kernel/kgdb.c
23663@@ -127,11 +127,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
23664 #ifdef CONFIG_X86_32
23665 switch (regno) {
23666 case GDB_SS:
23667- if (!user_mode_vm(regs))
23668+ if (!user_mode(regs))
23669 *(unsigned long *)mem = __KERNEL_DS;
23670 break;
23671 case GDB_SP:
23672- if (!user_mode_vm(regs))
23673+ if (!user_mode(regs))
23674 *(unsigned long *)mem = kernel_stack_pointer(regs);
23675 break;
23676 case GDB_GS:
23677@@ -229,7 +229,10 @@ static void kgdb_correct_hw_break(void)
23678 bp->attr.bp_addr = breakinfo[breakno].addr;
23679 bp->attr.bp_len = breakinfo[breakno].len;
23680 bp->attr.bp_type = breakinfo[breakno].type;
23681- info->address = breakinfo[breakno].addr;
23682+ if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
23683+ info->address = ktla_ktva(breakinfo[breakno].addr);
23684+ else
23685+ info->address = breakinfo[breakno].addr;
23686 info->len = breakinfo[breakno].len;
23687 info->type = breakinfo[breakno].type;
23688 val = arch_install_hw_breakpoint(bp);
23689@@ -476,12 +479,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
23690 case 'k':
23691 /* clear the trace bit */
23692 linux_regs->flags &= ~X86_EFLAGS_TF;
23693- atomic_set(&kgdb_cpu_doing_single_step, -1);
23694+ atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
23695
23696 /* set the trace bit if we're stepping */
23697 if (remcomInBuffer[0] == 's') {
23698 linux_regs->flags |= X86_EFLAGS_TF;
23699- atomic_set(&kgdb_cpu_doing_single_step,
23700+ atomic_set_unchecked(&kgdb_cpu_doing_single_step,
23701 raw_smp_processor_id());
23702 }
23703
23704@@ -546,7 +549,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
23705
23706 switch (cmd) {
23707 case DIE_DEBUG:
23708- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
23709+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
23710 if (user_mode(regs))
23711 return single_step_cont(regs, args);
23712 break;
23713@@ -751,11 +754,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
23714 #endif /* CONFIG_DEBUG_RODATA */
23715
23716 bpt->type = BP_BREAKPOINT;
23717- err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
23718+ err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
23719 BREAK_INSTR_SIZE);
23720 if (err)
23721 return err;
23722- err = probe_kernel_write((char *)bpt->bpt_addr,
23723+ err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
23724 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
23725 #ifdef CONFIG_DEBUG_RODATA
23726 if (!err)
23727@@ -768,7 +771,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
23728 return -EBUSY;
23729 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
23730 BREAK_INSTR_SIZE);
23731- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
23732+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
23733 if (err)
23734 return err;
23735 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
23736@@ -793,13 +796,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
23737 if (mutex_is_locked(&text_mutex))
23738 goto knl_write;
23739 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
23740- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
23741+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
23742 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
23743 goto knl_write;
23744 return err;
23745 knl_write:
23746 #endif /* CONFIG_DEBUG_RODATA */
23747- return probe_kernel_write((char *)bpt->bpt_addr,
23748+ return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
23749 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
23750 }
23751
23752diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
23753index 79a3f96..6ba030a 100644
23754--- a/arch/x86/kernel/kprobes/core.c
23755+++ b/arch/x86/kernel/kprobes/core.c
23756@@ -119,9 +119,12 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
23757 s32 raddr;
23758 } __packed *insn;
23759
23760- insn = (struct __arch_relative_insn *)from;
23761+ insn = (struct __arch_relative_insn *)ktla_ktva(from);
23762+
23763+ pax_open_kernel();
23764 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
23765 insn->op = op;
23766+ pax_close_kernel();
23767 }
23768
23769 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
23770@@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
23771 kprobe_opcode_t opcode;
23772 kprobe_opcode_t *orig_opcodes = opcodes;
23773
23774- if (search_exception_tables((unsigned long)opcodes))
23775+ if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
23776 return 0; /* Page fault may occur on this address. */
23777
23778 retry:
23779@@ -238,9 +241,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
23780 * for the first byte, we can recover the original instruction
23781 * from it and kp->opcode.
23782 */
23783- memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
23784+ memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
23785 buf[0] = kp->opcode;
23786- return (unsigned long)buf;
23787+ return ktva_ktla((unsigned long)buf);
23788 }
23789
23790 /*
23791@@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
23792 /* Another subsystem puts a breakpoint, failed to recover */
23793 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
23794 return 0;
23795+ pax_open_kernel();
23796 memcpy(dest, insn.kaddr, insn.length);
23797+ pax_close_kernel();
23798
23799 #ifdef CONFIG_X86_64
23800 if (insn_rip_relative(&insn)) {
23801@@ -359,7 +364,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
23802 return 0;
23803 }
23804 disp = (u8 *) dest + insn_offset_displacement(&insn);
23805+ pax_open_kernel();
23806 *(s32 *) disp = (s32) newdisp;
23807+ pax_close_kernel();
23808 }
23809 #endif
23810 return insn.length;
23811@@ -498,7 +505,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
23812 * nor set current_kprobe, because it doesn't use single
23813 * stepping.
23814 */
23815- regs->ip = (unsigned long)p->ainsn.insn;
23816+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
23817 preempt_enable_no_resched();
23818 return;
23819 }
23820@@ -515,9 +522,9 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
23821 regs->flags &= ~X86_EFLAGS_IF;
23822 /* single step inline if the instruction is an int3 */
23823 if (p->opcode == BREAKPOINT_INSTRUCTION)
23824- regs->ip = (unsigned long)p->addr;
23825+ regs->ip = ktla_ktva((unsigned long)p->addr);
23826 else
23827- regs->ip = (unsigned long)p->ainsn.insn;
23828+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
23829 }
23830
23831 /*
23832@@ -596,7 +603,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
23833 setup_singlestep(p, regs, kcb, 0);
23834 return 1;
23835 }
23836- } else if (*addr != BREAKPOINT_INSTRUCTION) {
23837+ } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
23838 /*
23839 * The breakpoint instruction was removed right
23840 * after we hit it. Another cpu has removed
23841@@ -642,6 +649,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
23842 " movq %rax, 152(%rsp)\n"
23843 RESTORE_REGS_STRING
23844 " popfq\n"
23845+#ifdef KERNEXEC_PLUGIN
23846+ " btsq $63,(%rsp)\n"
23847+#endif
23848 #else
23849 " pushf\n"
23850 SAVE_REGS_STRING
23851@@ -779,7 +789,7 @@ static void __kprobes
23852 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
23853 {
23854 unsigned long *tos = stack_addr(regs);
23855- unsigned long copy_ip = (unsigned long)p->ainsn.insn;
23856+ unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
23857 unsigned long orig_ip = (unsigned long)p->addr;
23858 kprobe_opcode_t *insn = p->ainsn.insn;
23859
23860@@ -961,7 +971,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
23861 struct die_args *args = data;
23862 int ret = NOTIFY_DONE;
23863
23864- if (args->regs && user_mode_vm(args->regs))
23865+ if (args->regs && user_mode(args->regs))
23866 return ret;
23867
23868 switch (val) {
23869diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c
23870index 898160b..758cde8 100644
23871--- a/arch/x86/kernel/kprobes/opt.c
23872+++ b/arch/x86/kernel/kprobes/opt.c
23873@@ -79,6 +79,7 @@ found:
23874 /* Insert a move instruction which sets a pointer to eax/rdi (1st arg). */
23875 static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val)
23876 {
23877+ pax_open_kernel();
23878 #ifdef CONFIG_X86_64
23879 *addr++ = 0x48;
23880 *addr++ = 0xbf;
23881@@ -86,6 +87,7 @@ static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long v
23882 *addr++ = 0xb8;
23883 #endif
23884 *(unsigned long *)addr = val;
23885+ pax_close_kernel();
23886 }
23887
23888 asm (
23889@@ -335,7 +337,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
23890 * Verify if the address gap is in 2GB range, because this uses
23891 * a relative jump.
23892 */
23893- rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
23894+ rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
23895 if (abs(rel) > 0x7fffffff)
23896 return -ERANGE;
23897
23898@@ -350,16 +352,18 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
23899 op->optinsn.size = ret;
23900
23901 /* Copy arch-dep-instance from template */
23902- memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
23903+ pax_open_kernel();
23904+ memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
23905+ pax_close_kernel();
23906
23907 /* Set probe information */
23908 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
23909
23910 /* Set probe function call */
23911- synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
23912+ synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
23913
23914 /* Set returning jmp instruction at the tail of out-of-line buffer */
23915- synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
23916+ synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
23917 (u8 *)op->kp.addr + op->optinsn.size);
23918
23919 flush_icache_range((unsigned long) buf,
23920@@ -384,7 +388,7 @@ void __kprobes arch_optimize_kprobes(struct list_head *oplist)
23921 WARN_ON(kprobe_disabled(&op->kp));
23922
23923 /* Backup instructions which will be replaced by jump address */
23924- memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
23925+ memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
23926 RELATIVE_ADDR_SIZE);
23927
23928 insn_buf[0] = RELATIVEJUMP_OPCODE;
23929@@ -433,7 +437,7 @@ setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
23930 /* This kprobe is really able to run optimized path. */
23931 op = container_of(p, struct optimized_kprobe, kp);
23932 /* Detour through copied instructions */
23933- regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
23934+ regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
23935 if (!reenter)
23936 reset_current_kprobe();
23937 preempt_enable_no_resched();
23938diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
23939index ebc9873..1b9724b 100644
23940--- a/arch/x86/kernel/ldt.c
23941+++ b/arch/x86/kernel/ldt.c
23942@@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
23943 if (reload) {
23944 #ifdef CONFIG_SMP
23945 preempt_disable();
23946- load_LDT(pc);
23947+ load_LDT_nolock(pc);
23948 if (!cpumask_equal(mm_cpumask(current->mm),
23949 cpumask_of(smp_processor_id())))
23950 smp_call_function(flush_ldt, current->mm, 1);
23951 preempt_enable();
23952 #else
23953- load_LDT(pc);
23954+ load_LDT_nolock(pc);
23955 #endif
23956 }
23957 if (oldsize) {
23958@@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
23959 return err;
23960
23961 for (i = 0; i < old->size; i++)
23962- write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
23963+ write_ldt_entry(new->ldt, i, old->ldt + i);
23964 return 0;
23965 }
23966
23967@@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
23968 retval = copy_ldt(&mm->context, &old_mm->context);
23969 mutex_unlock(&old_mm->context.lock);
23970 }
23971+
23972+ if (tsk == current) {
23973+ mm->context.vdso = 0;
23974+
23975+#ifdef CONFIG_X86_32
23976+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23977+ mm->context.user_cs_base = 0UL;
23978+ mm->context.user_cs_limit = ~0UL;
23979+
23980+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
23981+ cpus_clear(mm->context.cpu_user_cs_mask);
23982+#endif
23983+
23984+#endif
23985+#endif
23986+
23987+ }
23988+
23989 return retval;
23990 }
23991
23992@@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
23993 }
23994 }
23995
23996+#ifdef CONFIG_PAX_SEGMEXEC
23997+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
23998+ error = -EINVAL;
23999+ goto out_unlock;
24000+ }
24001+#endif
24002+
24003 fill_ldt(&ldt, &ldt_info);
24004 if (oldmode)
24005 ldt.avl = 0;
24006diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
24007index 5b19e4d..6476a76 100644
24008--- a/arch/x86/kernel/machine_kexec_32.c
24009+++ b/arch/x86/kernel/machine_kexec_32.c
24010@@ -26,7 +26,7 @@
24011 #include <asm/cacheflush.h>
24012 #include <asm/debugreg.h>
24013
24014-static void set_idt(void *newidt, __u16 limit)
24015+static void set_idt(struct desc_struct *newidt, __u16 limit)
24016 {
24017 struct desc_ptr curidt;
24018
24019@@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
24020 }
24021
24022
24023-static void set_gdt(void *newgdt, __u16 limit)
24024+static void set_gdt(struct desc_struct *newgdt, __u16 limit)
24025 {
24026 struct desc_ptr curgdt;
24027
24028@@ -216,7 +216,7 @@ void machine_kexec(struct kimage *image)
24029 }
24030
24031 control_page = page_address(image->control_code_page);
24032- memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
24033+ memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
24034
24035 relocate_kernel_ptr = control_page;
24036 page_list[PA_CONTROL_PAGE] = __pa(control_page);
24037diff --git a/arch/x86/kernel/microcode_core.c b/arch/x86/kernel/microcode_core.c
24038index 15c9876..0a43909 100644
24039--- a/arch/x86/kernel/microcode_core.c
24040+++ b/arch/x86/kernel/microcode_core.c
24041@@ -513,7 +513,7 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
24042 return NOTIFY_OK;
24043 }
24044
24045-static struct notifier_block __refdata mc_cpu_notifier = {
24046+static struct notifier_block mc_cpu_notifier = {
24047 .notifier_call = mc_cpu_callback,
24048 };
24049
24050diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
24051index 5fb2ceb..3ae90bb 100644
24052--- a/arch/x86/kernel/microcode_intel.c
24053+++ b/arch/x86/kernel/microcode_intel.c
24054@@ -293,13 +293,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
24055
24056 static int get_ucode_user(void *to, const void *from, size_t n)
24057 {
24058- return copy_from_user(to, from, n);
24059+ return copy_from_user(to, (const void __force_user *)from, n);
24060 }
24061
24062 static enum ucode_state
24063 request_microcode_user(int cpu, const void __user *buf, size_t size)
24064 {
24065- return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
24066+ return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
24067 }
24068
24069 static void microcode_fini_cpu(int cpu)
24070diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
24071index 216a4d7..228255a 100644
24072--- a/arch/x86/kernel/module.c
24073+++ b/arch/x86/kernel/module.c
24074@@ -43,15 +43,60 @@ do { \
24075 } while (0)
24076 #endif
24077
24078-void *module_alloc(unsigned long size)
24079+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
24080 {
24081- if (PAGE_ALIGN(size) > MODULES_LEN)
24082+ if (!size || PAGE_ALIGN(size) > MODULES_LEN)
24083 return NULL;
24084 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
24085- GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
24086+ GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
24087 -1, __builtin_return_address(0));
24088 }
24089
24090+void *module_alloc(unsigned long size)
24091+{
24092+
24093+#ifdef CONFIG_PAX_KERNEXEC
24094+ return __module_alloc(size, PAGE_KERNEL);
24095+#else
24096+ return __module_alloc(size, PAGE_KERNEL_EXEC);
24097+#endif
24098+
24099+}
24100+
24101+#ifdef CONFIG_PAX_KERNEXEC
24102+#ifdef CONFIG_X86_32
24103+void *module_alloc_exec(unsigned long size)
24104+{
24105+ struct vm_struct *area;
24106+
24107+ if (size == 0)
24108+ return NULL;
24109+
24110+ area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
24111+ return area ? area->addr : NULL;
24112+}
24113+EXPORT_SYMBOL(module_alloc_exec);
24114+
24115+void module_free_exec(struct module *mod, void *module_region)
24116+{
24117+ vunmap(module_region);
24118+}
24119+EXPORT_SYMBOL(module_free_exec);
24120+#else
24121+void module_free_exec(struct module *mod, void *module_region)
24122+{
24123+ module_free(mod, module_region);
24124+}
24125+EXPORT_SYMBOL(module_free_exec);
24126+
24127+void *module_alloc_exec(unsigned long size)
24128+{
24129+ return __module_alloc(size, PAGE_KERNEL_RX);
24130+}
24131+EXPORT_SYMBOL(module_alloc_exec);
24132+#endif
24133+#endif
24134+
24135 #ifdef CONFIG_X86_32
24136 int apply_relocate(Elf32_Shdr *sechdrs,
24137 const char *strtab,
24138@@ -62,14 +107,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
24139 unsigned int i;
24140 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
24141 Elf32_Sym *sym;
24142- uint32_t *location;
24143+ uint32_t *plocation, location;
24144
24145 DEBUGP("Applying relocate section %u to %u\n",
24146 relsec, sechdrs[relsec].sh_info);
24147 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
24148 /* This is where to make the change */
24149- location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
24150- + rel[i].r_offset;
24151+ plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
24152+ location = (uint32_t)plocation;
24153+ if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
24154+ plocation = ktla_ktva((void *)plocation);
24155 /* This is the symbol it is referring to. Note that all
24156 undefined symbols have been resolved. */
24157 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
24158@@ -78,11 +125,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
24159 switch (ELF32_R_TYPE(rel[i].r_info)) {
24160 case R_386_32:
24161 /* We add the value into the location given */
24162- *location += sym->st_value;
24163+ pax_open_kernel();
24164+ *plocation += sym->st_value;
24165+ pax_close_kernel();
24166 break;
24167 case R_386_PC32:
24168 /* Add the value, subtract its position */
24169- *location += sym->st_value - (uint32_t)location;
24170+ pax_open_kernel();
24171+ *plocation += sym->st_value - location;
24172+ pax_close_kernel();
24173 break;
24174 default:
24175 pr_err("%s: Unknown relocation: %u\n",
24176@@ -127,21 +178,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
24177 case R_X86_64_NONE:
24178 break;
24179 case R_X86_64_64:
24180+ pax_open_kernel();
24181 *(u64 *)loc = val;
24182+ pax_close_kernel();
24183 break;
24184 case R_X86_64_32:
24185+ pax_open_kernel();
24186 *(u32 *)loc = val;
24187+ pax_close_kernel();
24188 if (val != *(u32 *)loc)
24189 goto overflow;
24190 break;
24191 case R_X86_64_32S:
24192+ pax_open_kernel();
24193 *(s32 *)loc = val;
24194+ pax_close_kernel();
24195 if ((s64)val != *(s32 *)loc)
24196 goto overflow;
24197 break;
24198 case R_X86_64_PC32:
24199 val -= (u64)loc;
24200+ pax_open_kernel();
24201 *(u32 *)loc = val;
24202+ pax_close_kernel();
24203+
24204 #if 0
24205 if ((s64)val != *(s32 *)loc)
24206 goto overflow;
24207diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
24208index 88458fa..349f7a4 100644
24209--- a/arch/x86/kernel/msr.c
24210+++ b/arch/x86/kernel/msr.c
24211@@ -233,7 +233,7 @@ static int msr_class_cpu_callback(struct notifier_block *nfb,
24212 return notifier_from_errno(err);
24213 }
24214
24215-static struct notifier_block __refdata msr_class_cpu_notifier = {
24216+static struct notifier_block msr_class_cpu_notifier = {
24217 .notifier_call = msr_class_cpu_callback,
24218 };
24219
24220diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
24221index 6fcb49c..5b3f4ff 100644
24222--- a/arch/x86/kernel/nmi.c
24223+++ b/arch/x86/kernel/nmi.c
24224@@ -138,7 +138,7 @@ static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2
24225 return handled;
24226 }
24227
24228-int __register_nmi_handler(unsigned int type, struct nmiaction *action)
24229+int __register_nmi_handler(unsigned int type, const struct nmiaction *action)
24230 {
24231 struct nmi_desc *desc = nmi_to_desc(type);
24232 unsigned long flags;
24233@@ -162,9 +162,9 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
24234 * event confuses some handlers (kdump uses this flag)
24235 */
24236 if (action->flags & NMI_FLAG_FIRST)
24237- list_add_rcu(&action->list, &desc->head);
24238+ pax_list_add_rcu((struct list_head *)&action->list, &desc->head);
24239 else
24240- list_add_tail_rcu(&action->list, &desc->head);
24241+ pax_list_add_tail_rcu((struct list_head *)&action->list, &desc->head);
24242
24243 spin_unlock_irqrestore(&desc->lock, flags);
24244 return 0;
24245@@ -187,7 +187,7 @@ void unregister_nmi_handler(unsigned int type, const char *name)
24246 if (!strcmp(n->name, name)) {
24247 WARN(in_nmi(),
24248 "Trying to free NMI (%s) from NMI context!\n", n->name);
24249- list_del_rcu(&n->list);
24250+ pax_list_del_rcu((struct list_head *)&n->list);
24251 break;
24252 }
24253 }
24254@@ -512,6 +512,17 @@ static inline void nmi_nesting_postprocess(void)
24255 dotraplinkage notrace __kprobes void
24256 do_nmi(struct pt_regs *regs, long error_code)
24257 {
24258+
24259+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
24260+ if (!user_mode(regs)) {
24261+ unsigned long cs = regs->cs & 0xFFFF;
24262+ unsigned long ip = ktva_ktla(regs->ip);
24263+
24264+ if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
24265+ regs->ip = ip;
24266+ }
24267+#endif
24268+
24269 nmi_nesting_preprocess(regs);
24270
24271 nmi_enter();
24272diff --git a/arch/x86/kernel/nmi_selftest.c b/arch/x86/kernel/nmi_selftest.c
24273index 6d9582e..f746287 100644
24274--- a/arch/x86/kernel/nmi_selftest.c
24275+++ b/arch/x86/kernel/nmi_selftest.c
24276@@ -43,7 +43,7 @@ static void __init init_nmi_testsuite(void)
24277 {
24278 /* trap all the unknown NMIs we may generate */
24279 register_nmi_handler(NMI_UNKNOWN, nmi_unk_cb, 0, "nmi_selftest_unk",
24280- __initdata);
24281+ __initconst);
24282 }
24283
24284 static void __init cleanup_nmi_testsuite(void)
24285@@ -66,7 +66,7 @@ static void __init test_nmi_ipi(struct cpumask *mask)
24286 unsigned long timeout;
24287
24288 if (register_nmi_handler(NMI_LOCAL, test_nmi_ipi_callback,
24289- NMI_FLAG_FIRST, "nmi_selftest", __initdata)) {
24290+ NMI_FLAG_FIRST, "nmi_selftest", __initconst)) {
24291 nmi_fail = FAILURE;
24292 return;
24293 }
24294diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
24295index bbb6c73..24a58ef 100644
24296--- a/arch/x86/kernel/paravirt-spinlocks.c
24297+++ b/arch/x86/kernel/paravirt-spinlocks.c
24298@@ -8,7 +8,7 @@
24299
24300 #include <asm/paravirt.h>
24301
24302-struct pv_lock_ops pv_lock_ops = {
24303+struct pv_lock_ops pv_lock_ops __read_only = {
24304 #ifdef CONFIG_SMP
24305 .lock_spinning = __PV_IS_CALLEE_SAVE(paravirt_nop),
24306 .unlock_kick = paravirt_nop,
24307diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
24308index 1b10af8..0b58cbc 100644
24309--- a/arch/x86/kernel/paravirt.c
24310+++ b/arch/x86/kernel/paravirt.c
24311@@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
24312 {
24313 return x;
24314 }
24315+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
24316+PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
24317+#endif
24318
24319 void __init default_banner(void)
24320 {
24321@@ -142,15 +145,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
24322 if (opfunc == NULL)
24323 /* If there's no function, patch it with a ud2a (BUG) */
24324 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
24325- else if (opfunc == _paravirt_nop)
24326+ else if (opfunc == (void *)_paravirt_nop)
24327 /* If the operation is a nop, then nop the callsite */
24328 ret = paravirt_patch_nop();
24329
24330 /* identity functions just return their single argument */
24331- else if (opfunc == _paravirt_ident_32)
24332+ else if (opfunc == (void *)_paravirt_ident_32)
24333 ret = paravirt_patch_ident_32(insnbuf, len);
24334- else if (opfunc == _paravirt_ident_64)
24335+ else if (opfunc == (void *)_paravirt_ident_64)
24336 ret = paravirt_patch_ident_64(insnbuf, len);
24337+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
24338+ else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
24339+ ret = paravirt_patch_ident_64(insnbuf, len);
24340+#endif
24341
24342 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
24343 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
24344@@ -175,7 +182,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
24345 if (insn_len > len || start == NULL)
24346 insn_len = len;
24347 else
24348- memcpy(insnbuf, start, insn_len);
24349+ memcpy(insnbuf, ktla_ktva(start), insn_len);
24350
24351 return insn_len;
24352 }
24353@@ -299,7 +306,7 @@ enum paravirt_lazy_mode paravirt_get_lazy_mode(void)
24354 return this_cpu_read(paravirt_lazy_mode);
24355 }
24356
24357-struct pv_info pv_info = {
24358+struct pv_info pv_info __read_only = {
24359 .name = "bare hardware",
24360 .paravirt_enabled = 0,
24361 .kernel_rpl = 0,
24362@@ -310,16 +317,16 @@ struct pv_info pv_info = {
24363 #endif
24364 };
24365
24366-struct pv_init_ops pv_init_ops = {
24367+struct pv_init_ops pv_init_ops __read_only = {
24368 .patch = native_patch,
24369 };
24370
24371-struct pv_time_ops pv_time_ops = {
24372+struct pv_time_ops pv_time_ops __read_only = {
24373 .sched_clock = native_sched_clock,
24374 .steal_clock = native_steal_clock,
24375 };
24376
24377-__visible struct pv_irq_ops pv_irq_ops = {
24378+__visible struct pv_irq_ops pv_irq_ops __read_only = {
24379 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
24380 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
24381 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
24382@@ -331,7 +338,7 @@ __visible struct pv_irq_ops pv_irq_ops = {
24383 #endif
24384 };
24385
24386-__visible struct pv_cpu_ops pv_cpu_ops = {
24387+__visible struct pv_cpu_ops pv_cpu_ops __read_only = {
24388 .cpuid = native_cpuid,
24389 .get_debugreg = native_get_debugreg,
24390 .set_debugreg = native_set_debugreg,
24391@@ -389,21 +396,26 @@ __visible struct pv_cpu_ops pv_cpu_ops = {
24392 .end_context_switch = paravirt_nop,
24393 };
24394
24395-struct pv_apic_ops pv_apic_ops = {
24396+struct pv_apic_ops pv_apic_ops __read_only= {
24397 #ifdef CONFIG_X86_LOCAL_APIC
24398 .startup_ipi_hook = paravirt_nop,
24399 #endif
24400 };
24401
24402-#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
24403+#ifdef CONFIG_X86_32
24404+#ifdef CONFIG_X86_PAE
24405+/* 64-bit pagetable entries */
24406+#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
24407+#else
24408 /* 32-bit pagetable entries */
24409 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
24410+#endif
24411 #else
24412 /* 64-bit pagetable entries */
24413 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
24414 #endif
24415
24416-struct pv_mmu_ops pv_mmu_ops = {
24417+struct pv_mmu_ops pv_mmu_ops __read_only = {
24418
24419 .read_cr2 = native_read_cr2,
24420 .write_cr2 = native_write_cr2,
24421@@ -453,6 +465,7 @@ struct pv_mmu_ops pv_mmu_ops = {
24422 .make_pud = PTE_IDENT,
24423
24424 .set_pgd = native_set_pgd,
24425+ .set_pgd_batched = native_set_pgd_batched,
24426 #endif
24427 #endif /* PAGETABLE_LEVELS >= 3 */
24428
24429@@ -473,6 +486,12 @@ struct pv_mmu_ops pv_mmu_ops = {
24430 },
24431
24432 .set_fixmap = native_set_fixmap,
24433+
24434+#ifdef CONFIG_PAX_KERNEXEC
24435+ .pax_open_kernel = native_pax_open_kernel,
24436+ .pax_close_kernel = native_pax_close_kernel,
24437+#endif
24438+
24439 };
24440
24441 EXPORT_SYMBOL_GPL(pv_time_ops);
24442diff --git a/arch/x86/kernel/pci-calgary_64.c b/arch/x86/kernel/pci-calgary_64.c
24443index 299d493..2ccb0ee 100644
24444--- a/arch/x86/kernel/pci-calgary_64.c
24445+++ b/arch/x86/kernel/pci-calgary_64.c
24446@@ -1339,7 +1339,7 @@ static void __init get_tce_space_from_tar(void)
24447 tce_space = be64_to_cpu(readq(target));
24448 tce_space = tce_space & TAR_SW_BITS;
24449
24450- tce_space = tce_space & (~specified_table_size);
24451+ tce_space = tce_space & (~(unsigned long)specified_table_size);
24452 info->tce_space = (u64 *)__va(tce_space);
24453 }
24454 }
24455diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
24456index 35ccf75..7a15747 100644
24457--- a/arch/x86/kernel/pci-iommu_table.c
24458+++ b/arch/x86/kernel/pci-iommu_table.c
24459@@ -2,7 +2,7 @@
24460 #include <asm/iommu_table.h>
24461 #include <linux/string.h>
24462 #include <linux/kallsyms.h>
24463-
24464+#include <linux/sched.h>
24465
24466 #define DEBUG 1
24467
24468diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
24469index 6c483ba..d10ce2f 100644
24470--- a/arch/x86/kernel/pci-swiotlb.c
24471+++ b/arch/x86/kernel/pci-swiotlb.c
24472@@ -32,7 +32,7 @@ static void x86_swiotlb_free_coherent(struct device *dev, size_t size,
24473 void *vaddr, dma_addr_t dma_addr,
24474 struct dma_attrs *attrs)
24475 {
24476- swiotlb_free_coherent(dev, size, vaddr, dma_addr);
24477+ swiotlb_free_coherent(dev, size, vaddr, dma_addr, attrs);
24478 }
24479
24480 static struct dma_map_ops swiotlb_dma_ops = {
24481diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
24482index c83516b..432ad6d 100644
24483--- a/arch/x86/kernel/process.c
24484+++ b/arch/x86/kernel/process.c
24485@@ -36,7 +36,8 @@
24486 * section. Since TSS's are completely CPU-local, we want them
24487 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
24488 */
24489-__visible DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
24490+struct tss_struct init_tss[NR_CPUS] __visible ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
24491+EXPORT_SYMBOL(init_tss);
24492
24493 #ifdef CONFIG_X86_64
24494 static DEFINE_PER_CPU(unsigned char, is_idle);
24495@@ -92,7 +93,7 @@ void arch_task_cache_init(void)
24496 task_xstate_cachep =
24497 kmem_cache_create("task_xstate", xstate_size,
24498 __alignof__(union thread_xstate),
24499- SLAB_PANIC | SLAB_NOTRACK, NULL);
24500+ SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
24501 }
24502
24503 /*
24504@@ -105,7 +106,7 @@ void exit_thread(void)
24505 unsigned long *bp = t->io_bitmap_ptr;
24506
24507 if (bp) {
24508- struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
24509+ struct tss_struct *tss = init_tss + get_cpu();
24510
24511 t->io_bitmap_ptr = NULL;
24512 clear_thread_flag(TIF_IO_BITMAP);
24513@@ -125,6 +126,9 @@ void flush_thread(void)
24514 {
24515 struct task_struct *tsk = current;
24516
24517+#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
24518+ loadsegment(gs, 0);
24519+#endif
24520 flush_ptrace_hw_breakpoint(tsk);
24521 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
24522 drop_init_fpu(tsk);
24523@@ -271,7 +275,7 @@ static void __exit_idle(void)
24524 void exit_idle(void)
24525 {
24526 /* idle loop has pid 0 */
24527- if (current->pid)
24528+ if (task_pid_nr(current))
24529 return;
24530 __exit_idle();
24531 }
24532@@ -327,7 +331,7 @@ bool xen_set_default_idle(void)
24533 return ret;
24534 }
24535 #endif
24536-void stop_this_cpu(void *dummy)
24537+__noreturn void stop_this_cpu(void *dummy)
24538 {
24539 local_irq_disable();
24540 /*
24541@@ -456,16 +460,37 @@ static int __init idle_setup(char *str)
24542 }
24543 early_param("idle", idle_setup);
24544
24545-unsigned long arch_align_stack(unsigned long sp)
24546+#ifdef CONFIG_PAX_RANDKSTACK
24547+void pax_randomize_kstack(struct pt_regs *regs)
24548 {
24549- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
24550- sp -= get_random_int() % 8192;
24551- return sp & ~0xf;
24552-}
24553+ struct thread_struct *thread = &current->thread;
24554+ unsigned long time;
24555
24556-unsigned long arch_randomize_brk(struct mm_struct *mm)
24557-{
24558- unsigned long range_end = mm->brk + 0x02000000;
24559- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
24560-}
24561+ if (!randomize_va_space)
24562+ return;
24563+
24564+ if (v8086_mode(regs))
24565+ return;
24566
24567+ rdtscl(time);
24568+
24569+ /* P4 seems to return a 0 LSB, ignore it */
24570+#ifdef CONFIG_MPENTIUM4
24571+ time &= 0x3EUL;
24572+ time <<= 2;
24573+#elif defined(CONFIG_X86_64)
24574+ time &= 0xFUL;
24575+ time <<= 4;
24576+#else
24577+ time &= 0x1FUL;
24578+ time <<= 3;
24579+#endif
24580+
24581+ thread->sp0 ^= time;
24582+ load_sp0(init_tss + smp_processor_id(), thread);
24583+
24584+#ifdef CONFIG_X86_64
24585+ this_cpu_write(kernel_stack, thread->sp0);
24586+#endif
24587+}
24588+#endif
24589diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
24590index 884f98f..ec23e04 100644
24591--- a/arch/x86/kernel/process_32.c
24592+++ b/arch/x86/kernel/process_32.c
24593@@ -65,6 +65,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
24594 unsigned long thread_saved_pc(struct task_struct *tsk)
24595 {
24596 return ((unsigned long *)tsk->thread.sp)[3];
24597+//XXX return tsk->thread.eip;
24598 }
24599
24600 void __show_regs(struct pt_regs *regs, int all)
24601@@ -74,19 +75,18 @@ void __show_regs(struct pt_regs *regs, int all)
24602 unsigned long sp;
24603 unsigned short ss, gs;
24604
24605- if (user_mode_vm(regs)) {
24606+ if (user_mode(regs)) {
24607 sp = regs->sp;
24608 ss = regs->ss & 0xffff;
24609- gs = get_user_gs(regs);
24610 } else {
24611 sp = kernel_stack_pointer(regs);
24612 savesegment(ss, ss);
24613- savesegment(gs, gs);
24614 }
24615+ gs = get_user_gs(regs);
24616
24617 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
24618 (u16)regs->cs, regs->ip, regs->flags,
24619- smp_processor_id());
24620+ raw_smp_processor_id());
24621 print_symbol("EIP is at %s\n", regs->ip);
24622
24623 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
24624@@ -133,20 +133,21 @@ void release_thread(struct task_struct *dead_task)
24625 int copy_thread(unsigned long clone_flags, unsigned long sp,
24626 unsigned long arg, struct task_struct *p)
24627 {
24628- struct pt_regs *childregs = task_pt_regs(p);
24629+ struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
24630 struct task_struct *tsk;
24631 int err;
24632
24633 p->thread.sp = (unsigned long) childregs;
24634 p->thread.sp0 = (unsigned long) (childregs+1);
24635+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
24636
24637 if (unlikely(p->flags & PF_KTHREAD)) {
24638 /* kernel thread */
24639 memset(childregs, 0, sizeof(struct pt_regs));
24640 p->thread.ip = (unsigned long) ret_from_kernel_thread;
24641- task_user_gs(p) = __KERNEL_STACK_CANARY;
24642- childregs->ds = __USER_DS;
24643- childregs->es = __USER_DS;
24644+ savesegment(gs, childregs->gs);
24645+ childregs->ds = __KERNEL_DS;
24646+ childregs->es = __KERNEL_DS;
24647 childregs->fs = __KERNEL_PERCPU;
24648 childregs->bx = sp; /* function */
24649 childregs->bp = arg;
24650@@ -253,7 +254,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
24651 struct thread_struct *prev = &prev_p->thread,
24652 *next = &next_p->thread;
24653 int cpu = smp_processor_id();
24654- struct tss_struct *tss = &per_cpu(init_tss, cpu);
24655+ struct tss_struct *tss = init_tss + cpu;
24656 fpu_switch_t fpu;
24657
24658 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
24659@@ -277,6 +278,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
24660 */
24661 lazy_save_gs(prev->gs);
24662
24663+#ifdef CONFIG_PAX_MEMORY_UDEREF
24664+ __set_fs(task_thread_info(next_p)->addr_limit);
24665+#endif
24666+
24667 /*
24668 * Load the per-thread Thread-Local Storage descriptor.
24669 */
24670@@ -307,6 +312,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
24671 */
24672 arch_end_context_switch(next_p);
24673
24674+ this_cpu_write(current_task, next_p);
24675+ this_cpu_write(current_tinfo, &next_p->tinfo);
24676+
24677 /*
24678 * Restore %gs if needed (which is common)
24679 */
24680@@ -315,8 +323,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
24681
24682 switch_fpu_finish(next_p, fpu);
24683
24684- this_cpu_write(current_task, next_p);
24685-
24686 return prev_p;
24687 }
24688
24689@@ -346,4 +352,3 @@ unsigned long get_wchan(struct task_struct *p)
24690 } while (count++ < 16);
24691 return 0;
24692 }
24693-
24694diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
24695index bb1dc51..08dda7f 100644
24696--- a/arch/x86/kernel/process_64.c
24697+++ b/arch/x86/kernel/process_64.c
24698@@ -158,10 +158,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
24699 struct pt_regs *childregs;
24700 struct task_struct *me = current;
24701
24702- p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
24703+ p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
24704 childregs = task_pt_regs(p);
24705 p->thread.sp = (unsigned long) childregs;
24706 p->thread.usersp = me->thread.usersp;
24707+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
24708 set_tsk_thread_flag(p, TIF_FORK);
24709 p->fpu_counter = 0;
24710 p->thread.io_bitmap_ptr = NULL;
24711@@ -172,6 +173,8 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
24712 p->thread.fs = p->thread.fsindex ? 0 : me->thread.fs;
24713 savesegment(es, p->thread.es);
24714 savesegment(ds, p->thread.ds);
24715+ savesegment(ss, p->thread.ss);
24716+ BUG_ON(p->thread.ss == __UDEREF_KERNEL_DS);
24717 memset(p->thread.ptrace_bps, 0, sizeof(p->thread.ptrace_bps));
24718
24719 if (unlikely(p->flags & PF_KTHREAD)) {
24720@@ -280,7 +283,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
24721 struct thread_struct *prev = &prev_p->thread;
24722 struct thread_struct *next = &next_p->thread;
24723 int cpu = smp_processor_id();
24724- struct tss_struct *tss = &per_cpu(init_tss, cpu);
24725+ struct tss_struct *tss = init_tss + cpu;
24726 unsigned fsindex, gsindex;
24727 fpu_switch_t fpu;
24728
24729@@ -303,6 +306,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
24730 if (unlikely(next->ds | prev->ds))
24731 loadsegment(ds, next->ds);
24732
24733+ savesegment(ss, prev->ss);
24734+ if (unlikely(next->ss != prev->ss))
24735+ loadsegment(ss, next->ss);
24736
24737 /* We must save %fs and %gs before load_TLS() because
24738 * %fs and %gs may be cleared by load_TLS().
24739@@ -362,10 +368,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
24740 prev->usersp = this_cpu_read(old_rsp);
24741 this_cpu_write(old_rsp, next->usersp);
24742 this_cpu_write(current_task, next_p);
24743+ this_cpu_write(current_tinfo, &next_p->tinfo);
24744
24745- this_cpu_write(kernel_stack,
24746- (unsigned long)task_stack_page(next_p) +
24747- THREAD_SIZE - KERNEL_STACK_OFFSET);
24748+ this_cpu_write(kernel_stack, next->sp0);
24749
24750 /*
24751 * Now maybe reload the debug registers and handle I/O bitmaps
24752@@ -434,12 +439,11 @@ unsigned long get_wchan(struct task_struct *p)
24753 if (!p || p == current || p->state == TASK_RUNNING)
24754 return 0;
24755 stack = (unsigned long)task_stack_page(p);
24756- if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
24757+ if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
24758 return 0;
24759 fp = *(u64 *)(p->thread.sp);
24760 do {
24761- if (fp < (unsigned long)stack ||
24762- fp >= (unsigned long)stack+THREAD_SIZE)
24763+ if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
24764 return 0;
24765 ip = *(u64 *)(fp+8);
24766 if (!in_sched_functions(ip))
24767diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
24768index 7461f50..1334029 100644
24769--- a/arch/x86/kernel/ptrace.c
24770+++ b/arch/x86/kernel/ptrace.c
24771@@ -184,14 +184,13 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
24772 {
24773 unsigned long context = (unsigned long)regs & ~(THREAD_SIZE - 1);
24774 unsigned long sp = (unsigned long)&regs->sp;
24775- struct thread_info *tinfo;
24776
24777- if (context == (sp & ~(THREAD_SIZE - 1)))
24778+ if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
24779 return sp;
24780
24781- tinfo = (struct thread_info *)context;
24782- if (tinfo->previous_esp)
24783- return tinfo->previous_esp;
24784+ sp = *(unsigned long *)context;
24785+ if (sp)
24786+ return sp;
24787
24788 return (unsigned long)regs;
24789 }
24790@@ -588,7 +587,7 @@ static void ptrace_triggered(struct perf_event *bp,
24791 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
24792 {
24793 int i;
24794- int dr7 = 0;
24795+ unsigned long dr7 = 0;
24796 struct arch_hw_breakpoint *info;
24797
24798 for (i = 0; i < HBP_NUM; i++) {
24799@@ -822,7 +821,7 @@ long arch_ptrace(struct task_struct *child, long request,
24800 unsigned long addr, unsigned long data)
24801 {
24802 int ret;
24803- unsigned long __user *datap = (unsigned long __user *)data;
24804+ unsigned long __user *datap = (__force unsigned long __user *)data;
24805
24806 switch (request) {
24807 /* read the word at location addr in the USER area. */
24808@@ -907,14 +906,14 @@ long arch_ptrace(struct task_struct *child, long request,
24809 if ((int) addr < 0)
24810 return -EIO;
24811 ret = do_get_thread_area(child, addr,
24812- (struct user_desc __user *)data);
24813+ (__force struct user_desc __user *) data);
24814 break;
24815
24816 case PTRACE_SET_THREAD_AREA:
24817 if ((int) addr < 0)
24818 return -EIO;
24819 ret = do_set_thread_area(child, addr,
24820- (struct user_desc __user *)data, 0);
24821+ (__force struct user_desc __user *) data, 0);
24822 break;
24823 #endif
24824
24825@@ -1292,7 +1291,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
24826
24827 #ifdef CONFIG_X86_64
24828
24829-static struct user_regset x86_64_regsets[] __read_mostly = {
24830+static user_regset_no_const x86_64_regsets[] __read_only = {
24831 [REGSET_GENERAL] = {
24832 .core_note_type = NT_PRSTATUS,
24833 .n = sizeof(struct user_regs_struct) / sizeof(long),
24834@@ -1333,7 +1332,7 @@ static const struct user_regset_view user_x86_64_view = {
24835 #endif /* CONFIG_X86_64 */
24836
24837 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
24838-static struct user_regset x86_32_regsets[] __read_mostly = {
24839+static user_regset_no_const x86_32_regsets[] __read_only = {
24840 [REGSET_GENERAL] = {
24841 .core_note_type = NT_PRSTATUS,
24842 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
24843@@ -1386,7 +1385,7 @@ static const struct user_regset_view user_x86_32_view = {
24844 */
24845 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
24846
24847-void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
24848+void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
24849 {
24850 #ifdef CONFIG_X86_64
24851 x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
24852@@ -1421,7 +1420,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
24853 memset(info, 0, sizeof(*info));
24854 info->si_signo = SIGTRAP;
24855 info->si_code = si_code;
24856- info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
24857+ info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
24858 }
24859
24860 void user_single_step_siginfo(struct task_struct *tsk,
24861@@ -1450,6 +1449,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
24862 # define IS_IA32 0
24863 #endif
24864
24865+#ifdef CONFIG_GRKERNSEC_SETXID
24866+extern void gr_delayed_cred_worker(void);
24867+#endif
24868+
24869 /*
24870 * We must return the syscall number to actually look up in the table.
24871 * This can be -1L to skip running any syscall at all.
24872@@ -1460,6 +1463,11 @@ long syscall_trace_enter(struct pt_regs *regs)
24873
24874 user_exit();
24875
24876+#ifdef CONFIG_GRKERNSEC_SETXID
24877+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
24878+ gr_delayed_cred_worker();
24879+#endif
24880+
24881 /*
24882 * If we stepped into a sysenter/syscall insn, it trapped in
24883 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
24884@@ -1515,6 +1523,11 @@ void syscall_trace_leave(struct pt_regs *regs)
24885 */
24886 user_exit();
24887
24888+#ifdef CONFIG_GRKERNSEC_SETXID
24889+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
24890+ gr_delayed_cred_worker();
24891+#endif
24892+
24893 audit_syscall_exit(regs);
24894
24895 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
24896diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
24897index a16bae3..1f65f25 100644
24898--- a/arch/x86/kernel/pvclock.c
24899+++ b/arch/x86/kernel/pvclock.c
24900@@ -43,11 +43,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
24901 return pv_tsc_khz;
24902 }
24903
24904-static atomic64_t last_value = ATOMIC64_INIT(0);
24905+static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
24906
24907 void pvclock_resume(void)
24908 {
24909- atomic64_set(&last_value, 0);
24910+ atomic64_set_unchecked(&last_value, 0);
24911 }
24912
24913 u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src)
24914@@ -92,11 +92,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
24915 * updating at the same time, and one of them could be slightly behind,
24916 * making the assumption that last_value always go forward fail to hold.
24917 */
24918- last = atomic64_read(&last_value);
24919+ last = atomic64_read_unchecked(&last_value);
24920 do {
24921 if (ret < last)
24922 return last;
24923- last = atomic64_cmpxchg(&last_value, last, ret);
24924+ last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
24925 } while (unlikely(last != ret));
24926
24927 return ret;
24928diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
24929index 7e920bf..cc24446 100644
24930--- a/arch/x86/kernel/reboot.c
24931+++ b/arch/x86/kernel/reboot.c
24932@@ -68,6 +68,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
24933
24934 void __noreturn machine_real_restart(unsigned int type)
24935 {
24936+
24937+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
24938+ struct desc_struct *gdt;
24939+#endif
24940+
24941 local_irq_disable();
24942
24943 /*
24944@@ -95,7 +100,29 @@ void __noreturn machine_real_restart(unsigned int type)
24945
24946 /* Jump to the identity-mapped low memory code */
24947 #ifdef CONFIG_X86_32
24948- asm volatile("jmpl *%0" : :
24949+
24950+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
24951+ gdt = get_cpu_gdt_table(smp_processor_id());
24952+ pax_open_kernel();
24953+#ifdef CONFIG_PAX_MEMORY_UDEREF
24954+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
24955+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
24956+ loadsegment(ds, __KERNEL_DS);
24957+ loadsegment(es, __KERNEL_DS);
24958+ loadsegment(ss, __KERNEL_DS);
24959+#endif
24960+#ifdef CONFIG_PAX_KERNEXEC
24961+ gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
24962+ gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
24963+ gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
24964+ gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
24965+ gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
24966+ gdt[GDT_ENTRY_KERNEL_CS].g = 1;
24967+#endif
24968+ pax_close_kernel();
24969+#endif
24970+
24971+ asm volatile("ljmpl *%0" : :
24972 "rm" (real_mode_header->machine_real_restart_asm),
24973 "a" (type));
24974 #else
24975@@ -466,7 +493,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
24976 * try to force a triple fault and then cycle between hitting the keyboard
24977 * controller and doing that
24978 */
24979-static void native_machine_emergency_restart(void)
24980+static void __noreturn native_machine_emergency_restart(void)
24981 {
24982 int i;
24983 int attempt = 0;
24984@@ -575,13 +602,13 @@ void native_machine_shutdown(void)
24985 #endif
24986 }
24987
24988-static void __machine_emergency_restart(int emergency)
24989+static void __noreturn __machine_emergency_restart(int emergency)
24990 {
24991 reboot_emergency = emergency;
24992 machine_ops.emergency_restart();
24993 }
24994
24995-static void native_machine_restart(char *__unused)
24996+static void __noreturn native_machine_restart(char *__unused)
24997 {
24998 pr_notice("machine restart\n");
24999
25000@@ -590,7 +617,7 @@ static void native_machine_restart(char *__unused)
25001 __machine_emergency_restart(0);
25002 }
25003
25004-static void native_machine_halt(void)
25005+static void __noreturn native_machine_halt(void)
25006 {
25007 /* Stop other cpus and apics */
25008 machine_shutdown();
25009@@ -600,7 +627,7 @@ static void native_machine_halt(void)
25010 stop_this_cpu(NULL);
25011 }
25012
25013-static void native_machine_power_off(void)
25014+static void __noreturn native_machine_power_off(void)
25015 {
25016 if (pm_power_off) {
25017 if (!reboot_force)
25018@@ -609,9 +636,10 @@ static void native_machine_power_off(void)
25019 }
25020 /* A fallback in case there is no PM info available */
25021 tboot_shutdown(TB_SHUTDOWN_HALT);
25022+ unreachable();
25023 }
25024
25025-struct machine_ops machine_ops = {
25026+struct machine_ops machine_ops __read_only = {
25027 .power_off = native_machine_power_off,
25028 .shutdown = native_machine_shutdown,
25029 .emergency_restart = native_machine_emergency_restart,
25030diff --git a/arch/x86/kernel/reboot_fixups_32.c b/arch/x86/kernel/reboot_fixups_32.c
25031index c8e41e9..64049ef 100644
25032--- a/arch/x86/kernel/reboot_fixups_32.c
25033+++ b/arch/x86/kernel/reboot_fixups_32.c
25034@@ -57,7 +57,7 @@ struct device_fixup {
25035 unsigned int vendor;
25036 unsigned int device;
25037 void (*reboot_fixup)(struct pci_dev *);
25038-};
25039+} __do_const;
25040
25041 /*
25042 * PCI ids solely used for fixups_table go here
25043diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
25044index 3fd2c69..16ef367 100644
25045--- a/arch/x86/kernel/relocate_kernel_64.S
25046+++ b/arch/x86/kernel/relocate_kernel_64.S
25047@@ -11,6 +11,7 @@
25048 #include <asm/kexec.h>
25049 #include <asm/processor-flags.h>
25050 #include <asm/pgtable_types.h>
25051+#include <asm/alternative-asm.h>
25052
25053 /*
25054 * Must be relocatable PIC code callable as a C function
25055@@ -96,8 +97,7 @@ relocate_kernel:
25056
25057 /* jump to identity mapped page */
25058 addq $(identity_mapped - relocate_kernel), %r8
25059- pushq %r8
25060- ret
25061+ jmp *%r8
25062
25063 identity_mapped:
25064 /* set return address to 0 if not preserving context */
25065@@ -167,6 +167,7 @@ identity_mapped:
25066 xorl %r14d, %r14d
25067 xorl %r15d, %r15d
25068
25069+ pax_force_retaddr 0, 1
25070 ret
25071
25072 1:
25073diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
25074index f0de629..a4978a8f 100644
25075--- a/arch/x86/kernel/setup.c
25076+++ b/arch/x86/kernel/setup.c
25077@@ -110,6 +110,7 @@
25078 #include <asm/mce.h>
25079 #include <asm/alternative.h>
25080 #include <asm/prom.h>
25081+#include <asm/boot.h>
25082
25083 /*
25084 * max_low_pfn_mapped: highest direct mapped pfn under 4GB
25085@@ -205,12 +206,50 @@ EXPORT_SYMBOL(boot_cpu_data);
25086 #endif
25087
25088
25089-#if !defined(CONFIG_X86_PAE) || defined(CONFIG_X86_64)
25090-__visible unsigned long mmu_cr4_features;
25091+#ifdef CONFIG_X86_64
25092+__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE;
25093+#elif defined(CONFIG_X86_PAE)
25094+__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PAE;
25095 #else
25096-__visible unsigned long mmu_cr4_features = X86_CR4_PAE;
25097+__visible unsigned long mmu_cr4_features __read_only;
25098 #endif
25099
25100+void set_in_cr4(unsigned long mask)
25101+{
25102+ unsigned long cr4 = read_cr4();
25103+
25104+ if ((cr4 & mask) == mask && cr4 == mmu_cr4_features)
25105+ return;
25106+
25107+ pax_open_kernel();
25108+ mmu_cr4_features |= mask;
25109+ pax_close_kernel();
25110+
25111+ if (trampoline_cr4_features)
25112+ *trampoline_cr4_features = mmu_cr4_features;
25113+ cr4 |= mask;
25114+ write_cr4(cr4);
25115+}
25116+EXPORT_SYMBOL(set_in_cr4);
25117+
25118+void clear_in_cr4(unsigned long mask)
25119+{
25120+ unsigned long cr4 = read_cr4();
25121+
25122+ if (!(cr4 & mask) && cr4 == mmu_cr4_features)
25123+ return;
25124+
25125+ pax_open_kernel();
25126+ mmu_cr4_features &= ~mask;
25127+ pax_close_kernel();
25128+
25129+ if (trampoline_cr4_features)
25130+ *trampoline_cr4_features = mmu_cr4_features;
25131+ cr4 &= ~mask;
25132+ write_cr4(cr4);
25133+}
25134+EXPORT_SYMBOL(clear_in_cr4);
25135+
25136 /* Boot loader ID and version as integers, for the benefit of proc_dointvec */
25137 int bootloader_type, bootloader_version;
25138
25139@@ -768,7 +807,7 @@ static void __init trim_bios_range(void)
25140 * area (640->1Mb) as ram even though it is not.
25141 * take them out.
25142 */
25143- e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
25144+ e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
25145
25146 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
25147 }
25148@@ -776,7 +815,7 @@ static void __init trim_bios_range(void)
25149 /* called before trim_bios_range() to spare extra sanitize */
25150 static void __init e820_add_kernel_range(void)
25151 {
25152- u64 start = __pa_symbol(_text);
25153+ u64 start = __pa_symbol(ktla_ktva(_text));
25154 u64 size = __pa_symbol(_end) - start;
25155
25156 /*
25157@@ -838,8 +877,12 @@ static void __init trim_low_memory_range(void)
25158
25159 void __init setup_arch(char **cmdline_p)
25160 {
25161+#ifdef CONFIG_X86_32
25162+ memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(__bss_stop) - LOAD_PHYSICAL_ADDR);
25163+#else
25164 memblock_reserve(__pa_symbol(_text),
25165 (unsigned long)__bss_stop - (unsigned long)_text);
25166+#endif
25167
25168 early_reserve_initrd();
25169
25170@@ -931,14 +974,14 @@ void __init setup_arch(char **cmdline_p)
25171
25172 if (!boot_params.hdr.root_flags)
25173 root_mountflags &= ~MS_RDONLY;
25174- init_mm.start_code = (unsigned long) _text;
25175- init_mm.end_code = (unsigned long) _etext;
25176+ init_mm.start_code = ktla_ktva((unsigned long) _text);
25177+ init_mm.end_code = ktla_ktva((unsigned long) _etext);
25178 init_mm.end_data = (unsigned long) _edata;
25179 init_mm.brk = _brk_end;
25180
25181- code_resource.start = __pa_symbol(_text);
25182- code_resource.end = __pa_symbol(_etext)-1;
25183- data_resource.start = __pa_symbol(_etext);
25184+ code_resource.start = __pa_symbol(ktla_ktva(_text));
25185+ code_resource.end = __pa_symbol(ktla_ktva(_etext))-1;
25186+ data_resource.start = __pa_symbol(_sdata);
25187 data_resource.end = __pa_symbol(_edata)-1;
25188 bss_resource.start = __pa_symbol(__bss_start);
25189 bss_resource.end = __pa_symbol(__bss_stop)-1;
25190diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
25191index 5cdff03..80fa283 100644
25192--- a/arch/x86/kernel/setup_percpu.c
25193+++ b/arch/x86/kernel/setup_percpu.c
25194@@ -21,19 +21,17 @@
25195 #include <asm/cpu.h>
25196 #include <asm/stackprotector.h>
25197
25198-DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
25199+#ifdef CONFIG_SMP
25200+DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
25201 EXPORT_PER_CPU_SYMBOL(cpu_number);
25202+#endif
25203
25204-#ifdef CONFIG_X86_64
25205 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
25206-#else
25207-#define BOOT_PERCPU_OFFSET 0
25208-#endif
25209
25210 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
25211 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
25212
25213-unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
25214+unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
25215 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
25216 };
25217 EXPORT_SYMBOL(__per_cpu_offset);
25218@@ -66,7 +64,7 @@ static bool __init pcpu_need_numa(void)
25219 {
25220 #ifdef CONFIG_NEED_MULTIPLE_NODES
25221 pg_data_t *last = NULL;
25222- unsigned int cpu;
25223+ int cpu;
25224
25225 for_each_possible_cpu(cpu) {
25226 int node = early_cpu_to_node(cpu);
25227@@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
25228 {
25229 #ifdef CONFIG_X86_32
25230 struct desc_struct gdt;
25231+ unsigned long base = per_cpu_offset(cpu);
25232
25233- pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
25234- 0x2 | DESCTYPE_S, 0x8);
25235- gdt.s = 1;
25236+ pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
25237+ 0x83 | DESCTYPE_S, 0xC);
25238 write_gdt_entry(get_cpu_gdt_table(cpu),
25239 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
25240 #endif
25241@@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
25242 /* alrighty, percpu areas up and running */
25243 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
25244 for_each_possible_cpu(cpu) {
25245+#ifdef CONFIG_CC_STACKPROTECTOR
25246+#ifdef CONFIG_X86_32
25247+ unsigned long canary = per_cpu(stack_canary.canary, cpu);
25248+#endif
25249+#endif
25250 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
25251 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
25252 per_cpu(cpu_number, cpu) = cpu;
25253@@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
25254 */
25255 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
25256 #endif
25257+#ifdef CONFIG_CC_STACKPROTECTOR
25258+#ifdef CONFIG_X86_32
25259+ if (!cpu)
25260+ per_cpu(stack_canary.canary, cpu) = canary;
25261+#endif
25262+#endif
25263 /*
25264 * Up to this point, the boot CPU has been using .init.data
25265 * area. Reload any changed state for the boot CPU.
25266diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
25267index 9e5de68..16c53cb 100644
25268--- a/arch/x86/kernel/signal.c
25269+++ b/arch/x86/kernel/signal.c
25270@@ -190,7 +190,7 @@ static unsigned long align_sigframe(unsigned long sp)
25271 * Align the stack pointer according to the i386 ABI,
25272 * i.e. so that on function entry ((sp + 4) & 15) == 0.
25273 */
25274- sp = ((sp + 4) & -16ul) - 4;
25275+ sp = ((sp - 12) & -16ul) - 4;
25276 #else /* !CONFIG_X86_32 */
25277 sp = round_down(sp, 16) - 8;
25278 #endif
25279@@ -298,9 +298,9 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
25280 }
25281
25282 if (current->mm->context.vdso)
25283- restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
25284+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
25285 else
25286- restorer = &frame->retcode;
25287+ restorer = (void __user *)&frame->retcode;
25288 if (ksig->ka.sa.sa_flags & SA_RESTORER)
25289 restorer = ksig->ka.sa.sa_restorer;
25290
25291@@ -314,7 +314,7 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
25292 * reasons and because gdb uses it as a signature to notice
25293 * signal handler stack frames.
25294 */
25295- err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
25296+ err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
25297
25298 if (err)
25299 return -EFAULT;
25300@@ -361,7 +361,10 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
25301 save_altstack_ex(&frame->uc.uc_stack, regs->sp);
25302
25303 /* Set up to return from userspace. */
25304- restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
25305+ if (current->mm->context.vdso)
25306+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
25307+ else
25308+ restorer = (void __user *)&frame->retcode;
25309 if (ksig->ka.sa.sa_flags & SA_RESTORER)
25310 restorer = ksig->ka.sa.sa_restorer;
25311 put_user_ex(restorer, &frame->pretcode);
25312@@ -373,7 +376,7 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
25313 * reasons and because gdb uses it as a signature to notice
25314 * signal handler stack frames.
25315 */
25316- put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
25317+ put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
25318 } put_user_catch(err);
25319
25320 err |= copy_siginfo_to_user(&frame->info, &ksig->info);
25321@@ -609,7 +612,12 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
25322 {
25323 int usig = signr_convert(ksig->sig);
25324 sigset_t *set = sigmask_to_save();
25325- compat_sigset_t *cset = (compat_sigset_t *) set;
25326+ sigset_t sigcopy;
25327+ compat_sigset_t *cset;
25328+
25329+ sigcopy = *set;
25330+
25331+ cset = (compat_sigset_t *) &sigcopy;
25332
25333 /* Set up the stack frame */
25334 if (is_ia32_frame()) {
25335@@ -620,7 +628,7 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
25336 } else if (is_x32_frame()) {
25337 return x32_setup_rt_frame(ksig, cset, regs);
25338 } else {
25339- return __setup_rt_frame(ksig->sig, ksig, set, regs);
25340+ return __setup_rt_frame(ksig->sig, ksig, &sigcopy, regs);
25341 }
25342 }
25343
25344diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c
25345index 7c3a5a6..f0a8961 100644
25346--- a/arch/x86/kernel/smp.c
25347+++ b/arch/x86/kernel/smp.c
25348@@ -341,7 +341,7 @@ static int __init nonmi_ipi_setup(char *str)
25349
25350 __setup("nonmi_ipi", nonmi_ipi_setup);
25351
25352-struct smp_ops smp_ops = {
25353+struct smp_ops smp_ops __read_only = {
25354 .smp_prepare_boot_cpu = native_smp_prepare_boot_cpu,
25355 .smp_prepare_cpus = native_smp_prepare_cpus,
25356 .smp_cpus_done = native_smp_cpus_done,
25357diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
25358index 6cacab6..750636a 100644
25359--- a/arch/x86/kernel/smpboot.c
25360+++ b/arch/x86/kernel/smpboot.c
25361@@ -251,14 +251,18 @@ static void notrace start_secondary(void *unused)
25362
25363 enable_start_cpu0 = 0;
25364
25365-#ifdef CONFIG_X86_32
25366- /* switch away from the initial page table */
25367- load_cr3(swapper_pg_dir);
25368- __flush_tlb_all();
25369-#endif
25370-
25371 /* otherwise gcc will move up smp_processor_id before the cpu_init */
25372 barrier();
25373+
25374+ /* switch away from the initial page table */
25375+#ifdef CONFIG_PAX_PER_CPU_PGD
25376+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
25377+ __flush_tlb_all();
25378+#elif defined(CONFIG_X86_32)
25379+ load_cr3(swapper_pg_dir);
25380+ __flush_tlb_all();
25381+#endif
25382+
25383 /*
25384 * Check TSC synchronization with the BP:
25385 */
25386@@ -749,6 +753,7 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
25387 idle->thread.sp = (unsigned long) (((struct pt_regs *)
25388 (THREAD_SIZE + task_stack_page(idle))) - 1);
25389 per_cpu(current_task, cpu) = idle;
25390+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
25391
25392 #ifdef CONFIG_X86_32
25393 /* Stack for startup_32 can be just as for start_secondary onwards */
25394@@ -756,11 +761,13 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
25395 #else
25396 clear_tsk_thread_flag(idle, TIF_FORK);
25397 initial_gs = per_cpu_offset(cpu);
25398- per_cpu(kernel_stack, cpu) =
25399- (unsigned long)task_stack_page(idle) -
25400- KERNEL_STACK_OFFSET + THREAD_SIZE;
25401+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
25402 #endif
25403+
25404+ pax_open_kernel();
25405 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
25406+ pax_close_kernel();
25407+
25408 initial_code = (unsigned long)start_secondary;
25409 stack_start = idle->thread.sp;
25410
25411@@ -909,6 +916,15 @@ int native_cpu_up(unsigned int cpu, struct task_struct *tidle)
25412 /* the FPU context is blank, nobody can own it */
25413 __cpu_disable_lazy_restore(cpu);
25414
25415+#ifdef CONFIG_PAX_PER_CPU_PGD
25416+ clone_pgd_range(get_cpu_pgd(cpu, kernel) + KERNEL_PGD_BOUNDARY,
25417+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
25418+ KERNEL_PGD_PTRS);
25419+ clone_pgd_range(get_cpu_pgd(cpu, user) + KERNEL_PGD_BOUNDARY,
25420+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
25421+ KERNEL_PGD_PTRS);
25422+#endif
25423+
25424 err = do_boot_cpu(apicid, cpu, tidle);
25425 if (err) {
25426 pr_debug("do_boot_cpu failed %d\n", err);
25427diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
25428index 9b4d51d..5d28b58 100644
25429--- a/arch/x86/kernel/step.c
25430+++ b/arch/x86/kernel/step.c
25431@@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
25432 struct desc_struct *desc;
25433 unsigned long base;
25434
25435- seg &= ~7UL;
25436+ seg >>= 3;
25437
25438 mutex_lock(&child->mm->context.lock);
25439- if (unlikely((seg >> 3) >= child->mm->context.size))
25440+ if (unlikely(seg >= child->mm->context.size))
25441 addr = -1L; /* bogus selector, access would fault */
25442 else {
25443 desc = child->mm->context.ldt + seg;
25444@@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
25445 addr += base;
25446 }
25447 mutex_unlock(&child->mm->context.lock);
25448- }
25449+ } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
25450+ addr = ktla_ktva(addr);
25451
25452 return addr;
25453 }
25454@@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
25455 unsigned char opcode[15];
25456 unsigned long addr = convert_ip_to_linear(child, regs);
25457
25458+ if (addr == -EINVAL)
25459+ return 0;
25460+
25461 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
25462 for (i = 0; i < copied; i++) {
25463 switch (opcode[i]) {
25464diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
25465new file mode 100644
25466index 0000000..5877189
25467--- /dev/null
25468+++ b/arch/x86/kernel/sys_i386_32.c
25469@@ -0,0 +1,189 @@
25470+/*
25471+ * This file contains various random system calls that
25472+ * have a non-standard calling sequence on the Linux/i386
25473+ * platform.
25474+ */
25475+
25476+#include <linux/errno.h>
25477+#include <linux/sched.h>
25478+#include <linux/mm.h>
25479+#include <linux/fs.h>
25480+#include <linux/smp.h>
25481+#include <linux/sem.h>
25482+#include <linux/msg.h>
25483+#include <linux/shm.h>
25484+#include <linux/stat.h>
25485+#include <linux/syscalls.h>
25486+#include <linux/mman.h>
25487+#include <linux/file.h>
25488+#include <linux/utsname.h>
25489+#include <linux/ipc.h>
25490+#include <linux/elf.h>
25491+
25492+#include <linux/uaccess.h>
25493+#include <linux/unistd.h>
25494+
25495+#include <asm/syscalls.h>
25496+
25497+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
25498+{
25499+ unsigned long pax_task_size = TASK_SIZE;
25500+
25501+#ifdef CONFIG_PAX_SEGMEXEC
25502+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
25503+ pax_task_size = SEGMEXEC_TASK_SIZE;
25504+#endif
25505+
25506+ if (flags & MAP_FIXED)
25507+ if (len > pax_task_size || addr > pax_task_size - len)
25508+ return -EINVAL;
25509+
25510+ return 0;
25511+}
25512+
25513+/*
25514+ * Align a virtual address to avoid aliasing in the I$ on AMD F15h.
25515+ */
25516+static unsigned long get_align_mask(void)
25517+{
25518+ if (va_align.flags < 0 || !(va_align.flags & ALIGN_VA_32))
25519+ return 0;
25520+
25521+ if (!(current->flags & PF_RANDOMIZE))
25522+ return 0;
25523+
25524+ return va_align.mask;
25525+}
25526+
25527+unsigned long
25528+arch_get_unmapped_area(struct file *filp, unsigned long addr,
25529+ unsigned long len, unsigned long pgoff, unsigned long flags)
25530+{
25531+ struct mm_struct *mm = current->mm;
25532+ struct vm_area_struct *vma;
25533+ unsigned long pax_task_size = TASK_SIZE;
25534+ struct vm_unmapped_area_info info;
25535+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
25536+
25537+#ifdef CONFIG_PAX_SEGMEXEC
25538+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
25539+ pax_task_size = SEGMEXEC_TASK_SIZE;
25540+#endif
25541+
25542+ pax_task_size -= PAGE_SIZE;
25543+
25544+ if (len > pax_task_size)
25545+ return -ENOMEM;
25546+
25547+ if (flags & MAP_FIXED)
25548+ return addr;
25549+
25550+#ifdef CONFIG_PAX_RANDMMAP
25551+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
25552+#endif
25553+
25554+ if (addr) {
25555+ addr = PAGE_ALIGN(addr);
25556+ if (pax_task_size - len >= addr) {
25557+ vma = find_vma(mm, addr);
25558+ if (check_heap_stack_gap(vma, addr, len, offset))
25559+ return addr;
25560+ }
25561+ }
25562+
25563+ info.flags = 0;
25564+ info.length = len;
25565+ info.align_mask = filp ? get_align_mask() : 0;
25566+ info.align_offset = pgoff << PAGE_SHIFT;
25567+ info.threadstack_offset = offset;
25568+
25569+#ifdef CONFIG_PAX_PAGEEXEC
25570+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE)) {
25571+ info.low_limit = 0x00110000UL;
25572+ info.high_limit = mm->start_code;
25573+
25574+#ifdef CONFIG_PAX_RANDMMAP
25575+ if (mm->pax_flags & MF_PAX_RANDMMAP)
25576+ info.low_limit += mm->delta_mmap & 0x03FFF000UL;
25577+#endif
25578+
25579+ if (info.low_limit < info.high_limit) {
25580+ addr = vm_unmapped_area(&info);
25581+ if (!IS_ERR_VALUE(addr))
25582+ return addr;
25583+ }
25584+ } else
25585+#endif
25586+
25587+ info.low_limit = mm->mmap_base;
25588+ info.high_limit = pax_task_size;
25589+
25590+ return vm_unmapped_area(&info);
25591+}
25592+
25593+unsigned long
25594+arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
25595+ const unsigned long len, const unsigned long pgoff,
25596+ const unsigned long flags)
25597+{
25598+ struct vm_area_struct *vma;
25599+ struct mm_struct *mm = current->mm;
25600+ unsigned long addr = addr0, pax_task_size = TASK_SIZE;
25601+ struct vm_unmapped_area_info info;
25602+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
25603+
25604+#ifdef CONFIG_PAX_SEGMEXEC
25605+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
25606+ pax_task_size = SEGMEXEC_TASK_SIZE;
25607+#endif
25608+
25609+ pax_task_size -= PAGE_SIZE;
25610+
25611+ /* requested length too big for entire address space */
25612+ if (len > pax_task_size)
25613+ return -ENOMEM;
25614+
25615+ if (flags & MAP_FIXED)
25616+ return addr;
25617+
25618+#ifdef CONFIG_PAX_PAGEEXEC
25619+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
25620+ goto bottomup;
25621+#endif
25622+
25623+#ifdef CONFIG_PAX_RANDMMAP
25624+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
25625+#endif
25626+
25627+ /* requesting a specific address */
25628+ if (addr) {
25629+ addr = PAGE_ALIGN(addr);
25630+ if (pax_task_size - len >= addr) {
25631+ vma = find_vma(mm, addr);
25632+ if (check_heap_stack_gap(vma, addr, len, offset))
25633+ return addr;
25634+ }
25635+ }
25636+
25637+ info.flags = VM_UNMAPPED_AREA_TOPDOWN;
25638+ info.length = len;
25639+ info.low_limit = PAGE_SIZE;
25640+ info.high_limit = mm->mmap_base;
25641+ info.align_mask = filp ? get_align_mask() : 0;
25642+ info.align_offset = pgoff << PAGE_SHIFT;
25643+ info.threadstack_offset = offset;
25644+
25645+ addr = vm_unmapped_area(&info);
25646+ if (!(addr & ~PAGE_MASK))
25647+ return addr;
25648+ VM_BUG_ON(addr != -ENOMEM);
25649+
25650+bottomup:
25651+ /*
25652+ * A failed mmap() very likely causes application failure,
25653+ * so fall back to the bottom-up function here. This scenario
25654+ * can happen with large stack limits and large mmap()
25655+ * allocations.
25656+ */
25657+ return arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
25658+}
25659diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
25660index 30277e2..5664a29 100644
25661--- a/arch/x86/kernel/sys_x86_64.c
25662+++ b/arch/x86/kernel/sys_x86_64.c
25663@@ -81,8 +81,8 @@ out:
25664 return error;
25665 }
25666
25667-static void find_start_end(unsigned long flags, unsigned long *begin,
25668- unsigned long *end)
25669+static void find_start_end(struct mm_struct *mm, unsigned long flags,
25670+ unsigned long *begin, unsigned long *end)
25671 {
25672 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
25673 unsigned long new_begin;
25674@@ -101,7 +101,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
25675 *begin = new_begin;
25676 }
25677 } else {
25678- *begin = current->mm->mmap_legacy_base;
25679+ *begin = mm->mmap_legacy_base;
25680 *end = TASK_SIZE;
25681 }
25682 }
25683@@ -114,20 +114,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
25684 struct vm_area_struct *vma;
25685 struct vm_unmapped_area_info info;
25686 unsigned long begin, end;
25687+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
25688
25689 if (flags & MAP_FIXED)
25690 return addr;
25691
25692- find_start_end(flags, &begin, &end);
25693+ find_start_end(mm, flags, &begin, &end);
25694
25695 if (len > end)
25696 return -ENOMEM;
25697
25698+#ifdef CONFIG_PAX_RANDMMAP
25699+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
25700+#endif
25701+
25702 if (addr) {
25703 addr = PAGE_ALIGN(addr);
25704 vma = find_vma(mm, addr);
25705- if (end - len >= addr &&
25706- (!vma || addr + len <= vma->vm_start))
25707+ if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
25708 return addr;
25709 }
25710
25711@@ -137,6 +141,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
25712 info.high_limit = end;
25713 info.align_mask = filp ? get_align_mask() : 0;
25714 info.align_offset = pgoff << PAGE_SHIFT;
25715+ info.threadstack_offset = offset;
25716 return vm_unmapped_area(&info);
25717 }
25718
25719@@ -149,6 +154,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
25720 struct mm_struct *mm = current->mm;
25721 unsigned long addr = addr0;
25722 struct vm_unmapped_area_info info;
25723+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
25724
25725 /* requested length too big for entire address space */
25726 if (len > TASK_SIZE)
25727@@ -161,12 +167,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
25728 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
25729 goto bottomup;
25730
25731+#ifdef CONFIG_PAX_RANDMMAP
25732+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
25733+#endif
25734+
25735 /* requesting a specific address */
25736 if (addr) {
25737 addr = PAGE_ALIGN(addr);
25738 vma = find_vma(mm, addr);
25739- if (TASK_SIZE - len >= addr &&
25740- (!vma || addr + len <= vma->vm_start))
25741+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
25742 return addr;
25743 }
25744
25745@@ -176,6 +185,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
25746 info.high_limit = mm->mmap_base;
25747 info.align_mask = filp ? get_align_mask() : 0;
25748 info.align_offset = pgoff << PAGE_SHIFT;
25749+ info.threadstack_offset = offset;
25750 addr = vm_unmapped_area(&info);
25751 if (!(addr & ~PAGE_MASK))
25752 return addr;
25753diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
25754index 91a4496..1730bff 100644
25755--- a/arch/x86/kernel/tboot.c
25756+++ b/arch/x86/kernel/tboot.c
25757@@ -221,7 +221,7 @@ static int tboot_setup_sleep(void)
25758
25759 void tboot_shutdown(u32 shutdown_type)
25760 {
25761- void (*shutdown)(void);
25762+ void (* __noreturn shutdown)(void);
25763
25764 if (!tboot_enabled())
25765 return;
25766@@ -243,7 +243,7 @@ void tboot_shutdown(u32 shutdown_type)
25767
25768 switch_to_tboot_pt();
25769
25770- shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
25771+ shutdown = (void *)tboot->shutdown_entry;
25772 shutdown();
25773
25774 /* should not reach here */
25775@@ -310,7 +310,7 @@ static int tboot_extended_sleep(u8 sleep_state, u32 val_a, u32 val_b)
25776 return -ENODEV;
25777 }
25778
25779-static atomic_t ap_wfs_count;
25780+static atomic_unchecked_t ap_wfs_count;
25781
25782 static int tboot_wait_for_aps(int num_aps)
25783 {
25784@@ -334,9 +334,9 @@ static int tboot_cpu_callback(struct notifier_block *nfb, unsigned long action,
25785 {
25786 switch (action) {
25787 case CPU_DYING:
25788- atomic_inc(&ap_wfs_count);
25789+ atomic_inc_unchecked(&ap_wfs_count);
25790 if (num_online_cpus() == 1)
25791- if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
25792+ if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
25793 return NOTIFY_BAD;
25794 break;
25795 }
25796@@ -422,7 +422,7 @@ static __init int tboot_late_init(void)
25797
25798 tboot_create_trampoline();
25799
25800- atomic_set(&ap_wfs_count, 0);
25801+ atomic_set_unchecked(&ap_wfs_count, 0);
25802 register_hotcpu_notifier(&tboot_cpu_notifier);
25803
25804 #ifdef CONFIG_DEBUG_FS
25805diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
25806index 24d3c91..d06b473 100644
25807--- a/arch/x86/kernel/time.c
25808+++ b/arch/x86/kernel/time.c
25809@@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
25810 {
25811 unsigned long pc = instruction_pointer(regs);
25812
25813- if (!user_mode_vm(regs) && in_lock_functions(pc)) {
25814+ if (!user_mode(regs) && in_lock_functions(pc)) {
25815 #ifdef CONFIG_FRAME_POINTER
25816- return *(unsigned long *)(regs->bp + sizeof(long));
25817+ return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
25818 #else
25819 unsigned long *sp =
25820 (unsigned long *)kernel_stack_pointer(regs);
25821@@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
25822 * or above a saved flags. Eflags has bits 22-31 zero,
25823 * kernel addresses don't.
25824 */
25825+
25826+#ifdef CONFIG_PAX_KERNEXEC
25827+ return ktla_ktva(sp[0]);
25828+#else
25829 if (sp[0] >> 22)
25830 return sp[0];
25831 if (sp[1] >> 22)
25832 return sp[1];
25833 #endif
25834+
25835+#endif
25836 }
25837 return pc;
25838 }
25839diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
25840index f7fec09..9991981 100644
25841--- a/arch/x86/kernel/tls.c
25842+++ b/arch/x86/kernel/tls.c
25843@@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
25844 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
25845 return -EINVAL;
25846
25847+#ifdef CONFIG_PAX_SEGMEXEC
25848+ if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
25849+ return -EINVAL;
25850+#endif
25851+
25852 set_tls_desc(p, idx, &info, 1);
25853
25854 return 0;
25855@@ -200,7 +205,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
25856
25857 if (kbuf)
25858 info = kbuf;
25859- else if (__copy_from_user(infobuf, ubuf, count))
25860+ else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
25861 return -EFAULT;
25862 else
25863 info = infobuf;
25864diff --git a/arch/x86/kernel/tracepoint.c b/arch/x86/kernel/tracepoint.c
25865index 1c113db..287b42e 100644
25866--- a/arch/x86/kernel/tracepoint.c
25867+++ b/arch/x86/kernel/tracepoint.c
25868@@ -9,11 +9,11 @@
25869 #include <linux/atomic.h>
25870
25871 atomic_t trace_idt_ctr = ATOMIC_INIT(0);
25872-struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
25873+const struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
25874 (unsigned long) trace_idt_table };
25875
25876 /* No need to be aligned, but done to keep all IDTs defined the same way. */
25877-gate_desc trace_idt_table[NR_VECTORS] __page_aligned_bss;
25878+gate_desc trace_idt_table[NR_VECTORS] __page_aligned_rodata;
25879
25880 static int trace_irq_vector_refcount;
25881 static DEFINE_MUTEX(irq_vector_mutex);
25882diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
25883index 8c8093b..c93f581 100644
25884--- a/arch/x86/kernel/traps.c
25885+++ b/arch/x86/kernel/traps.c
25886@@ -66,7 +66,7 @@
25887 #include <asm/proto.h>
25888
25889 /* No need to be aligned, but done to keep all IDTs defined the same way. */
25890-gate_desc debug_idt_table[NR_VECTORS] __page_aligned_bss;
25891+gate_desc debug_idt_table[NR_VECTORS] __page_aligned_rodata;
25892 #else
25893 #include <asm/processor-flags.h>
25894 #include <asm/setup.h>
25895@@ -75,7 +75,7 @@ asmlinkage int system_call(void);
25896 #endif
25897
25898 /* Must be page-aligned because the real IDT is used in a fixmap. */
25899-gate_desc idt_table[NR_VECTORS] __page_aligned_bss;
25900+gate_desc idt_table[NR_VECTORS] __page_aligned_rodata;
25901
25902 DECLARE_BITMAP(used_vectors, NR_VECTORS);
25903 EXPORT_SYMBOL_GPL(used_vectors);
25904@@ -107,11 +107,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
25905 }
25906
25907 static int __kprobes
25908-do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
25909+do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
25910 struct pt_regs *regs, long error_code)
25911 {
25912 #ifdef CONFIG_X86_32
25913- if (regs->flags & X86_VM_MASK) {
25914+ if (v8086_mode(regs)) {
25915 /*
25916 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
25917 * On nmi (interrupt 2), do_trap should not be called.
25918@@ -124,12 +124,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
25919 return -1;
25920 }
25921 #endif
25922- if (!user_mode(regs)) {
25923+ if (!user_mode_novm(regs)) {
25924 if (!fixup_exception(regs)) {
25925 tsk->thread.error_code = error_code;
25926 tsk->thread.trap_nr = trapnr;
25927+
25928+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
25929+ if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
25930+ str = "PAX: suspicious stack segment fault";
25931+#endif
25932+
25933 die(str, regs, error_code);
25934 }
25935+
25936+#ifdef CONFIG_PAX_REFCOUNT
25937+ if (trapnr == 4)
25938+ pax_report_refcount_overflow(regs);
25939+#endif
25940+
25941 return 0;
25942 }
25943
25944@@ -137,7 +149,7 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
25945 }
25946
25947 static void __kprobes
25948-do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
25949+do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
25950 long error_code, siginfo_t *info)
25951 {
25952 struct task_struct *tsk = current;
25953@@ -161,7 +173,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
25954 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
25955 printk_ratelimit()) {
25956 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
25957- tsk->comm, tsk->pid, str,
25958+ tsk->comm, task_pid_nr(tsk), str,
25959 regs->ip, regs->sp, error_code);
25960 print_vma_addr(" in ", regs->ip);
25961 pr_cont("\n");
25962@@ -277,7 +289,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
25963 conditional_sti(regs);
25964
25965 #ifdef CONFIG_X86_32
25966- if (regs->flags & X86_VM_MASK) {
25967+ if (v8086_mode(regs)) {
25968 local_irq_enable();
25969 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
25970 goto exit;
25971@@ -285,18 +297,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
25972 #endif
25973
25974 tsk = current;
25975- if (!user_mode(regs)) {
25976+ if (!user_mode_novm(regs)) {
25977 if (fixup_exception(regs))
25978 goto exit;
25979
25980 tsk->thread.error_code = error_code;
25981 tsk->thread.trap_nr = X86_TRAP_GP;
25982 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
25983- X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
25984+ X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
25985+
25986+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
25987+ if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
25988+ die("PAX: suspicious general protection fault", regs, error_code);
25989+ else
25990+#endif
25991+
25992 die("general protection fault", regs, error_code);
25993+ }
25994 goto exit;
25995 }
25996
25997+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
25998+ if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
25999+ struct mm_struct *mm = tsk->mm;
26000+ unsigned long limit;
26001+
26002+ down_write(&mm->mmap_sem);
26003+ limit = mm->context.user_cs_limit;
26004+ if (limit < TASK_SIZE) {
26005+ track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
26006+ up_write(&mm->mmap_sem);
26007+ return;
26008+ }
26009+ up_write(&mm->mmap_sem);
26010+ }
26011+#endif
26012+
26013 tsk->thread.error_code = error_code;
26014 tsk->thread.trap_nr = X86_TRAP_GP;
26015
26016@@ -457,7 +493,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
26017 /* It's safe to allow irq's after DR6 has been saved */
26018 preempt_conditional_sti(regs);
26019
26020- if (regs->flags & X86_VM_MASK) {
26021+ if (v8086_mode(regs)) {
26022 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
26023 X86_TRAP_DB);
26024 preempt_conditional_cli(regs);
26025@@ -472,7 +508,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
26026 * We already checked v86 mode above, so we can check for kernel mode
26027 * by just checking the CPL of CS.
26028 */
26029- if ((dr6 & DR_STEP) && !user_mode(regs)) {
26030+ if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
26031 tsk->thread.debugreg6 &= ~DR_STEP;
26032 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
26033 regs->flags &= ~X86_EFLAGS_TF;
26034@@ -504,7 +540,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
26035 return;
26036 conditional_sti(regs);
26037
26038- if (!user_mode_vm(regs))
26039+ if (!user_mode(regs))
26040 {
26041 if (!fixup_exception(regs)) {
26042 task->thread.error_code = error_code;
26043diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
26044index 2ed8459..7cf329f 100644
26045--- a/arch/x86/kernel/uprobes.c
26046+++ b/arch/x86/kernel/uprobes.c
26047@@ -629,7 +629,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
26048 int ret = NOTIFY_DONE;
26049
26050 /* We are only interested in userspace traps */
26051- if (regs && !user_mode_vm(regs))
26052+ if (regs && !user_mode(regs))
26053 return NOTIFY_DONE;
26054
26055 switch (val) {
26056@@ -719,7 +719,7 @@ arch_uretprobe_hijack_return_addr(unsigned long trampoline_vaddr, struct pt_regs
26057
26058 if (ncopied != rasize) {
26059 pr_err("uprobe: return address clobbered: pid=%d, %%sp=%#lx, "
26060- "%%ip=%#lx\n", current->pid, regs->sp, regs->ip);
26061+ "%%ip=%#lx\n", task_pid_nr(current), regs->sp, regs->ip);
26062
26063 force_sig_info(SIGSEGV, SEND_SIG_FORCED, current);
26064 }
26065diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
26066index b9242ba..50c5edd 100644
26067--- a/arch/x86/kernel/verify_cpu.S
26068+++ b/arch/x86/kernel/verify_cpu.S
26069@@ -20,6 +20,7 @@
26070 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
26071 * arch/x86/kernel/trampoline_64.S: secondary processor verification
26072 * arch/x86/kernel/head_32.S: processor startup
26073+ * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
26074 *
26075 * verify_cpu, returns the status of longmode and SSE in register %eax.
26076 * 0: Success 1: Failure
26077diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
26078index e8edcf5..27f9344 100644
26079--- a/arch/x86/kernel/vm86_32.c
26080+++ b/arch/x86/kernel/vm86_32.c
26081@@ -44,6 +44,7 @@
26082 #include <linux/ptrace.h>
26083 #include <linux/audit.h>
26084 #include <linux/stddef.h>
26085+#include <linux/grsecurity.h>
26086
26087 #include <asm/uaccess.h>
26088 #include <asm/io.h>
26089@@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
26090 do_exit(SIGSEGV);
26091 }
26092
26093- tss = &per_cpu(init_tss, get_cpu());
26094+ tss = init_tss + get_cpu();
26095 current->thread.sp0 = current->thread.saved_sp0;
26096 current->thread.sysenter_cs = __KERNEL_CS;
26097 load_sp0(tss, &current->thread);
26098@@ -214,6 +215,14 @@ SYSCALL_DEFINE1(vm86old, struct vm86_struct __user *, v86)
26099
26100 if (tsk->thread.saved_sp0)
26101 return -EPERM;
26102+
26103+#ifdef CONFIG_GRKERNSEC_VM86
26104+ if (!capable(CAP_SYS_RAWIO)) {
26105+ gr_handle_vm86();
26106+ return -EPERM;
26107+ }
26108+#endif
26109+
26110 tmp = copy_vm86_regs_from_user(&info.regs, &v86->regs,
26111 offsetof(struct kernel_vm86_struct, vm86plus) -
26112 sizeof(info.regs));
26113@@ -238,6 +247,13 @@ SYSCALL_DEFINE2(vm86, unsigned long, cmd, unsigned long, arg)
26114 int tmp;
26115 struct vm86plus_struct __user *v86;
26116
26117+#ifdef CONFIG_GRKERNSEC_VM86
26118+ if (!capable(CAP_SYS_RAWIO)) {
26119+ gr_handle_vm86();
26120+ return -EPERM;
26121+ }
26122+#endif
26123+
26124 tsk = current;
26125 switch (cmd) {
26126 case VM86_REQUEST_IRQ:
26127@@ -318,7 +334,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
26128 tsk->thread.saved_fs = info->regs32->fs;
26129 tsk->thread.saved_gs = get_user_gs(info->regs32);
26130
26131- tss = &per_cpu(init_tss, get_cpu());
26132+ tss = init_tss + get_cpu();
26133 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
26134 if (cpu_has_sep)
26135 tsk->thread.sysenter_cs = 0;
26136@@ -525,7 +541,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
26137 goto cannot_handle;
26138 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
26139 goto cannot_handle;
26140- intr_ptr = (unsigned long __user *) (i << 2);
26141+ intr_ptr = (__force unsigned long __user *) (i << 2);
26142 if (get_user(segoffs, intr_ptr))
26143 goto cannot_handle;
26144 if ((segoffs >> 16) == BIOSSEG)
26145diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
26146index 10c4f30..65408b9 100644
26147--- a/arch/x86/kernel/vmlinux.lds.S
26148+++ b/arch/x86/kernel/vmlinux.lds.S
26149@@ -26,6 +26,13 @@
26150 #include <asm/page_types.h>
26151 #include <asm/cache.h>
26152 #include <asm/boot.h>
26153+#include <asm/segment.h>
26154+
26155+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26156+#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
26157+#else
26158+#define __KERNEL_TEXT_OFFSET 0
26159+#endif
26160
26161 #undef i386 /* in case the preprocessor is a 32bit one */
26162
26163@@ -69,30 +76,43 @@ jiffies_64 = jiffies;
26164
26165 PHDRS {
26166 text PT_LOAD FLAGS(5); /* R_E */
26167+#ifdef CONFIG_X86_32
26168+ module PT_LOAD FLAGS(5); /* R_E */
26169+#endif
26170+#ifdef CONFIG_XEN
26171+ rodata PT_LOAD FLAGS(5); /* R_E */
26172+#else
26173+ rodata PT_LOAD FLAGS(4); /* R__ */
26174+#endif
26175 data PT_LOAD FLAGS(6); /* RW_ */
26176-#ifdef CONFIG_X86_64
26177+ init.begin PT_LOAD FLAGS(6); /* RW_ */
26178 #ifdef CONFIG_SMP
26179 percpu PT_LOAD FLAGS(6); /* RW_ */
26180 #endif
26181+ text.init PT_LOAD FLAGS(5); /* R_E */
26182+ text.exit PT_LOAD FLAGS(5); /* R_E */
26183 init PT_LOAD FLAGS(7); /* RWE */
26184-#endif
26185 note PT_NOTE FLAGS(0); /* ___ */
26186 }
26187
26188 SECTIONS
26189 {
26190 #ifdef CONFIG_X86_32
26191- . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
26192- phys_startup_32 = startup_32 - LOAD_OFFSET;
26193+ . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
26194 #else
26195- . = __START_KERNEL;
26196- phys_startup_64 = startup_64 - LOAD_OFFSET;
26197+ . = __START_KERNEL;
26198 #endif
26199
26200 /* Text and read-only data */
26201- .text : AT(ADDR(.text) - LOAD_OFFSET) {
26202- _text = .;
26203+ .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
26204 /* bootstrapping code */
26205+#ifdef CONFIG_X86_32
26206+ phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
26207+#else
26208+ phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
26209+#endif
26210+ __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
26211+ _text = .;
26212 HEAD_TEXT
26213 . = ALIGN(8);
26214 _stext = .;
26215@@ -104,13 +124,47 @@ SECTIONS
26216 IRQENTRY_TEXT
26217 *(.fixup)
26218 *(.gnu.warning)
26219- /* End of text section */
26220- _etext = .;
26221 } :text = 0x9090
26222
26223- NOTES :text :note
26224+ . += __KERNEL_TEXT_OFFSET;
26225
26226- EXCEPTION_TABLE(16) :text = 0x9090
26227+#ifdef CONFIG_X86_32
26228+ . = ALIGN(PAGE_SIZE);
26229+ .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
26230+
26231+#ifdef CONFIG_PAX_KERNEXEC
26232+ MODULES_EXEC_VADDR = .;
26233+ BYTE(0)
26234+ . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
26235+ . = ALIGN(HPAGE_SIZE) - 1;
26236+ MODULES_EXEC_END = .;
26237+#endif
26238+
26239+ } :module
26240+#endif
26241+
26242+ .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
26243+ /* End of text section */
26244+ BYTE(0)
26245+ _etext = . - __KERNEL_TEXT_OFFSET;
26246+ }
26247+
26248+#ifdef CONFIG_X86_32
26249+ . = ALIGN(PAGE_SIZE);
26250+ .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
26251+ . = ALIGN(PAGE_SIZE);
26252+ *(.empty_zero_page)
26253+ *(.initial_pg_fixmap)
26254+ *(.initial_pg_pmd)
26255+ *(.initial_page_table)
26256+ *(.swapper_pg_dir)
26257+ } :rodata
26258+#endif
26259+
26260+ . = ALIGN(PAGE_SIZE);
26261+ NOTES :rodata :note
26262+
26263+ EXCEPTION_TABLE(16) :rodata
26264
26265 #if defined(CONFIG_DEBUG_RODATA)
26266 /* .text should occupy whole number of pages */
26267@@ -122,16 +176,20 @@ SECTIONS
26268
26269 /* Data */
26270 .data : AT(ADDR(.data) - LOAD_OFFSET) {
26271+
26272+#ifdef CONFIG_PAX_KERNEXEC
26273+ . = ALIGN(HPAGE_SIZE);
26274+#else
26275+ . = ALIGN(PAGE_SIZE);
26276+#endif
26277+
26278 /* Start of data section */
26279 _sdata = .;
26280
26281 /* init_task */
26282 INIT_TASK_DATA(THREAD_SIZE)
26283
26284-#ifdef CONFIG_X86_32
26285- /* 32 bit has nosave before _edata */
26286 NOSAVE_DATA
26287-#endif
26288
26289 PAGE_ALIGNED_DATA(PAGE_SIZE)
26290
26291@@ -172,12 +230,19 @@ SECTIONS
26292 #endif /* CONFIG_X86_64 */
26293
26294 /* Init code and data - will be freed after init */
26295- . = ALIGN(PAGE_SIZE);
26296 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
26297+ BYTE(0)
26298+
26299+#ifdef CONFIG_PAX_KERNEXEC
26300+ . = ALIGN(HPAGE_SIZE);
26301+#else
26302+ . = ALIGN(PAGE_SIZE);
26303+#endif
26304+
26305 __init_begin = .; /* paired with __init_end */
26306- }
26307+ } :init.begin
26308
26309-#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
26310+#ifdef CONFIG_SMP
26311 /*
26312 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
26313 * output PHDR, so the next output section - .init.text - should
26314@@ -186,12 +251,27 @@ SECTIONS
26315 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
26316 #endif
26317
26318- INIT_TEXT_SECTION(PAGE_SIZE)
26319-#ifdef CONFIG_X86_64
26320- :init
26321-#endif
26322+ . = ALIGN(PAGE_SIZE);
26323+ init_begin = .;
26324+ .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
26325+ VMLINUX_SYMBOL(_sinittext) = .;
26326+ INIT_TEXT
26327+ VMLINUX_SYMBOL(_einittext) = .;
26328+ . = ALIGN(PAGE_SIZE);
26329+ } :text.init
26330
26331- INIT_DATA_SECTION(16)
26332+ /*
26333+ * .exit.text is discard at runtime, not link time, to deal with
26334+ * references from .altinstructions and .eh_frame
26335+ */
26336+ .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
26337+ EXIT_TEXT
26338+ . = ALIGN(16);
26339+ } :text.exit
26340+ . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
26341+
26342+ . = ALIGN(PAGE_SIZE);
26343+ INIT_DATA_SECTION(16) :init
26344
26345 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
26346 __x86_cpu_dev_start = .;
26347@@ -253,19 +333,12 @@ SECTIONS
26348 }
26349
26350 . = ALIGN(8);
26351- /*
26352- * .exit.text is discard at runtime, not link time, to deal with
26353- * references from .altinstructions and .eh_frame
26354- */
26355- .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
26356- EXIT_TEXT
26357- }
26358
26359 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
26360 EXIT_DATA
26361 }
26362
26363-#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
26364+#ifndef CONFIG_SMP
26365 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
26366 #endif
26367
26368@@ -284,16 +357,10 @@ SECTIONS
26369 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
26370 __smp_locks = .;
26371 *(.smp_locks)
26372- . = ALIGN(PAGE_SIZE);
26373 __smp_locks_end = .;
26374+ . = ALIGN(PAGE_SIZE);
26375 }
26376
26377-#ifdef CONFIG_X86_64
26378- .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
26379- NOSAVE_DATA
26380- }
26381-#endif
26382-
26383 /* BSS */
26384 . = ALIGN(PAGE_SIZE);
26385 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
26386@@ -309,6 +376,7 @@ SECTIONS
26387 __brk_base = .;
26388 . += 64 * 1024; /* 64k alignment slop space */
26389 *(.brk_reservation) /* areas brk users have reserved */
26390+ . = ALIGN(HPAGE_SIZE);
26391 __brk_limit = .;
26392 }
26393
26394@@ -335,13 +403,12 @@ SECTIONS
26395 * for the boot processor.
26396 */
26397 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
26398-INIT_PER_CPU(gdt_page);
26399 INIT_PER_CPU(irq_stack_union);
26400
26401 /*
26402 * Build-time check on the image size:
26403 */
26404-. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
26405+. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
26406 "kernel image bigger than KERNEL_IMAGE_SIZE");
26407
26408 #ifdef CONFIG_SMP
26409diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
26410index 1f96f93..d5c8f7a 100644
26411--- a/arch/x86/kernel/vsyscall_64.c
26412+++ b/arch/x86/kernel/vsyscall_64.c
26413@@ -56,15 +56,13 @@
26414 DEFINE_VVAR(int, vgetcpu_mode);
26415 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
26416
26417-static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
26418+static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
26419
26420 static int __init vsyscall_setup(char *str)
26421 {
26422 if (str) {
26423 if (!strcmp("emulate", str))
26424 vsyscall_mode = EMULATE;
26425- else if (!strcmp("native", str))
26426- vsyscall_mode = NATIVE;
26427 else if (!strcmp("none", str))
26428 vsyscall_mode = NONE;
26429 else
26430@@ -323,8 +321,7 @@ do_ret:
26431 return true;
26432
26433 sigsegv:
26434- force_sig(SIGSEGV, current);
26435- return true;
26436+ do_group_exit(SIGKILL);
26437 }
26438
26439 /*
26440@@ -377,10 +374,7 @@ void __init map_vsyscall(void)
26441 extern char __vvar_page;
26442 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
26443
26444- __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
26445- vsyscall_mode == NATIVE
26446- ? PAGE_KERNEL_VSYSCALL
26447- : PAGE_KERNEL_VVAR);
26448+ __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
26449 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
26450 (unsigned long)VSYSCALL_START);
26451
26452diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
26453index b014d94..e775258 100644
26454--- a/arch/x86/kernel/x8664_ksyms_64.c
26455+++ b/arch/x86/kernel/x8664_ksyms_64.c
26456@@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
26457 EXPORT_SYMBOL(copy_user_generic_unrolled);
26458 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
26459 EXPORT_SYMBOL(__copy_user_nocache);
26460-EXPORT_SYMBOL(_copy_from_user);
26461-EXPORT_SYMBOL(_copy_to_user);
26462
26463 EXPORT_SYMBOL(copy_page);
26464 EXPORT_SYMBOL(clear_page);
26465@@ -66,3 +64,7 @@ EXPORT_SYMBOL(empty_zero_page);
26466 #ifndef CONFIG_PARAVIRT
26467 EXPORT_SYMBOL(native_load_gs_index);
26468 #endif
26469+
26470+#ifdef CONFIG_PAX_PER_CPU_PGD
26471+EXPORT_SYMBOL(cpu_pgd);
26472+#endif
26473diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
26474index 8ce0072..431a0e7 100644
26475--- a/arch/x86/kernel/x86_init.c
26476+++ b/arch/x86/kernel/x86_init.c
26477@@ -93,7 +93,7 @@ struct x86_cpuinit_ops x86_cpuinit = {
26478 static void default_nmi_init(void) { };
26479 static int default_i8042_detect(void) { return 1; };
26480
26481-struct x86_platform_ops x86_platform = {
26482+struct x86_platform_ops x86_platform __read_only = {
26483 .calibrate_tsc = native_calibrate_tsc,
26484 .get_wallclock = mach_get_cmos_time,
26485 .set_wallclock = mach_set_rtc_mmss,
26486@@ -109,7 +109,7 @@ struct x86_platform_ops x86_platform = {
26487 EXPORT_SYMBOL_GPL(x86_platform);
26488
26489 #if defined(CONFIG_PCI_MSI)
26490-struct x86_msi_ops x86_msi = {
26491+struct x86_msi_ops x86_msi __read_only = {
26492 .setup_msi_irqs = native_setup_msi_irqs,
26493 .compose_msi_msg = native_compose_msi_msg,
26494 .teardown_msi_irq = native_teardown_msi_irq,
26495@@ -140,7 +140,7 @@ void arch_restore_msi_irqs(struct pci_dev *dev, int irq)
26496 }
26497 #endif
26498
26499-struct x86_io_apic_ops x86_io_apic_ops = {
26500+struct x86_io_apic_ops x86_io_apic_ops __read_only = {
26501 .init = native_io_apic_init_mappings,
26502 .read = native_io_apic_read,
26503 .write = native_io_apic_write,
26504diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
26505index 422fd82..c3687ca 100644
26506--- a/arch/x86/kernel/xsave.c
26507+++ b/arch/x86/kernel/xsave.c
26508@@ -199,6 +199,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
26509 {
26510 int err;
26511
26512+ buf = (struct xsave_struct __user *)____m(buf);
26513 if (use_xsave())
26514 err = xsave_user(buf);
26515 else if (use_fxsr())
26516@@ -311,6 +312,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
26517 */
26518 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
26519 {
26520+ buf = (void __user *)____m(buf);
26521 if (use_xsave()) {
26522 if ((unsigned long)buf % 64 || fx_only) {
26523 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
26524diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
26525index b110fe6..d9c19f2 100644
26526--- a/arch/x86/kvm/cpuid.c
26527+++ b/arch/x86/kvm/cpuid.c
26528@@ -124,15 +124,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
26529 struct kvm_cpuid2 *cpuid,
26530 struct kvm_cpuid_entry2 __user *entries)
26531 {
26532- int r;
26533+ int r, i;
26534
26535 r = -E2BIG;
26536 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
26537 goto out;
26538 r = -EFAULT;
26539- if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
26540- cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
26541+ if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
26542 goto out;
26543+ for (i = 0; i < cpuid->nent; ++i) {
26544+ struct kvm_cpuid_entry2 cpuid_entry;
26545+ if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
26546+ goto out;
26547+ vcpu->arch.cpuid_entries[i] = cpuid_entry;
26548+ }
26549 vcpu->arch.cpuid_nent = cpuid->nent;
26550 kvm_apic_set_version(vcpu);
26551 kvm_x86_ops->cpuid_update(vcpu);
26552@@ -147,15 +152,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
26553 struct kvm_cpuid2 *cpuid,
26554 struct kvm_cpuid_entry2 __user *entries)
26555 {
26556- int r;
26557+ int r, i;
26558
26559 r = -E2BIG;
26560 if (cpuid->nent < vcpu->arch.cpuid_nent)
26561 goto out;
26562 r = -EFAULT;
26563- if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
26564- vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
26565+ if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
26566 goto out;
26567+ for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
26568+ struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
26569+ if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
26570+ goto out;
26571+ }
26572 return 0;
26573
26574 out:
26575diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
26576index 5439117..d08f3d4 100644
26577--- a/arch/x86/kvm/lapic.c
26578+++ b/arch/x86/kvm/lapic.c
26579@@ -55,7 +55,7 @@
26580 #define APIC_BUS_CYCLE_NS 1
26581
26582 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
26583-#define apic_debug(fmt, arg...)
26584+#define apic_debug(fmt, arg...) do {} while (0)
26585
26586 #define APIC_LVT_NUM 6
26587 /* 14 is the version for Xeon and Pentium 8.4.8*/
26588diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
26589index ad75d77..a679d32 100644
26590--- a/arch/x86/kvm/paging_tmpl.h
26591+++ b/arch/x86/kvm/paging_tmpl.h
26592@@ -331,7 +331,7 @@ retry_walk:
26593 if (unlikely(kvm_is_error_hva(host_addr)))
26594 goto error;
26595
26596- ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
26597+ ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
26598 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
26599 goto error;
26600 walker->ptep_user[walker->level - 1] = ptep_user;
26601diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
26602index c0bc803..6837a50 100644
26603--- a/arch/x86/kvm/svm.c
26604+++ b/arch/x86/kvm/svm.c
26605@@ -3501,7 +3501,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
26606 int cpu = raw_smp_processor_id();
26607
26608 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
26609+
26610+ pax_open_kernel();
26611 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
26612+ pax_close_kernel();
26613+
26614 load_TR_desc();
26615 }
26616
26617@@ -3902,6 +3906,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
26618 #endif
26619 #endif
26620
26621+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
26622+ __set_fs(current_thread_info()->addr_limit);
26623+#endif
26624+
26625 reload_tss(vcpu);
26626
26627 local_irq_disable();
26628diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
26629index 2b2fce1..da76be4 100644
26630--- a/arch/x86/kvm/vmx.c
26631+++ b/arch/x86/kvm/vmx.c
26632@@ -1316,12 +1316,12 @@ static void vmcs_write64(unsigned long field, u64 value)
26633 #endif
26634 }
26635
26636-static void vmcs_clear_bits(unsigned long field, u32 mask)
26637+static void vmcs_clear_bits(unsigned long field, unsigned long mask)
26638 {
26639 vmcs_writel(field, vmcs_readl(field) & ~mask);
26640 }
26641
26642-static void vmcs_set_bits(unsigned long field, u32 mask)
26643+static void vmcs_set_bits(unsigned long field, unsigned long mask)
26644 {
26645 vmcs_writel(field, vmcs_readl(field) | mask);
26646 }
26647@@ -1522,7 +1522,11 @@ static void reload_tss(void)
26648 struct desc_struct *descs;
26649
26650 descs = (void *)gdt->address;
26651+
26652+ pax_open_kernel();
26653 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
26654+ pax_close_kernel();
26655+
26656 load_TR_desc();
26657 }
26658
26659@@ -1746,6 +1750,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
26660 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
26661 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
26662
26663+#ifdef CONFIG_PAX_PER_CPU_PGD
26664+ vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
26665+#endif
26666+
26667 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
26668 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
26669 vmx->loaded_vmcs->cpu = cpu;
26670@@ -2037,7 +2045,7 @@ static void setup_msrs(struct vcpu_vmx *vmx)
26671 * reads and returns guest's timestamp counter "register"
26672 * guest_tsc = host_tsc + tsc_offset -- 21.3
26673 */
26674-static u64 guest_read_tsc(void)
26675+static u64 __intentional_overflow(-1) guest_read_tsc(void)
26676 {
26677 u64 host_tsc, tsc_offset;
26678
26679@@ -2982,8 +2990,11 @@ static __init int hardware_setup(void)
26680 if (!cpu_has_vmx_flexpriority())
26681 flexpriority_enabled = 0;
26682
26683- if (!cpu_has_vmx_tpr_shadow())
26684- kvm_x86_ops->update_cr8_intercept = NULL;
26685+ if (!cpu_has_vmx_tpr_shadow()) {
26686+ pax_open_kernel();
26687+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
26688+ pax_close_kernel();
26689+ }
26690
26691 if (enable_ept && !cpu_has_vmx_ept_2m_page())
26692 kvm_disable_largepages();
26693@@ -2994,13 +3005,15 @@ static __init int hardware_setup(void)
26694 if (!cpu_has_vmx_apicv())
26695 enable_apicv = 0;
26696
26697+ pax_open_kernel();
26698 if (enable_apicv)
26699- kvm_x86_ops->update_cr8_intercept = NULL;
26700+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
26701 else {
26702- kvm_x86_ops->hwapic_irr_update = NULL;
26703- kvm_x86_ops->deliver_posted_interrupt = NULL;
26704- kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
26705+ *(void **)&kvm_x86_ops->hwapic_irr_update = NULL;
26706+ *(void **)&kvm_x86_ops->deliver_posted_interrupt = NULL;
26707+ *(void **)&kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
26708 }
26709+ pax_close_kernel();
26710
26711 if (nested)
26712 nested_vmx_setup_ctls_msrs();
26713@@ -4127,7 +4140,10 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
26714
26715 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
26716 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
26717+
26718+#ifndef CONFIG_PAX_PER_CPU_PGD
26719 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
26720+#endif
26721
26722 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
26723 #ifdef CONFIG_X86_64
26724@@ -4149,7 +4165,7 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
26725 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
26726 vmx->host_idt_base = dt.address;
26727
26728- vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
26729+ vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
26730
26731 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
26732 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
26733@@ -7191,6 +7207,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
26734 "jmp 2f \n\t"
26735 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
26736 "2: "
26737+
26738+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26739+ "ljmp %[cs],$3f\n\t"
26740+ "3: "
26741+#endif
26742+
26743 /* Save guest registers, load host registers, keep flags */
26744 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
26745 "pop %0 \n\t"
26746@@ -7243,6 +7265,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
26747 #endif
26748 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
26749 [wordsize]"i"(sizeof(ulong))
26750+
26751+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26752+ ,[cs]"i"(__KERNEL_CS)
26753+#endif
26754+
26755 : "cc", "memory"
26756 #ifdef CONFIG_X86_64
26757 , "rax", "rbx", "rdi", "rsi"
26758@@ -7256,7 +7283,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
26759 if (debugctlmsr)
26760 update_debugctlmsr(debugctlmsr);
26761
26762-#ifndef CONFIG_X86_64
26763+#ifdef CONFIG_X86_32
26764 /*
26765 * The sysexit path does not restore ds/es, so we must set them to
26766 * a reasonable value ourselves.
26767@@ -7265,8 +7292,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
26768 * may be executed in interrupt context, which saves and restore segments
26769 * around it, nullifying its effect.
26770 */
26771- loadsegment(ds, __USER_DS);
26772- loadsegment(es, __USER_DS);
26773+ loadsegment(ds, __KERNEL_DS);
26774+ loadsegment(es, __KERNEL_DS);
26775+ loadsegment(ss, __KERNEL_DS);
26776+
26777+#ifdef CONFIG_PAX_KERNEXEC
26778+ loadsegment(fs, __KERNEL_PERCPU);
26779+#endif
26780+
26781+#ifdef CONFIG_PAX_MEMORY_UDEREF
26782+ __set_fs(current_thread_info()->addr_limit);
26783+#endif
26784+
26785 #endif
26786
26787 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
26788diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
26789index e5ca72a..83d5177 100644
26790--- a/arch/x86/kvm/x86.c
26791+++ b/arch/x86/kvm/x86.c
26792@@ -1779,8 +1779,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
26793 {
26794 struct kvm *kvm = vcpu->kvm;
26795 int lm = is_long_mode(vcpu);
26796- u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
26797- : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
26798+ u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
26799+ : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
26800 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
26801 : kvm->arch.xen_hvm_config.blob_size_32;
26802 u32 page_num = data & ~PAGE_MASK;
26803@@ -2663,6 +2663,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
26804 if (n < msr_list.nmsrs)
26805 goto out;
26806 r = -EFAULT;
26807+ if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
26808+ goto out;
26809 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
26810 num_msrs_to_save * sizeof(u32)))
26811 goto out;
26812@@ -5462,7 +5464,7 @@ static struct notifier_block pvclock_gtod_notifier = {
26813 };
26814 #endif
26815
26816-int kvm_arch_init(void *opaque)
26817+int kvm_arch_init(const void *opaque)
26818 {
26819 int r;
26820 struct kvm_x86_ops *ops = opaque;
26821diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
26822index bdf8532..f63c587 100644
26823--- a/arch/x86/lguest/boot.c
26824+++ b/arch/x86/lguest/boot.c
26825@@ -1206,9 +1206,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
26826 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
26827 * Launcher to reboot us.
26828 */
26829-static void lguest_restart(char *reason)
26830+static __noreturn void lguest_restart(char *reason)
26831 {
26832 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
26833+ BUG();
26834 }
26835
26836 /*G:050
26837diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
26838index 00933d5..3a64af9 100644
26839--- a/arch/x86/lib/atomic64_386_32.S
26840+++ b/arch/x86/lib/atomic64_386_32.S
26841@@ -48,6 +48,10 @@ BEGIN(read)
26842 movl (v), %eax
26843 movl 4(v), %edx
26844 RET_ENDP
26845+BEGIN(read_unchecked)
26846+ movl (v), %eax
26847+ movl 4(v), %edx
26848+RET_ENDP
26849 #undef v
26850
26851 #define v %esi
26852@@ -55,6 +59,10 @@ BEGIN(set)
26853 movl %ebx, (v)
26854 movl %ecx, 4(v)
26855 RET_ENDP
26856+BEGIN(set_unchecked)
26857+ movl %ebx, (v)
26858+ movl %ecx, 4(v)
26859+RET_ENDP
26860 #undef v
26861
26862 #define v %esi
26863@@ -70,6 +78,20 @@ RET_ENDP
26864 BEGIN(add)
26865 addl %eax, (v)
26866 adcl %edx, 4(v)
26867+
26868+#ifdef CONFIG_PAX_REFCOUNT
26869+ jno 0f
26870+ subl %eax, (v)
26871+ sbbl %edx, 4(v)
26872+ int $4
26873+0:
26874+ _ASM_EXTABLE(0b, 0b)
26875+#endif
26876+
26877+RET_ENDP
26878+BEGIN(add_unchecked)
26879+ addl %eax, (v)
26880+ adcl %edx, 4(v)
26881 RET_ENDP
26882 #undef v
26883
26884@@ -77,6 +99,24 @@ RET_ENDP
26885 BEGIN(add_return)
26886 addl (v), %eax
26887 adcl 4(v), %edx
26888+
26889+#ifdef CONFIG_PAX_REFCOUNT
26890+ into
26891+1234:
26892+ _ASM_EXTABLE(1234b, 2f)
26893+#endif
26894+
26895+ movl %eax, (v)
26896+ movl %edx, 4(v)
26897+
26898+#ifdef CONFIG_PAX_REFCOUNT
26899+2:
26900+#endif
26901+
26902+RET_ENDP
26903+BEGIN(add_return_unchecked)
26904+ addl (v), %eax
26905+ adcl 4(v), %edx
26906 movl %eax, (v)
26907 movl %edx, 4(v)
26908 RET_ENDP
26909@@ -86,6 +126,20 @@ RET_ENDP
26910 BEGIN(sub)
26911 subl %eax, (v)
26912 sbbl %edx, 4(v)
26913+
26914+#ifdef CONFIG_PAX_REFCOUNT
26915+ jno 0f
26916+ addl %eax, (v)
26917+ adcl %edx, 4(v)
26918+ int $4
26919+0:
26920+ _ASM_EXTABLE(0b, 0b)
26921+#endif
26922+
26923+RET_ENDP
26924+BEGIN(sub_unchecked)
26925+ subl %eax, (v)
26926+ sbbl %edx, 4(v)
26927 RET_ENDP
26928 #undef v
26929
26930@@ -96,6 +150,27 @@ BEGIN(sub_return)
26931 sbbl $0, %edx
26932 addl (v), %eax
26933 adcl 4(v), %edx
26934+
26935+#ifdef CONFIG_PAX_REFCOUNT
26936+ into
26937+1234:
26938+ _ASM_EXTABLE(1234b, 2f)
26939+#endif
26940+
26941+ movl %eax, (v)
26942+ movl %edx, 4(v)
26943+
26944+#ifdef CONFIG_PAX_REFCOUNT
26945+2:
26946+#endif
26947+
26948+RET_ENDP
26949+BEGIN(sub_return_unchecked)
26950+ negl %edx
26951+ negl %eax
26952+ sbbl $0, %edx
26953+ addl (v), %eax
26954+ adcl 4(v), %edx
26955 movl %eax, (v)
26956 movl %edx, 4(v)
26957 RET_ENDP
26958@@ -105,6 +180,20 @@ RET_ENDP
26959 BEGIN(inc)
26960 addl $1, (v)
26961 adcl $0, 4(v)
26962+
26963+#ifdef CONFIG_PAX_REFCOUNT
26964+ jno 0f
26965+ subl $1, (v)
26966+ sbbl $0, 4(v)
26967+ int $4
26968+0:
26969+ _ASM_EXTABLE(0b, 0b)
26970+#endif
26971+
26972+RET_ENDP
26973+BEGIN(inc_unchecked)
26974+ addl $1, (v)
26975+ adcl $0, 4(v)
26976 RET_ENDP
26977 #undef v
26978
26979@@ -114,6 +203,26 @@ BEGIN(inc_return)
26980 movl 4(v), %edx
26981 addl $1, %eax
26982 adcl $0, %edx
26983+
26984+#ifdef CONFIG_PAX_REFCOUNT
26985+ into
26986+1234:
26987+ _ASM_EXTABLE(1234b, 2f)
26988+#endif
26989+
26990+ movl %eax, (v)
26991+ movl %edx, 4(v)
26992+
26993+#ifdef CONFIG_PAX_REFCOUNT
26994+2:
26995+#endif
26996+
26997+RET_ENDP
26998+BEGIN(inc_return_unchecked)
26999+ movl (v), %eax
27000+ movl 4(v), %edx
27001+ addl $1, %eax
27002+ adcl $0, %edx
27003 movl %eax, (v)
27004 movl %edx, 4(v)
27005 RET_ENDP
27006@@ -123,6 +232,20 @@ RET_ENDP
27007 BEGIN(dec)
27008 subl $1, (v)
27009 sbbl $0, 4(v)
27010+
27011+#ifdef CONFIG_PAX_REFCOUNT
27012+ jno 0f
27013+ addl $1, (v)
27014+ adcl $0, 4(v)
27015+ int $4
27016+0:
27017+ _ASM_EXTABLE(0b, 0b)
27018+#endif
27019+
27020+RET_ENDP
27021+BEGIN(dec_unchecked)
27022+ subl $1, (v)
27023+ sbbl $0, 4(v)
27024 RET_ENDP
27025 #undef v
27026
27027@@ -132,6 +255,26 @@ BEGIN(dec_return)
27028 movl 4(v), %edx
27029 subl $1, %eax
27030 sbbl $0, %edx
27031+
27032+#ifdef CONFIG_PAX_REFCOUNT
27033+ into
27034+1234:
27035+ _ASM_EXTABLE(1234b, 2f)
27036+#endif
27037+
27038+ movl %eax, (v)
27039+ movl %edx, 4(v)
27040+
27041+#ifdef CONFIG_PAX_REFCOUNT
27042+2:
27043+#endif
27044+
27045+RET_ENDP
27046+BEGIN(dec_return_unchecked)
27047+ movl (v), %eax
27048+ movl 4(v), %edx
27049+ subl $1, %eax
27050+ sbbl $0, %edx
27051 movl %eax, (v)
27052 movl %edx, 4(v)
27053 RET_ENDP
27054@@ -143,6 +286,13 @@ BEGIN(add_unless)
27055 adcl %edx, %edi
27056 addl (v), %eax
27057 adcl 4(v), %edx
27058+
27059+#ifdef CONFIG_PAX_REFCOUNT
27060+ into
27061+1234:
27062+ _ASM_EXTABLE(1234b, 2f)
27063+#endif
27064+
27065 cmpl %eax, %ecx
27066 je 3f
27067 1:
27068@@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
27069 1:
27070 addl $1, %eax
27071 adcl $0, %edx
27072+
27073+#ifdef CONFIG_PAX_REFCOUNT
27074+ into
27075+1234:
27076+ _ASM_EXTABLE(1234b, 2f)
27077+#endif
27078+
27079 movl %eax, (v)
27080 movl %edx, 4(v)
27081 movl $1, %eax
27082@@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
27083 movl 4(v), %edx
27084 subl $1, %eax
27085 sbbl $0, %edx
27086+
27087+#ifdef CONFIG_PAX_REFCOUNT
27088+ into
27089+1234:
27090+ _ASM_EXTABLE(1234b, 1f)
27091+#endif
27092+
27093 js 1f
27094 movl %eax, (v)
27095 movl %edx, 4(v)
27096diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
27097index f5cc9eb..51fa319 100644
27098--- a/arch/x86/lib/atomic64_cx8_32.S
27099+++ b/arch/x86/lib/atomic64_cx8_32.S
27100@@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
27101 CFI_STARTPROC
27102
27103 read64 %ecx
27104+ pax_force_retaddr
27105 ret
27106 CFI_ENDPROC
27107 ENDPROC(atomic64_read_cx8)
27108
27109+ENTRY(atomic64_read_unchecked_cx8)
27110+ CFI_STARTPROC
27111+
27112+ read64 %ecx
27113+ pax_force_retaddr
27114+ ret
27115+ CFI_ENDPROC
27116+ENDPROC(atomic64_read_unchecked_cx8)
27117+
27118 ENTRY(atomic64_set_cx8)
27119 CFI_STARTPROC
27120
27121@@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
27122 cmpxchg8b (%esi)
27123 jne 1b
27124
27125+ pax_force_retaddr
27126 ret
27127 CFI_ENDPROC
27128 ENDPROC(atomic64_set_cx8)
27129
27130+ENTRY(atomic64_set_unchecked_cx8)
27131+ CFI_STARTPROC
27132+
27133+1:
27134+/* we don't need LOCK_PREFIX since aligned 64-bit writes
27135+ * are atomic on 586 and newer */
27136+ cmpxchg8b (%esi)
27137+ jne 1b
27138+
27139+ pax_force_retaddr
27140+ ret
27141+ CFI_ENDPROC
27142+ENDPROC(atomic64_set_unchecked_cx8)
27143+
27144 ENTRY(atomic64_xchg_cx8)
27145 CFI_STARTPROC
27146
27147@@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
27148 cmpxchg8b (%esi)
27149 jne 1b
27150
27151+ pax_force_retaddr
27152 ret
27153 CFI_ENDPROC
27154 ENDPROC(atomic64_xchg_cx8)
27155
27156-.macro addsub_return func ins insc
27157-ENTRY(atomic64_\func\()_return_cx8)
27158+.macro addsub_return func ins insc unchecked=""
27159+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
27160 CFI_STARTPROC
27161 SAVE ebp
27162 SAVE ebx
27163@@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
27164 movl %edx, %ecx
27165 \ins\()l %esi, %ebx
27166 \insc\()l %edi, %ecx
27167+
27168+.ifb \unchecked
27169+#ifdef CONFIG_PAX_REFCOUNT
27170+ into
27171+2:
27172+ _ASM_EXTABLE(2b, 3f)
27173+#endif
27174+.endif
27175+
27176 LOCK_PREFIX
27177 cmpxchg8b (%ebp)
27178 jne 1b
27179-
27180-10:
27181 movl %ebx, %eax
27182 movl %ecx, %edx
27183+
27184+.ifb \unchecked
27185+#ifdef CONFIG_PAX_REFCOUNT
27186+3:
27187+#endif
27188+.endif
27189+
27190 RESTORE edi
27191 RESTORE esi
27192 RESTORE ebx
27193 RESTORE ebp
27194+ pax_force_retaddr
27195 ret
27196 CFI_ENDPROC
27197-ENDPROC(atomic64_\func\()_return_cx8)
27198+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
27199 .endm
27200
27201 addsub_return add add adc
27202 addsub_return sub sub sbb
27203+addsub_return add add adc _unchecked
27204+addsub_return sub sub sbb _unchecked
27205
27206-.macro incdec_return func ins insc
27207-ENTRY(atomic64_\func\()_return_cx8)
27208+.macro incdec_return func ins insc unchecked=""
27209+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
27210 CFI_STARTPROC
27211 SAVE ebx
27212
27213@@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
27214 movl %edx, %ecx
27215 \ins\()l $1, %ebx
27216 \insc\()l $0, %ecx
27217+
27218+.ifb \unchecked
27219+#ifdef CONFIG_PAX_REFCOUNT
27220+ into
27221+2:
27222+ _ASM_EXTABLE(2b, 3f)
27223+#endif
27224+.endif
27225+
27226 LOCK_PREFIX
27227 cmpxchg8b (%esi)
27228 jne 1b
27229
27230-10:
27231 movl %ebx, %eax
27232 movl %ecx, %edx
27233+
27234+.ifb \unchecked
27235+#ifdef CONFIG_PAX_REFCOUNT
27236+3:
27237+#endif
27238+.endif
27239+
27240 RESTORE ebx
27241+ pax_force_retaddr
27242 ret
27243 CFI_ENDPROC
27244-ENDPROC(atomic64_\func\()_return_cx8)
27245+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
27246 .endm
27247
27248 incdec_return inc add adc
27249 incdec_return dec sub sbb
27250+incdec_return inc add adc _unchecked
27251+incdec_return dec sub sbb _unchecked
27252
27253 ENTRY(atomic64_dec_if_positive_cx8)
27254 CFI_STARTPROC
27255@@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
27256 movl %edx, %ecx
27257 subl $1, %ebx
27258 sbb $0, %ecx
27259+
27260+#ifdef CONFIG_PAX_REFCOUNT
27261+ into
27262+1234:
27263+ _ASM_EXTABLE(1234b, 2f)
27264+#endif
27265+
27266 js 2f
27267 LOCK_PREFIX
27268 cmpxchg8b (%esi)
27269@@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
27270 movl %ebx, %eax
27271 movl %ecx, %edx
27272 RESTORE ebx
27273+ pax_force_retaddr
27274 ret
27275 CFI_ENDPROC
27276 ENDPROC(atomic64_dec_if_positive_cx8)
27277@@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
27278 movl %edx, %ecx
27279 addl %ebp, %ebx
27280 adcl %edi, %ecx
27281+
27282+#ifdef CONFIG_PAX_REFCOUNT
27283+ into
27284+1234:
27285+ _ASM_EXTABLE(1234b, 3f)
27286+#endif
27287+
27288 LOCK_PREFIX
27289 cmpxchg8b (%esi)
27290 jne 1b
27291@@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
27292 CFI_ADJUST_CFA_OFFSET -8
27293 RESTORE ebx
27294 RESTORE ebp
27295+ pax_force_retaddr
27296 ret
27297 4:
27298 cmpl %edx, 4(%esp)
27299@@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
27300 xorl %ecx, %ecx
27301 addl $1, %ebx
27302 adcl %edx, %ecx
27303+
27304+#ifdef CONFIG_PAX_REFCOUNT
27305+ into
27306+1234:
27307+ _ASM_EXTABLE(1234b, 3f)
27308+#endif
27309+
27310 LOCK_PREFIX
27311 cmpxchg8b (%esi)
27312 jne 1b
27313@@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
27314 movl $1, %eax
27315 3:
27316 RESTORE ebx
27317+ pax_force_retaddr
27318 ret
27319 CFI_ENDPROC
27320 ENDPROC(atomic64_inc_not_zero_cx8)
27321diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
27322index e78b8ee..7e173a8 100644
27323--- a/arch/x86/lib/checksum_32.S
27324+++ b/arch/x86/lib/checksum_32.S
27325@@ -29,7 +29,8 @@
27326 #include <asm/dwarf2.h>
27327 #include <asm/errno.h>
27328 #include <asm/asm.h>
27329-
27330+#include <asm/segment.h>
27331+
27332 /*
27333 * computes a partial checksum, e.g. for TCP/UDP fragments
27334 */
27335@@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
27336
27337 #define ARGBASE 16
27338 #define FP 12
27339-
27340-ENTRY(csum_partial_copy_generic)
27341+
27342+ENTRY(csum_partial_copy_generic_to_user)
27343 CFI_STARTPROC
27344+
27345+#ifdef CONFIG_PAX_MEMORY_UDEREF
27346+ pushl_cfi %gs
27347+ popl_cfi %es
27348+ jmp csum_partial_copy_generic
27349+#endif
27350+
27351+ENTRY(csum_partial_copy_generic_from_user)
27352+
27353+#ifdef CONFIG_PAX_MEMORY_UDEREF
27354+ pushl_cfi %gs
27355+ popl_cfi %ds
27356+#endif
27357+
27358+ENTRY(csum_partial_copy_generic)
27359 subl $4,%esp
27360 CFI_ADJUST_CFA_OFFSET 4
27361 pushl_cfi %edi
27362@@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
27363 jmp 4f
27364 SRC(1: movw (%esi), %bx )
27365 addl $2, %esi
27366-DST( movw %bx, (%edi) )
27367+DST( movw %bx, %es:(%edi) )
27368 addl $2, %edi
27369 addw %bx, %ax
27370 adcl $0, %eax
27371@@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
27372 SRC(1: movl (%esi), %ebx )
27373 SRC( movl 4(%esi), %edx )
27374 adcl %ebx, %eax
27375-DST( movl %ebx, (%edi) )
27376+DST( movl %ebx, %es:(%edi) )
27377 adcl %edx, %eax
27378-DST( movl %edx, 4(%edi) )
27379+DST( movl %edx, %es:4(%edi) )
27380
27381 SRC( movl 8(%esi), %ebx )
27382 SRC( movl 12(%esi), %edx )
27383 adcl %ebx, %eax
27384-DST( movl %ebx, 8(%edi) )
27385+DST( movl %ebx, %es:8(%edi) )
27386 adcl %edx, %eax
27387-DST( movl %edx, 12(%edi) )
27388+DST( movl %edx, %es:12(%edi) )
27389
27390 SRC( movl 16(%esi), %ebx )
27391 SRC( movl 20(%esi), %edx )
27392 adcl %ebx, %eax
27393-DST( movl %ebx, 16(%edi) )
27394+DST( movl %ebx, %es:16(%edi) )
27395 adcl %edx, %eax
27396-DST( movl %edx, 20(%edi) )
27397+DST( movl %edx, %es:20(%edi) )
27398
27399 SRC( movl 24(%esi), %ebx )
27400 SRC( movl 28(%esi), %edx )
27401 adcl %ebx, %eax
27402-DST( movl %ebx, 24(%edi) )
27403+DST( movl %ebx, %es:24(%edi) )
27404 adcl %edx, %eax
27405-DST( movl %edx, 28(%edi) )
27406+DST( movl %edx, %es:28(%edi) )
27407
27408 lea 32(%esi), %esi
27409 lea 32(%edi), %edi
27410@@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
27411 shrl $2, %edx # This clears CF
27412 SRC(3: movl (%esi), %ebx )
27413 adcl %ebx, %eax
27414-DST( movl %ebx, (%edi) )
27415+DST( movl %ebx, %es:(%edi) )
27416 lea 4(%esi), %esi
27417 lea 4(%edi), %edi
27418 dec %edx
27419@@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
27420 jb 5f
27421 SRC( movw (%esi), %cx )
27422 leal 2(%esi), %esi
27423-DST( movw %cx, (%edi) )
27424+DST( movw %cx, %es:(%edi) )
27425 leal 2(%edi), %edi
27426 je 6f
27427 shll $16,%ecx
27428 SRC(5: movb (%esi), %cl )
27429-DST( movb %cl, (%edi) )
27430+DST( movb %cl, %es:(%edi) )
27431 6: addl %ecx, %eax
27432 adcl $0, %eax
27433 7:
27434@@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
27435
27436 6001:
27437 movl ARGBASE+20(%esp), %ebx # src_err_ptr
27438- movl $-EFAULT, (%ebx)
27439+ movl $-EFAULT, %ss:(%ebx)
27440
27441 # zero the complete destination - computing the rest
27442 # is too much work
27443@@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
27444
27445 6002:
27446 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
27447- movl $-EFAULT,(%ebx)
27448+ movl $-EFAULT,%ss:(%ebx)
27449 jmp 5000b
27450
27451 .previous
27452
27453+ pushl_cfi %ss
27454+ popl_cfi %ds
27455+ pushl_cfi %ss
27456+ popl_cfi %es
27457 popl_cfi %ebx
27458 CFI_RESTORE ebx
27459 popl_cfi %esi
27460@@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
27461 popl_cfi %ecx # equivalent to addl $4,%esp
27462 ret
27463 CFI_ENDPROC
27464-ENDPROC(csum_partial_copy_generic)
27465+ENDPROC(csum_partial_copy_generic_to_user)
27466
27467 #else
27468
27469 /* Version for PentiumII/PPro */
27470
27471 #define ROUND1(x) \
27472+ nop; nop; nop; \
27473 SRC(movl x(%esi), %ebx ) ; \
27474 addl %ebx, %eax ; \
27475- DST(movl %ebx, x(%edi) ) ;
27476+ DST(movl %ebx, %es:x(%edi)) ;
27477
27478 #define ROUND(x) \
27479+ nop; nop; nop; \
27480 SRC(movl x(%esi), %ebx ) ; \
27481 adcl %ebx, %eax ; \
27482- DST(movl %ebx, x(%edi) ) ;
27483+ DST(movl %ebx, %es:x(%edi)) ;
27484
27485 #define ARGBASE 12
27486-
27487-ENTRY(csum_partial_copy_generic)
27488+
27489+ENTRY(csum_partial_copy_generic_to_user)
27490 CFI_STARTPROC
27491+
27492+#ifdef CONFIG_PAX_MEMORY_UDEREF
27493+ pushl_cfi %gs
27494+ popl_cfi %es
27495+ jmp csum_partial_copy_generic
27496+#endif
27497+
27498+ENTRY(csum_partial_copy_generic_from_user)
27499+
27500+#ifdef CONFIG_PAX_MEMORY_UDEREF
27501+ pushl_cfi %gs
27502+ popl_cfi %ds
27503+#endif
27504+
27505+ENTRY(csum_partial_copy_generic)
27506 pushl_cfi %ebx
27507 CFI_REL_OFFSET ebx, 0
27508 pushl_cfi %edi
27509@@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
27510 subl %ebx, %edi
27511 lea -1(%esi),%edx
27512 andl $-32,%edx
27513- lea 3f(%ebx,%ebx), %ebx
27514+ lea 3f(%ebx,%ebx,2), %ebx
27515 testl %esi, %esi
27516 jmp *%ebx
27517 1: addl $64,%esi
27518@@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
27519 jb 5f
27520 SRC( movw (%esi), %dx )
27521 leal 2(%esi), %esi
27522-DST( movw %dx, (%edi) )
27523+DST( movw %dx, %es:(%edi) )
27524 leal 2(%edi), %edi
27525 je 6f
27526 shll $16,%edx
27527 5:
27528 SRC( movb (%esi), %dl )
27529-DST( movb %dl, (%edi) )
27530+DST( movb %dl, %es:(%edi) )
27531 6: addl %edx, %eax
27532 adcl $0, %eax
27533 7:
27534 .section .fixup, "ax"
27535 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
27536- movl $-EFAULT, (%ebx)
27537+ movl $-EFAULT, %ss:(%ebx)
27538 # zero the complete destination (computing the rest is too much work)
27539 movl ARGBASE+8(%esp),%edi # dst
27540 movl ARGBASE+12(%esp),%ecx # len
27541@@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
27542 rep; stosb
27543 jmp 7b
27544 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
27545- movl $-EFAULT, (%ebx)
27546+ movl $-EFAULT, %ss:(%ebx)
27547 jmp 7b
27548 .previous
27549
27550+#ifdef CONFIG_PAX_MEMORY_UDEREF
27551+ pushl_cfi %ss
27552+ popl_cfi %ds
27553+ pushl_cfi %ss
27554+ popl_cfi %es
27555+#endif
27556+
27557 popl_cfi %esi
27558 CFI_RESTORE esi
27559 popl_cfi %edi
27560@@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
27561 CFI_RESTORE ebx
27562 ret
27563 CFI_ENDPROC
27564-ENDPROC(csum_partial_copy_generic)
27565+ENDPROC(csum_partial_copy_generic_to_user)
27566
27567 #undef ROUND
27568 #undef ROUND1
27569diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
27570index f2145cf..cea889d 100644
27571--- a/arch/x86/lib/clear_page_64.S
27572+++ b/arch/x86/lib/clear_page_64.S
27573@@ -11,6 +11,7 @@ ENTRY(clear_page_c)
27574 movl $4096/8,%ecx
27575 xorl %eax,%eax
27576 rep stosq
27577+ pax_force_retaddr
27578 ret
27579 CFI_ENDPROC
27580 ENDPROC(clear_page_c)
27581@@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
27582 movl $4096,%ecx
27583 xorl %eax,%eax
27584 rep stosb
27585+ pax_force_retaddr
27586 ret
27587 CFI_ENDPROC
27588 ENDPROC(clear_page_c_e)
27589@@ -43,6 +45,7 @@ ENTRY(clear_page)
27590 leaq 64(%rdi),%rdi
27591 jnz .Lloop
27592 nop
27593+ pax_force_retaddr
27594 ret
27595 CFI_ENDPROC
27596 .Lclear_page_end:
27597@@ -58,7 +61,7 @@ ENDPROC(clear_page)
27598
27599 #include <asm/cpufeature.h>
27600
27601- .section .altinstr_replacement,"ax"
27602+ .section .altinstr_replacement,"a"
27603 1: .byte 0xeb /* jmp <disp8> */
27604 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
27605 2: .byte 0xeb /* jmp <disp8> */
27606diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
27607index 1e572c5..2a162cd 100644
27608--- a/arch/x86/lib/cmpxchg16b_emu.S
27609+++ b/arch/x86/lib/cmpxchg16b_emu.S
27610@@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
27611
27612 popf
27613 mov $1, %al
27614+ pax_force_retaddr
27615 ret
27616
27617 not_same:
27618 popf
27619 xor %al,%al
27620+ pax_force_retaddr
27621 ret
27622
27623 CFI_ENDPROC
27624diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
27625index 176cca6..1166c50 100644
27626--- a/arch/x86/lib/copy_page_64.S
27627+++ b/arch/x86/lib/copy_page_64.S
27628@@ -9,6 +9,7 @@ copy_page_rep:
27629 CFI_STARTPROC
27630 movl $4096/8, %ecx
27631 rep movsq
27632+ pax_force_retaddr
27633 ret
27634 CFI_ENDPROC
27635 ENDPROC(copy_page_rep)
27636@@ -20,12 +21,14 @@ ENDPROC(copy_page_rep)
27637
27638 ENTRY(copy_page)
27639 CFI_STARTPROC
27640- subq $2*8, %rsp
27641- CFI_ADJUST_CFA_OFFSET 2*8
27642+ subq $3*8, %rsp
27643+ CFI_ADJUST_CFA_OFFSET 3*8
27644 movq %rbx, (%rsp)
27645 CFI_REL_OFFSET rbx, 0
27646 movq %r12, 1*8(%rsp)
27647 CFI_REL_OFFSET r12, 1*8
27648+ movq %r13, 2*8(%rsp)
27649+ CFI_REL_OFFSET r13, 2*8
27650
27651 movl $(4096/64)-5, %ecx
27652 .p2align 4
27653@@ -36,7 +39,7 @@ ENTRY(copy_page)
27654 movq 0x8*2(%rsi), %rdx
27655 movq 0x8*3(%rsi), %r8
27656 movq 0x8*4(%rsi), %r9
27657- movq 0x8*5(%rsi), %r10
27658+ movq 0x8*5(%rsi), %r13
27659 movq 0x8*6(%rsi), %r11
27660 movq 0x8*7(%rsi), %r12
27661
27662@@ -47,7 +50,7 @@ ENTRY(copy_page)
27663 movq %rdx, 0x8*2(%rdi)
27664 movq %r8, 0x8*3(%rdi)
27665 movq %r9, 0x8*4(%rdi)
27666- movq %r10, 0x8*5(%rdi)
27667+ movq %r13, 0x8*5(%rdi)
27668 movq %r11, 0x8*6(%rdi)
27669 movq %r12, 0x8*7(%rdi)
27670
27671@@ -66,7 +69,7 @@ ENTRY(copy_page)
27672 movq 0x8*2(%rsi), %rdx
27673 movq 0x8*3(%rsi), %r8
27674 movq 0x8*4(%rsi), %r9
27675- movq 0x8*5(%rsi), %r10
27676+ movq 0x8*5(%rsi), %r13
27677 movq 0x8*6(%rsi), %r11
27678 movq 0x8*7(%rsi), %r12
27679
27680@@ -75,7 +78,7 @@ ENTRY(copy_page)
27681 movq %rdx, 0x8*2(%rdi)
27682 movq %r8, 0x8*3(%rdi)
27683 movq %r9, 0x8*4(%rdi)
27684- movq %r10, 0x8*5(%rdi)
27685+ movq %r13, 0x8*5(%rdi)
27686 movq %r11, 0x8*6(%rdi)
27687 movq %r12, 0x8*7(%rdi)
27688
27689@@ -87,8 +90,11 @@ ENTRY(copy_page)
27690 CFI_RESTORE rbx
27691 movq 1*8(%rsp), %r12
27692 CFI_RESTORE r12
27693- addq $2*8, %rsp
27694- CFI_ADJUST_CFA_OFFSET -2*8
27695+ movq 2*8(%rsp), %r13
27696+ CFI_RESTORE r13
27697+ addq $3*8, %rsp
27698+ CFI_ADJUST_CFA_OFFSET -3*8
27699+ pax_force_retaddr
27700 ret
27701 .Lcopy_page_end:
27702 CFI_ENDPROC
27703@@ -99,7 +105,7 @@ ENDPROC(copy_page)
27704
27705 #include <asm/cpufeature.h>
27706
27707- .section .altinstr_replacement,"ax"
27708+ .section .altinstr_replacement,"a"
27709 1: .byte 0xeb /* jmp <disp8> */
27710 .byte (copy_page_rep - copy_page) - (2f - 1b) /* offset */
27711 2:
27712diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
27713index a30ca15..6b3f4e1 100644
27714--- a/arch/x86/lib/copy_user_64.S
27715+++ b/arch/x86/lib/copy_user_64.S
27716@@ -18,31 +18,7 @@
27717 #include <asm/alternative-asm.h>
27718 #include <asm/asm.h>
27719 #include <asm/smap.h>
27720-
27721-/*
27722- * By placing feature2 after feature1 in altinstructions section, we logically
27723- * implement:
27724- * If CPU has feature2, jmp to alt2 is used
27725- * else if CPU has feature1, jmp to alt1 is used
27726- * else jmp to orig is used.
27727- */
27728- .macro ALTERNATIVE_JUMP feature1,feature2,orig,alt1,alt2
27729-0:
27730- .byte 0xe9 /* 32bit jump */
27731- .long \orig-1f /* by default jump to orig */
27732-1:
27733- .section .altinstr_replacement,"ax"
27734-2: .byte 0xe9 /* near jump with 32bit immediate */
27735- .long \alt1-1b /* offset */ /* or alternatively to alt1 */
27736-3: .byte 0xe9 /* near jump with 32bit immediate */
27737- .long \alt2-1b /* offset */ /* or alternatively to alt2 */
27738- .previous
27739-
27740- .section .altinstructions,"a"
27741- altinstruction_entry 0b,2b,\feature1,5,5
27742- altinstruction_entry 0b,3b,\feature2,5,5
27743- .previous
27744- .endm
27745+#include <asm/pgtable.h>
27746
27747 .macro ALIGN_DESTINATION
27748 #ifdef FIX_ALIGNMENT
27749@@ -70,52 +46,6 @@
27750 #endif
27751 .endm
27752
27753-/* Standard copy_to_user with segment limit checking */
27754-ENTRY(_copy_to_user)
27755- CFI_STARTPROC
27756- GET_THREAD_INFO(%rax)
27757- movq %rdi,%rcx
27758- addq %rdx,%rcx
27759- jc bad_to_user
27760- cmpq TI_addr_limit(%rax),%rcx
27761- ja bad_to_user
27762- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
27763- copy_user_generic_unrolled,copy_user_generic_string, \
27764- copy_user_enhanced_fast_string
27765- CFI_ENDPROC
27766-ENDPROC(_copy_to_user)
27767-
27768-/* Standard copy_from_user with segment limit checking */
27769-ENTRY(_copy_from_user)
27770- CFI_STARTPROC
27771- GET_THREAD_INFO(%rax)
27772- movq %rsi,%rcx
27773- addq %rdx,%rcx
27774- jc bad_from_user
27775- cmpq TI_addr_limit(%rax),%rcx
27776- ja bad_from_user
27777- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
27778- copy_user_generic_unrolled,copy_user_generic_string, \
27779- copy_user_enhanced_fast_string
27780- CFI_ENDPROC
27781-ENDPROC(_copy_from_user)
27782-
27783- .section .fixup,"ax"
27784- /* must zero dest */
27785-ENTRY(bad_from_user)
27786-bad_from_user:
27787- CFI_STARTPROC
27788- movl %edx,%ecx
27789- xorl %eax,%eax
27790- rep
27791- stosb
27792-bad_to_user:
27793- movl %edx,%eax
27794- ret
27795- CFI_ENDPROC
27796-ENDPROC(bad_from_user)
27797- .previous
27798-
27799 /*
27800 * copy_user_generic_unrolled - memory copy with exception handling.
27801 * This version is for CPUs like P4 that don't have efficient micro
27802@@ -131,6 +61,7 @@ ENDPROC(bad_from_user)
27803 */
27804 ENTRY(copy_user_generic_unrolled)
27805 CFI_STARTPROC
27806+ ASM_PAX_OPEN_USERLAND
27807 ASM_STAC
27808 cmpl $8,%edx
27809 jb 20f /* less then 8 bytes, go to byte copy loop */
27810@@ -141,19 +72,19 @@ ENTRY(copy_user_generic_unrolled)
27811 jz 17f
27812 1: movq (%rsi),%r8
27813 2: movq 1*8(%rsi),%r9
27814-3: movq 2*8(%rsi),%r10
27815+3: movq 2*8(%rsi),%rax
27816 4: movq 3*8(%rsi),%r11
27817 5: movq %r8,(%rdi)
27818 6: movq %r9,1*8(%rdi)
27819-7: movq %r10,2*8(%rdi)
27820+7: movq %rax,2*8(%rdi)
27821 8: movq %r11,3*8(%rdi)
27822 9: movq 4*8(%rsi),%r8
27823 10: movq 5*8(%rsi),%r9
27824-11: movq 6*8(%rsi),%r10
27825+11: movq 6*8(%rsi),%rax
27826 12: movq 7*8(%rsi),%r11
27827 13: movq %r8,4*8(%rdi)
27828 14: movq %r9,5*8(%rdi)
27829-15: movq %r10,6*8(%rdi)
27830+15: movq %rax,6*8(%rdi)
27831 16: movq %r11,7*8(%rdi)
27832 leaq 64(%rsi),%rsi
27833 leaq 64(%rdi),%rdi
27834@@ -180,6 +111,8 @@ ENTRY(copy_user_generic_unrolled)
27835 jnz 21b
27836 23: xor %eax,%eax
27837 ASM_CLAC
27838+ ASM_PAX_CLOSE_USERLAND
27839+ pax_force_retaddr
27840 ret
27841
27842 .section .fixup,"ax"
27843@@ -235,6 +168,7 @@ ENDPROC(copy_user_generic_unrolled)
27844 */
27845 ENTRY(copy_user_generic_string)
27846 CFI_STARTPROC
27847+ ASM_PAX_OPEN_USERLAND
27848 ASM_STAC
27849 andl %edx,%edx
27850 jz 4f
27851@@ -251,6 +185,8 @@ ENTRY(copy_user_generic_string)
27852 movsb
27853 4: xorl %eax,%eax
27854 ASM_CLAC
27855+ ASM_PAX_CLOSE_USERLAND
27856+ pax_force_retaddr
27857 ret
27858
27859 .section .fixup,"ax"
27860@@ -278,6 +214,7 @@ ENDPROC(copy_user_generic_string)
27861 */
27862 ENTRY(copy_user_enhanced_fast_string)
27863 CFI_STARTPROC
27864+ ASM_PAX_OPEN_USERLAND
27865 ASM_STAC
27866 andl %edx,%edx
27867 jz 2f
27868@@ -286,6 +223,8 @@ ENTRY(copy_user_enhanced_fast_string)
27869 movsb
27870 2: xorl %eax,%eax
27871 ASM_CLAC
27872+ ASM_PAX_CLOSE_USERLAND
27873+ pax_force_retaddr
27874 ret
27875
27876 .section .fixup,"ax"
27877diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
27878index 6a4f43c..55d26f2 100644
27879--- a/arch/x86/lib/copy_user_nocache_64.S
27880+++ b/arch/x86/lib/copy_user_nocache_64.S
27881@@ -8,6 +8,7 @@
27882
27883 #include <linux/linkage.h>
27884 #include <asm/dwarf2.h>
27885+#include <asm/alternative-asm.h>
27886
27887 #define FIX_ALIGNMENT 1
27888
27889@@ -16,6 +17,7 @@
27890 #include <asm/thread_info.h>
27891 #include <asm/asm.h>
27892 #include <asm/smap.h>
27893+#include <asm/pgtable.h>
27894
27895 .macro ALIGN_DESTINATION
27896 #ifdef FIX_ALIGNMENT
27897@@ -49,6 +51,16 @@
27898 */
27899 ENTRY(__copy_user_nocache)
27900 CFI_STARTPROC
27901+
27902+#ifdef CONFIG_PAX_MEMORY_UDEREF
27903+ mov pax_user_shadow_base,%rcx
27904+ cmp %rcx,%rsi
27905+ jae 1f
27906+ add %rcx,%rsi
27907+1:
27908+#endif
27909+
27910+ ASM_PAX_OPEN_USERLAND
27911 ASM_STAC
27912 cmpl $8,%edx
27913 jb 20f /* less then 8 bytes, go to byte copy loop */
27914@@ -59,19 +71,19 @@ ENTRY(__copy_user_nocache)
27915 jz 17f
27916 1: movq (%rsi),%r8
27917 2: movq 1*8(%rsi),%r9
27918-3: movq 2*8(%rsi),%r10
27919+3: movq 2*8(%rsi),%rax
27920 4: movq 3*8(%rsi),%r11
27921 5: movnti %r8,(%rdi)
27922 6: movnti %r9,1*8(%rdi)
27923-7: movnti %r10,2*8(%rdi)
27924+7: movnti %rax,2*8(%rdi)
27925 8: movnti %r11,3*8(%rdi)
27926 9: movq 4*8(%rsi),%r8
27927 10: movq 5*8(%rsi),%r9
27928-11: movq 6*8(%rsi),%r10
27929+11: movq 6*8(%rsi),%rax
27930 12: movq 7*8(%rsi),%r11
27931 13: movnti %r8,4*8(%rdi)
27932 14: movnti %r9,5*8(%rdi)
27933-15: movnti %r10,6*8(%rdi)
27934+15: movnti %rax,6*8(%rdi)
27935 16: movnti %r11,7*8(%rdi)
27936 leaq 64(%rsi),%rsi
27937 leaq 64(%rdi),%rdi
27938@@ -98,7 +110,9 @@ ENTRY(__copy_user_nocache)
27939 jnz 21b
27940 23: xorl %eax,%eax
27941 ASM_CLAC
27942+ ASM_PAX_CLOSE_USERLAND
27943 sfence
27944+ pax_force_retaddr
27945 ret
27946
27947 .section .fixup,"ax"
27948diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
27949index 2419d5f..953ee51 100644
27950--- a/arch/x86/lib/csum-copy_64.S
27951+++ b/arch/x86/lib/csum-copy_64.S
27952@@ -9,6 +9,7 @@
27953 #include <asm/dwarf2.h>
27954 #include <asm/errno.h>
27955 #include <asm/asm.h>
27956+#include <asm/alternative-asm.h>
27957
27958 /*
27959 * Checksum copy with exception handling.
27960@@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
27961 CFI_RESTORE rbp
27962 addq $7*8, %rsp
27963 CFI_ADJUST_CFA_OFFSET -7*8
27964+ pax_force_retaddr 0, 1
27965 ret
27966 CFI_RESTORE_STATE
27967
27968diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
27969index 7609e0e..b449b98 100644
27970--- a/arch/x86/lib/csum-wrappers_64.c
27971+++ b/arch/x86/lib/csum-wrappers_64.c
27972@@ -53,10 +53,12 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
27973 len -= 2;
27974 }
27975 }
27976+ pax_open_userland();
27977 stac();
27978- isum = csum_partial_copy_generic((__force const void *)src,
27979+ isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
27980 dst, len, isum, errp, NULL);
27981 clac();
27982+ pax_close_userland();
27983 if (unlikely(*errp))
27984 goto out_err;
27985
27986@@ -110,10 +112,12 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
27987 }
27988
27989 *errp = 0;
27990+ pax_open_userland();
27991 stac();
27992- ret = csum_partial_copy_generic(src, (void __force *)dst,
27993+ ret = csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
27994 len, isum, NULL, errp);
27995 clac();
27996+ pax_close_userland();
27997 return ret;
27998 }
27999 EXPORT_SYMBOL(csum_partial_copy_to_user);
28000diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
28001index a451235..1daa956 100644
28002--- a/arch/x86/lib/getuser.S
28003+++ b/arch/x86/lib/getuser.S
28004@@ -33,17 +33,40 @@
28005 #include <asm/thread_info.h>
28006 #include <asm/asm.h>
28007 #include <asm/smap.h>
28008+#include <asm/segment.h>
28009+#include <asm/pgtable.h>
28010+#include <asm/alternative-asm.h>
28011+
28012+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
28013+#define __copyuser_seg gs;
28014+#else
28015+#define __copyuser_seg
28016+#endif
28017
28018 .text
28019 ENTRY(__get_user_1)
28020 CFI_STARTPROC
28021+
28022+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
28023 GET_THREAD_INFO(%_ASM_DX)
28024 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
28025 jae bad_get_user
28026 ASM_STAC
28027-1: movzbl (%_ASM_AX),%edx
28028+
28029+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28030+ mov pax_user_shadow_base,%_ASM_DX
28031+ cmp %_ASM_DX,%_ASM_AX
28032+ jae 1234f
28033+ add %_ASM_DX,%_ASM_AX
28034+1234:
28035+#endif
28036+
28037+#endif
28038+
28039+1: __copyuser_seg movzbl (%_ASM_AX),%edx
28040 xor %eax,%eax
28041 ASM_CLAC
28042+ pax_force_retaddr
28043 ret
28044 CFI_ENDPROC
28045 ENDPROC(__get_user_1)
28046@@ -51,14 +74,28 @@ ENDPROC(__get_user_1)
28047 ENTRY(__get_user_2)
28048 CFI_STARTPROC
28049 add $1,%_ASM_AX
28050+
28051+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
28052 jc bad_get_user
28053 GET_THREAD_INFO(%_ASM_DX)
28054 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
28055 jae bad_get_user
28056 ASM_STAC
28057-2: movzwl -1(%_ASM_AX),%edx
28058+
28059+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28060+ mov pax_user_shadow_base,%_ASM_DX
28061+ cmp %_ASM_DX,%_ASM_AX
28062+ jae 1234f
28063+ add %_ASM_DX,%_ASM_AX
28064+1234:
28065+#endif
28066+
28067+#endif
28068+
28069+2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
28070 xor %eax,%eax
28071 ASM_CLAC
28072+ pax_force_retaddr
28073 ret
28074 CFI_ENDPROC
28075 ENDPROC(__get_user_2)
28076@@ -66,14 +103,28 @@ ENDPROC(__get_user_2)
28077 ENTRY(__get_user_4)
28078 CFI_STARTPROC
28079 add $3,%_ASM_AX
28080+
28081+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
28082 jc bad_get_user
28083 GET_THREAD_INFO(%_ASM_DX)
28084 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
28085 jae bad_get_user
28086 ASM_STAC
28087-3: movl -3(%_ASM_AX),%edx
28088+
28089+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28090+ mov pax_user_shadow_base,%_ASM_DX
28091+ cmp %_ASM_DX,%_ASM_AX
28092+ jae 1234f
28093+ add %_ASM_DX,%_ASM_AX
28094+1234:
28095+#endif
28096+
28097+#endif
28098+
28099+3: __copyuser_seg movl -3(%_ASM_AX),%edx
28100 xor %eax,%eax
28101 ASM_CLAC
28102+ pax_force_retaddr
28103 ret
28104 CFI_ENDPROC
28105 ENDPROC(__get_user_4)
28106@@ -86,10 +137,20 @@ ENTRY(__get_user_8)
28107 GET_THREAD_INFO(%_ASM_DX)
28108 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
28109 jae bad_get_user
28110+
28111+#ifdef CONFIG_PAX_MEMORY_UDEREF
28112+ mov pax_user_shadow_base,%_ASM_DX
28113+ cmp %_ASM_DX,%_ASM_AX
28114+ jae 1234f
28115+ add %_ASM_DX,%_ASM_AX
28116+1234:
28117+#endif
28118+
28119 ASM_STAC
28120 4: movq -7(%_ASM_AX),%rdx
28121 xor %eax,%eax
28122 ASM_CLAC
28123+ pax_force_retaddr
28124 ret
28125 #else
28126 add $7,%_ASM_AX
28127@@ -98,10 +159,11 @@ ENTRY(__get_user_8)
28128 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
28129 jae bad_get_user_8
28130 ASM_STAC
28131-4: movl -7(%_ASM_AX),%edx
28132-5: movl -3(%_ASM_AX),%ecx
28133+4: __copyuser_seg movl -7(%_ASM_AX),%edx
28134+5: __copyuser_seg movl -3(%_ASM_AX),%ecx
28135 xor %eax,%eax
28136 ASM_CLAC
28137+ pax_force_retaddr
28138 ret
28139 #endif
28140 CFI_ENDPROC
28141@@ -113,6 +175,7 @@ bad_get_user:
28142 xor %edx,%edx
28143 mov $(-EFAULT),%_ASM_AX
28144 ASM_CLAC
28145+ pax_force_retaddr
28146 ret
28147 CFI_ENDPROC
28148 END(bad_get_user)
28149@@ -124,6 +187,7 @@ bad_get_user_8:
28150 xor %ecx,%ecx
28151 mov $(-EFAULT),%_ASM_AX
28152 ASM_CLAC
28153+ pax_force_retaddr
28154 ret
28155 CFI_ENDPROC
28156 END(bad_get_user_8)
28157diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
28158index 54fcffe..7be149e 100644
28159--- a/arch/x86/lib/insn.c
28160+++ b/arch/x86/lib/insn.c
28161@@ -20,8 +20,10 @@
28162
28163 #ifdef __KERNEL__
28164 #include <linux/string.h>
28165+#include <asm/pgtable_types.h>
28166 #else
28167 #include <string.h>
28168+#define ktla_ktva(addr) addr
28169 #endif
28170 #include <asm/inat.h>
28171 #include <asm/insn.h>
28172@@ -53,8 +55,8 @@
28173 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
28174 {
28175 memset(insn, 0, sizeof(*insn));
28176- insn->kaddr = kaddr;
28177- insn->next_byte = kaddr;
28178+ insn->kaddr = ktla_ktva(kaddr);
28179+ insn->next_byte = ktla_ktva(kaddr);
28180 insn->x86_64 = x86_64 ? 1 : 0;
28181 insn->opnd_bytes = 4;
28182 if (x86_64)
28183diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
28184index 05a95e7..326f2fa 100644
28185--- a/arch/x86/lib/iomap_copy_64.S
28186+++ b/arch/x86/lib/iomap_copy_64.S
28187@@ -17,6 +17,7 @@
28188
28189 #include <linux/linkage.h>
28190 #include <asm/dwarf2.h>
28191+#include <asm/alternative-asm.h>
28192
28193 /*
28194 * override generic version in lib/iomap_copy.c
28195@@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
28196 CFI_STARTPROC
28197 movl %edx,%ecx
28198 rep movsd
28199+ pax_force_retaddr
28200 ret
28201 CFI_ENDPROC
28202 ENDPROC(__iowrite32_copy)
28203diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
28204index 56313a3..9b59269 100644
28205--- a/arch/x86/lib/memcpy_64.S
28206+++ b/arch/x86/lib/memcpy_64.S
28207@@ -24,7 +24,7 @@
28208 * This gets patched over the unrolled variant (below) via the
28209 * alternative instructions framework:
28210 */
28211- .section .altinstr_replacement, "ax", @progbits
28212+ .section .altinstr_replacement, "a", @progbits
28213 .Lmemcpy_c:
28214 movq %rdi, %rax
28215 movq %rdx, %rcx
28216@@ -33,6 +33,7 @@
28217 rep movsq
28218 movl %edx, %ecx
28219 rep movsb
28220+ pax_force_retaddr
28221 ret
28222 .Lmemcpy_e:
28223 .previous
28224@@ -44,11 +45,12 @@
28225 * This gets patched over the unrolled variant (below) via the
28226 * alternative instructions framework:
28227 */
28228- .section .altinstr_replacement, "ax", @progbits
28229+ .section .altinstr_replacement, "a", @progbits
28230 .Lmemcpy_c_e:
28231 movq %rdi, %rax
28232 movq %rdx, %rcx
28233 rep movsb
28234+ pax_force_retaddr
28235 ret
28236 .Lmemcpy_e_e:
28237 .previous
28238@@ -76,13 +78,13 @@ ENTRY(memcpy)
28239 */
28240 movq 0*8(%rsi), %r8
28241 movq 1*8(%rsi), %r9
28242- movq 2*8(%rsi), %r10
28243+ movq 2*8(%rsi), %rcx
28244 movq 3*8(%rsi), %r11
28245 leaq 4*8(%rsi), %rsi
28246
28247 movq %r8, 0*8(%rdi)
28248 movq %r9, 1*8(%rdi)
28249- movq %r10, 2*8(%rdi)
28250+ movq %rcx, 2*8(%rdi)
28251 movq %r11, 3*8(%rdi)
28252 leaq 4*8(%rdi), %rdi
28253 jae .Lcopy_forward_loop
28254@@ -105,12 +107,12 @@ ENTRY(memcpy)
28255 subq $0x20, %rdx
28256 movq -1*8(%rsi), %r8
28257 movq -2*8(%rsi), %r9
28258- movq -3*8(%rsi), %r10
28259+ movq -3*8(%rsi), %rcx
28260 movq -4*8(%rsi), %r11
28261 leaq -4*8(%rsi), %rsi
28262 movq %r8, -1*8(%rdi)
28263 movq %r9, -2*8(%rdi)
28264- movq %r10, -3*8(%rdi)
28265+ movq %rcx, -3*8(%rdi)
28266 movq %r11, -4*8(%rdi)
28267 leaq -4*8(%rdi), %rdi
28268 jae .Lcopy_backward_loop
28269@@ -130,12 +132,13 @@ ENTRY(memcpy)
28270 */
28271 movq 0*8(%rsi), %r8
28272 movq 1*8(%rsi), %r9
28273- movq -2*8(%rsi, %rdx), %r10
28274+ movq -2*8(%rsi, %rdx), %rcx
28275 movq -1*8(%rsi, %rdx), %r11
28276 movq %r8, 0*8(%rdi)
28277 movq %r9, 1*8(%rdi)
28278- movq %r10, -2*8(%rdi, %rdx)
28279+ movq %rcx, -2*8(%rdi, %rdx)
28280 movq %r11, -1*8(%rdi, %rdx)
28281+ pax_force_retaddr
28282 retq
28283 .p2align 4
28284 .Lless_16bytes:
28285@@ -148,6 +151,7 @@ ENTRY(memcpy)
28286 movq -1*8(%rsi, %rdx), %r9
28287 movq %r8, 0*8(%rdi)
28288 movq %r9, -1*8(%rdi, %rdx)
28289+ pax_force_retaddr
28290 retq
28291 .p2align 4
28292 .Lless_8bytes:
28293@@ -161,6 +165,7 @@ ENTRY(memcpy)
28294 movl -4(%rsi, %rdx), %r8d
28295 movl %ecx, (%rdi)
28296 movl %r8d, -4(%rdi, %rdx)
28297+ pax_force_retaddr
28298 retq
28299 .p2align 4
28300 .Lless_3bytes:
28301@@ -179,6 +184,7 @@ ENTRY(memcpy)
28302 movb %cl, (%rdi)
28303
28304 .Lend:
28305+ pax_force_retaddr
28306 retq
28307 CFI_ENDPROC
28308 ENDPROC(memcpy)
28309diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
28310index 65268a6..5aa7815 100644
28311--- a/arch/x86/lib/memmove_64.S
28312+++ b/arch/x86/lib/memmove_64.S
28313@@ -61,13 +61,13 @@ ENTRY(memmove)
28314 5:
28315 sub $0x20, %rdx
28316 movq 0*8(%rsi), %r11
28317- movq 1*8(%rsi), %r10
28318+ movq 1*8(%rsi), %rcx
28319 movq 2*8(%rsi), %r9
28320 movq 3*8(%rsi), %r8
28321 leaq 4*8(%rsi), %rsi
28322
28323 movq %r11, 0*8(%rdi)
28324- movq %r10, 1*8(%rdi)
28325+ movq %rcx, 1*8(%rdi)
28326 movq %r9, 2*8(%rdi)
28327 movq %r8, 3*8(%rdi)
28328 leaq 4*8(%rdi), %rdi
28329@@ -81,10 +81,10 @@ ENTRY(memmove)
28330 4:
28331 movq %rdx, %rcx
28332 movq -8(%rsi, %rdx), %r11
28333- lea -8(%rdi, %rdx), %r10
28334+ lea -8(%rdi, %rdx), %r9
28335 shrq $3, %rcx
28336 rep movsq
28337- movq %r11, (%r10)
28338+ movq %r11, (%r9)
28339 jmp 13f
28340 .Lmemmove_end_forward:
28341
28342@@ -95,14 +95,14 @@ ENTRY(memmove)
28343 7:
28344 movq %rdx, %rcx
28345 movq (%rsi), %r11
28346- movq %rdi, %r10
28347+ movq %rdi, %r9
28348 leaq -8(%rsi, %rdx), %rsi
28349 leaq -8(%rdi, %rdx), %rdi
28350 shrq $3, %rcx
28351 std
28352 rep movsq
28353 cld
28354- movq %r11, (%r10)
28355+ movq %r11, (%r9)
28356 jmp 13f
28357
28358 /*
28359@@ -127,13 +127,13 @@ ENTRY(memmove)
28360 8:
28361 subq $0x20, %rdx
28362 movq -1*8(%rsi), %r11
28363- movq -2*8(%rsi), %r10
28364+ movq -2*8(%rsi), %rcx
28365 movq -3*8(%rsi), %r9
28366 movq -4*8(%rsi), %r8
28367 leaq -4*8(%rsi), %rsi
28368
28369 movq %r11, -1*8(%rdi)
28370- movq %r10, -2*8(%rdi)
28371+ movq %rcx, -2*8(%rdi)
28372 movq %r9, -3*8(%rdi)
28373 movq %r8, -4*8(%rdi)
28374 leaq -4*8(%rdi), %rdi
28375@@ -151,11 +151,11 @@ ENTRY(memmove)
28376 * Move data from 16 bytes to 31 bytes.
28377 */
28378 movq 0*8(%rsi), %r11
28379- movq 1*8(%rsi), %r10
28380+ movq 1*8(%rsi), %rcx
28381 movq -2*8(%rsi, %rdx), %r9
28382 movq -1*8(%rsi, %rdx), %r8
28383 movq %r11, 0*8(%rdi)
28384- movq %r10, 1*8(%rdi)
28385+ movq %rcx, 1*8(%rdi)
28386 movq %r9, -2*8(%rdi, %rdx)
28387 movq %r8, -1*8(%rdi, %rdx)
28388 jmp 13f
28389@@ -167,9 +167,9 @@ ENTRY(memmove)
28390 * Move data from 8 bytes to 15 bytes.
28391 */
28392 movq 0*8(%rsi), %r11
28393- movq -1*8(%rsi, %rdx), %r10
28394+ movq -1*8(%rsi, %rdx), %r9
28395 movq %r11, 0*8(%rdi)
28396- movq %r10, -1*8(%rdi, %rdx)
28397+ movq %r9, -1*8(%rdi, %rdx)
28398 jmp 13f
28399 10:
28400 cmpq $4, %rdx
28401@@ -178,9 +178,9 @@ ENTRY(memmove)
28402 * Move data from 4 bytes to 7 bytes.
28403 */
28404 movl (%rsi), %r11d
28405- movl -4(%rsi, %rdx), %r10d
28406+ movl -4(%rsi, %rdx), %r9d
28407 movl %r11d, (%rdi)
28408- movl %r10d, -4(%rdi, %rdx)
28409+ movl %r9d, -4(%rdi, %rdx)
28410 jmp 13f
28411 11:
28412 cmp $2, %rdx
28413@@ -189,9 +189,9 @@ ENTRY(memmove)
28414 * Move data from 2 bytes to 3 bytes.
28415 */
28416 movw (%rsi), %r11w
28417- movw -2(%rsi, %rdx), %r10w
28418+ movw -2(%rsi, %rdx), %r9w
28419 movw %r11w, (%rdi)
28420- movw %r10w, -2(%rdi, %rdx)
28421+ movw %r9w, -2(%rdi, %rdx)
28422 jmp 13f
28423 12:
28424 cmp $1, %rdx
28425@@ -202,14 +202,16 @@ ENTRY(memmove)
28426 movb (%rsi), %r11b
28427 movb %r11b, (%rdi)
28428 13:
28429+ pax_force_retaddr
28430 retq
28431 CFI_ENDPROC
28432
28433- .section .altinstr_replacement,"ax"
28434+ .section .altinstr_replacement,"a"
28435 .Lmemmove_begin_forward_efs:
28436 /* Forward moving data. */
28437 movq %rdx, %rcx
28438 rep movsb
28439+ pax_force_retaddr
28440 retq
28441 .Lmemmove_end_forward_efs:
28442 .previous
28443diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
28444index 2dcb380..50a78bc 100644
28445--- a/arch/x86/lib/memset_64.S
28446+++ b/arch/x86/lib/memset_64.S
28447@@ -16,7 +16,7 @@
28448 *
28449 * rax original destination
28450 */
28451- .section .altinstr_replacement, "ax", @progbits
28452+ .section .altinstr_replacement, "a", @progbits
28453 .Lmemset_c:
28454 movq %rdi,%r9
28455 movq %rdx,%rcx
28456@@ -30,6 +30,7 @@
28457 movl %edx,%ecx
28458 rep stosb
28459 movq %r9,%rax
28460+ pax_force_retaddr
28461 ret
28462 .Lmemset_e:
28463 .previous
28464@@ -45,13 +46,14 @@
28465 *
28466 * rax original destination
28467 */
28468- .section .altinstr_replacement, "ax", @progbits
28469+ .section .altinstr_replacement, "a", @progbits
28470 .Lmemset_c_e:
28471 movq %rdi,%r9
28472 movb %sil,%al
28473 movq %rdx,%rcx
28474 rep stosb
28475 movq %r9,%rax
28476+ pax_force_retaddr
28477 ret
28478 .Lmemset_e_e:
28479 .previous
28480@@ -59,7 +61,7 @@
28481 ENTRY(memset)
28482 ENTRY(__memset)
28483 CFI_STARTPROC
28484- movq %rdi,%r10
28485+ movq %rdi,%r11
28486
28487 /* expand byte value */
28488 movzbl %sil,%ecx
28489@@ -117,7 +119,8 @@ ENTRY(__memset)
28490 jnz .Lloop_1
28491
28492 .Lende:
28493- movq %r10,%rax
28494+ movq %r11,%rax
28495+ pax_force_retaddr
28496 ret
28497
28498 CFI_RESTORE_STATE
28499diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
28500index c9f2d9b..e7fd2c0 100644
28501--- a/arch/x86/lib/mmx_32.c
28502+++ b/arch/x86/lib/mmx_32.c
28503@@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
28504 {
28505 void *p;
28506 int i;
28507+ unsigned long cr0;
28508
28509 if (unlikely(in_interrupt()))
28510 return __memcpy(to, from, len);
28511@@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
28512 kernel_fpu_begin();
28513
28514 __asm__ __volatile__ (
28515- "1: prefetch (%0)\n" /* This set is 28 bytes */
28516- " prefetch 64(%0)\n"
28517- " prefetch 128(%0)\n"
28518- " prefetch 192(%0)\n"
28519- " prefetch 256(%0)\n"
28520+ "1: prefetch (%1)\n" /* This set is 28 bytes */
28521+ " prefetch 64(%1)\n"
28522+ " prefetch 128(%1)\n"
28523+ " prefetch 192(%1)\n"
28524+ " prefetch 256(%1)\n"
28525 "2: \n"
28526 ".section .fixup, \"ax\"\n"
28527- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
28528+ "3: \n"
28529+
28530+#ifdef CONFIG_PAX_KERNEXEC
28531+ " movl %%cr0, %0\n"
28532+ " movl %0, %%eax\n"
28533+ " andl $0xFFFEFFFF, %%eax\n"
28534+ " movl %%eax, %%cr0\n"
28535+#endif
28536+
28537+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
28538+
28539+#ifdef CONFIG_PAX_KERNEXEC
28540+ " movl %0, %%cr0\n"
28541+#endif
28542+
28543 " jmp 2b\n"
28544 ".previous\n"
28545 _ASM_EXTABLE(1b, 3b)
28546- : : "r" (from));
28547+ : "=&r" (cr0) : "r" (from) : "ax");
28548
28549 for ( ; i > 5; i--) {
28550 __asm__ __volatile__ (
28551- "1: prefetch 320(%0)\n"
28552- "2: movq (%0), %%mm0\n"
28553- " movq 8(%0), %%mm1\n"
28554- " movq 16(%0), %%mm2\n"
28555- " movq 24(%0), %%mm3\n"
28556- " movq %%mm0, (%1)\n"
28557- " movq %%mm1, 8(%1)\n"
28558- " movq %%mm2, 16(%1)\n"
28559- " movq %%mm3, 24(%1)\n"
28560- " movq 32(%0), %%mm0\n"
28561- " movq 40(%0), %%mm1\n"
28562- " movq 48(%0), %%mm2\n"
28563- " movq 56(%0), %%mm3\n"
28564- " movq %%mm0, 32(%1)\n"
28565- " movq %%mm1, 40(%1)\n"
28566- " movq %%mm2, 48(%1)\n"
28567- " movq %%mm3, 56(%1)\n"
28568+ "1: prefetch 320(%1)\n"
28569+ "2: movq (%1), %%mm0\n"
28570+ " movq 8(%1), %%mm1\n"
28571+ " movq 16(%1), %%mm2\n"
28572+ " movq 24(%1), %%mm3\n"
28573+ " movq %%mm0, (%2)\n"
28574+ " movq %%mm1, 8(%2)\n"
28575+ " movq %%mm2, 16(%2)\n"
28576+ " movq %%mm3, 24(%2)\n"
28577+ " movq 32(%1), %%mm0\n"
28578+ " movq 40(%1), %%mm1\n"
28579+ " movq 48(%1), %%mm2\n"
28580+ " movq 56(%1), %%mm3\n"
28581+ " movq %%mm0, 32(%2)\n"
28582+ " movq %%mm1, 40(%2)\n"
28583+ " movq %%mm2, 48(%2)\n"
28584+ " movq %%mm3, 56(%2)\n"
28585 ".section .fixup, \"ax\"\n"
28586- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
28587+ "3:\n"
28588+
28589+#ifdef CONFIG_PAX_KERNEXEC
28590+ " movl %%cr0, %0\n"
28591+ " movl %0, %%eax\n"
28592+ " andl $0xFFFEFFFF, %%eax\n"
28593+ " movl %%eax, %%cr0\n"
28594+#endif
28595+
28596+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
28597+
28598+#ifdef CONFIG_PAX_KERNEXEC
28599+ " movl %0, %%cr0\n"
28600+#endif
28601+
28602 " jmp 2b\n"
28603 ".previous\n"
28604 _ASM_EXTABLE(1b, 3b)
28605- : : "r" (from), "r" (to) : "memory");
28606+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
28607
28608 from += 64;
28609 to += 64;
28610@@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
28611 static void fast_copy_page(void *to, void *from)
28612 {
28613 int i;
28614+ unsigned long cr0;
28615
28616 kernel_fpu_begin();
28617
28618@@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
28619 * but that is for later. -AV
28620 */
28621 __asm__ __volatile__(
28622- "1: prefetch (%0)\n"
28623- " prefetch 64(%0)\n"
28624- " prefetch 128(%0)\n"
28625- " prefetch 192(%0)\n"
28626- " prefetch 256(%0)\n"
28627+ "1: prefetch (%1)\n"
28628+ " prefetch 64(%1)\n"
28629+ " prefetch 128(%1)\n"
28630+ " prefetch 192(%1)\n"
28631+ " prefetch 256(%1)\n"
28632 "2: \n"
28633 ".section .fixup, \"ax\"\n"
28634- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
28635+ "3: \n"
28636+
28637+#ifdef CONFIG_PAX_KERNEXEC
28638+ " movl %%cr0, %0\n"
28639+ " movl %0, %%eax\n"
28640+ " andl $0xFFFEFFFF, %%eax\n"
28641+ " movl %%eax, %%cr0\n"
28642+#endif
28643+
28644+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
28645+
28646+#ifdef CONFIG_PAX_KERNEXEC
28647+ " movl %0, %%cr0\n"
28648+#endif
28649+
28650 " jmp 2b\n"
28651 ".previous\n"
28652- _ASM_EXTABLE(1b, 3b) : : "r" (from));
28653+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
28654
28655 for (i = 0; i < (4096-320)/64; i++) {
28656 __asm__ __volatile__ (
28657- "1: prefetch 320(%0)\n"
28658- "2: movq (%0), %%mm0\n"
28659- " movntq %%mm0, (%1)\n"
28660- " movq 8(%0), %%mm1\n"
28661- " movntq %%mm1, 8(%1)\n"
28662- " movq 16(%0), %%mm2\n"
28663- " movntq %%mm2, 16(%1)\n"
28664- " movq 24(%0), %%mm3\n"
28665- " movntq %%mm3, 24(%1)\n"
28666- " movq 32(%0), %%mm4\n"
28667- " movntq %%mm4, 32(%1)\n"
28668- " movq 40(%0), %%mm5\n"
28669- " movntq %%mm5, 40(%1)\n"
28670- " movq 48(%0), %%mm6\n"
28671- " movntq %%mm6, 48(%1)\n"
28672- " movq 56(%0), %%mm7\n"
28673- " movntq %%mm7, 56(%1)\n"
28674+ "1: prefetch 320(%1)\n"
28675+ "2: movq (%1), %%mm0\n"
28676+ " movntq %%mm0, (%2)\n"
28677+ " movq 8(%1), %%mm1\n"
28678+ " movntq %%mm1, 8(%2)\n"
28679+ " movq 16(%1), %%mm2\n"
28680+ " movntq %%mm2, 16(%2)\n"
28681+ " movq 24(%1), %%mm3\n"
28682+ " movntq %%mm3, 24(%2)\n"
28683+ " movq 32(%1), %%mm4\n"
28684+ " movntq %%mm4, 32(%2)\n"
28685+ " movq 40(%1), %%mm5\n"
28686+ " movntq %%mm5, 40(%2)\n"
28687+ " movq 48(%1), %%mm6\n"
28688+ " movntq %%mm6, 48(%2)\n"
28689+ " movq 56(%1), %%mm7\n"
28690+ " movntq %%mm7, 56(%2)\n"
28691 ".section .fixup, \"ax\"\n"
28692- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
28693+ "3:\n"
28694+
28695+#ifdef CONFIG_PAX_KERNEXEC
28696+ " movl %%cr0, %0\n"
28697+ " movl %0, %%eax\n"
28698+ " andl $0xFFFEFFFF, %%eax\n"
28699+ " movl %%eax, %%cr0\n"
28700+#endif
28701+
28702+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
28703+
28704+#ifdef CONFIG_PAX_KERNEXEC
28705+ " movl %0, %%cr0\n"
28706+#endif
28707+
28708 " jmp 2b\n"
28709 ".previous\n"
28710- _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
28711+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
28712
28713 from += 64;
28714 to += 64;
28715@@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
28716 static void fast_copy_page(void *to, void *from)
28717 {
28718 int i;
28719+ unsigned long cr0;
28720
28721 kernel_fpu_begin();
28722
28723 __asm__ __volatile__ (
28724- "1: prefetch (%0)\n"
28725- " prefetch 64(%0)\n"
28726- " prefetch 128(%0)\n"
28727- " prefetch 192(%0)\n"
28728- " prefetch 256(%0)\n"
28729+ "1: prefetch (%1)\n"
28730+ " prefetch 64(%1)\n"
28731+ " prefetch 128(%1)\n"
28732+ " prefetch 192(%1)\n"
28733+ " prefetch 256(%1)\n"
28734 "2: \n"
28735 ".section .fixup, \"ax\"\n"
28736- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
28737+ "3: \n"
28738+
28739+#ifdef CONFIG_PAX_KERNEXEC
28740+ " movl %%cr0, %0\n"
28741+ " movl %0, %%eax\n"
28742+ " andl $0xFFFEFFFF, %%eax\n"
28743+ " movl %%eax, %%cr0\n"
28744+#endif
28745+
28746+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
28747+
28748+#ifdef CONFIG_PAX_KERNEXEC
28749+ " movl %0, %%cr0\n"
28750+#endif
28751+
28752 " jmp 2b\n"
28753 ".previous\n"
28754- _ASM_EXTABLE(1b, 3b) : : "r" (from));
28755+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
28756
28757 for (i = 0; i < 4096/64; i++) {
28758 __asm__ __volatile__ (
28759- "1: prefetch 320(%0)\n"
28760- "2: movq (%0), %%mm0\n"
28761- " movq 8(%0), %%mm1\n"
28762- " movq 16(%0), %%mm2\n"
28763- " movq 24(%0), %%mm3\n"
28764- " movq %%mm0, (%1)\n"
28765- " movq %%mm1, 8(%1)\n"
28766- " movq %%mm2, 16(%1)\n"
28767- " movq %%mm3, 24(%1)\n"
28768- " movq 32(%0), %%mm0\n"
28769- " movq 40(%0), %%mm1\n"
28770- " movq 48(%0), %%mm2\n"
28771- " movq 56(%0), %%mm3\n"
28772- " movq %%mm0, 32(%1)\n"
28773- " movq %%mm1, 40(%1)\n"
28774- " movq %%mm2, 48(%1)\n"
28775- " movq %%mm3, 56(%1)\n"
28776+ "1: prefetch 320(%1)\n"
28777+ "2: movq (%1), %%mm0\n"
28778+ " movq 8(%1), %%mm1\n"
28779+ " movq 16(%1), %%mm2\n"
28780+ " movq 24(%1), %%mm3\n"
28781+ " movq %%mm0, (%2)\n"
28782+ " movq %%mm1, 8(%2)\n"
28783+ " movq %%mm2, 16(%2)\n"
28784+ " movq %%mm3, 24(%2)\n"
28785+ " movq 32(%1), %%mm0\n"
28786+ " movq 40(%1), %%mm1\n"
28787+ " movq 48(%1), %%mm2\n"
28788+ " movq 56(%1), %%mm3\n"
28789+ " movq %%mm0, 32(%2)\n"
28790+ " movq %%mm1, 40(%2)\n"
28791+ " movq %%mm2, 48(%2)\n"
28792+ " movq %%mm3, 56(%2)\n"
28793 ".section .fixup, \"ax\"\n"
28794- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
28795+ "3:\n"
28796+
28797+#ifdef CONFIG_PAX_KERNEXEC
28798+ " movl %%cr0, %0\n"
28799+ " movl %0, %%eax\n"
28800+ " andl $0xFFFEFFFF, %%eax\n"
28801+ " movl %%eax, %%cr0\n"
28802+#endif
28803+
28804+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
28805+
28806+#ifdef CONFIG_PAX_KERNEXEC
28807+ " movl %0, %%cr0\n"
28808+#endif
28809+
28810 " jmp 2b\n"
28811 ".previous\n"
28812 _ASM_EXTABLE(1b, 3b)
28813- : : "r" (from), "r" (to) : "memory");
28814+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
28815
28816 from += 64;
28817 to += 64;
28818diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
28819index f6d13ee..aca5f0b 100644
28820--- a/arch/x86/lib/msr-reg.S
28821+++ b/arch/x86/lib/msr-reg.S
28822@@ -3,6 +3,7 @@
28823 #include <asm/dwarf2.h>
28824 #include <asm/asm.h>
28825 #include <asm/msr.h>
28826+#include <asm/alternative-asm.h>
28827
28828 #ifdef CONFIG_X86_64
28829 /*
28830@@ -16,7 +17,7 @@ ENTRY(\op\()_safe_regs)
28831 CFI_STARTPROC
28832 pushq_cfi %rbx
28833 pushq_cfi %rbp
28834- movq %rdi, %r10 /* Save pointer */
28835+ movq %rdi, %r9 /* Save pointer */
28836 xorl %r11d, %r11d /* Return value */
28837 movl (%rdi), %eax
28838 movl 4(%rdi), %ecx
28839@@ -27,16 +28,17 @@ ENTRY(\op\()_safe_regs)
28840 movl 28(%rdi), %edi
28841 CFI_REMEMBER_STATE
28842 1: \op
28843-2: movl %eax, (%r10)
28844+2: movl %eax, (%r9)
28845 movl %r11d, %eax /* Return value */
28846- movl %ecx, 4(%r10)
28847- movl %edx, 8(%r10)
28848- movl %ebx, 12(%r10)
28849- movl %ebp, 20(%r10)
28850- movl %esi, 24(%r10)
28851- movl %edi, 28(%r10)
28852+ movl %ecx, 4(%r9)
28853+ movl %edx, 8(%r9)
28854+ movl %ebx, 12(%r9)
28855+ movl %ebp, 20(%r9)
28856+ movl %esi, 24(%r9)
28857+ movl %edi, 28(%r9)
28858 popq_cfi %rbp
28859 popq_cfi %rbx
28860+ pax_force_retaddr
28861 ret
28862 3:
28863 CFI_RESTORE_STATE
28864diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
28865index fc6ba17..d4d989d 100644
28866--- a/arch/x86/lib/putuser.S
28867+++ b/arch/x86/lib/putuser.S
28868@@ -16,7 +16,9 @@
28869 #include <asm/errno.h>
28870 #include <asm/asm.h>
28871 #include <asm/smap.h>
28872-
28873+#include <asm/segment.h>
28874+#include <asm/pgtable.h>
28875+#include <asm/alternative-asm.h>
28876
28877 /*
28878 * __put_user_X
28879@@ -30,57 +32,125 @@
28880 * as they get called from within inline assembly.
28881 */
28882
28883-#define ENTER CFI_STARTPROC ; \
28884- GET_THREAD_INFO(%_ASM_BX)
28885-#define EXIT ASM_CLAC ; \
28886- ret ; \
28887+#define ENTER CFI_STARTPROC
28888+#define EXIT ASM_CLAC ; \
28889+ pax_force_retaddr ; \
28890+ ret ; \
28891 CFI_ENDPROC
28892
28893+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28894+#define _DEST %_ASM_CX,%_ASM_BX
28895+#else
28896+#define _DEST %_ASM_CX
28897+#endif
28898+
28899+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
28900+#define __copyuser_seg gs;
28901+#else
28902+#define __copyuser_seg
28903+#endif
28904+
28905 .text
28906 ENTRY(__put_user_1)
28907 ENTER
28908+
28909+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
28910+ GET_THREAD_INFO(%_ASM_BX)
28911 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
28912 jae bad_put_user
28913 ASM_STAC
28914-1: movb %al,(%_ASM_CX)
28915+
28916+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28917+ mov pax_user_shadow_base,%_ASM_BX
28918+ cmp %_ASM_BX,%_ASM_CX
28919+ jb 1234f
28920+ xor %ebx,%ebx
28921+1234:
28922+#endif
28923+
28924+#endif
28925+
28926+1: __copyuser_seg movb %al,(_DEST)
28927 xor %eax,%eax
28928 EXIT
28929 ENDPROC(__put_user_1)
28930
28931 ENTRY(__put_user_2)
28932 ENTER
28933+
28934+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
28935+ GET_THREAD_INFO(%_ASM_BX)
28936 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
28937 sub $1,%_ASM_BX
28938 cmp %_ASM_BX,%_ASM_CX
28939 jae bad_put_user
28940 ASM_STAC
28941-2: movw %ax,(%_ASM_CX)
28942+
28943+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28944+ mov pax_user_shadow_base,%_ASM_BX
28945+ cmp %_ASM_BX,%_ASM_CX
28946+ jb 1234f
28947+ xor %ebx,%ebx
28948+1234:
28949+#endif
28950+
28951+#endif
28952+
28953+2: __copyuser_seg movw %ax,(_DEST)
28954 xor %eax,%eax
28955 EXIT
28956 ENDPROC(__put_user_2)
28957
28958 ENTRY(__put_user_4)
28959 ENTER
28960+
28961+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
28962+ GET_THREAD_INFO(%_ASM_BX)
28963 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
28964 sub $3,%_ASM_BX
28965 cmp %_ASM_BX,%_ASM_CX
28966 jae bad_put_user
28967 ASM_STAC
28968-3: movl %eax,(%_ASM_CX)
28969+
28970+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28971+ mov pax_user_shadow_base,%_ASM_BX
28972+ cmp %_ASM_BX,%_ASM_CX
28973+ jb 1234f
28974+ xor %ebx,%ebx
28975+1234:
28976+#endif
28977+
28978+#endif
28979+
28980+3: __copyuser_seg movl %eax,(_DEST)
28981 xor %eax,%eax
28982 EXIT
28983 ENDPROC(__put_user_4)
28984
28985 ENTRY(__put_user_8)
28986 ENTER
28987+
28988+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
28989+ GET_THREAD_INFO(%_ASM_BX)
28990 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
28991 sub $7,%_ASM_BX
28992 cmp %_ASM_BX,%_ASM_CX
28993 jae bad_put_user
28994 ASM_STAC
28995-4: mov %_ASM_AX,(%_ASM_CX)
28996+
28997+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28998+ mov pax_user_shadow_base,%_ASM_BX
28999+ cmp %_ASM_BX,%_ASM_CX
29000+ jb 1234f
29001+ xor %ebx,%ebx
29002+1234:
29003+#endif
29004+
29005+#endif
29006+
29007+4: __copyuser_seg mov %_ASM_AX,(_DEST)
29008 #ifdef CONFIG_X86_32
29009-5: movl %edx,4(%_ASM_CX)
29010+5: __copyuser_seg movl %edx,4(_DEST)
29011 #endif
29012 xor %eax,%eax
29013 EXIT
29014diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
29015index 1cad221..de671ee 100644
29016--- a/arch/x86/lib/rwlock.S
29017+++ b/arch/x86/lib/rwlock.S
29018@@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
29019 FRAME
29020 0: LOCK_PREFIX
29021 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
29022+
29023+#ifdef CONFIG_PAX_REFCOUNT
29024+ jno 1234f
29025+ LOCK_PREFIX
29026+ WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
29027+ int $4
29028+1234:
29029+ _ASM_EXTABLE(1234b, 1234b)
29030+#endif
29031+
29032 1: rep; nop
29033 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
29034 jne 1b
29035 LOCK_PREFIX
29036 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
29037+
29038+#ifdef CONFIG_PAX_REFCOUNT
29039+ jno 1234f
29040+ LOCK_PREFIX
29041+ WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
29042+ int $4
29043+1234:
29044+ _ASM_EXTABLE(1234b, 1234b)
29045+#endif
29046+
29047 jnz 0b
29048 ENDFRAME
29049+ pax_force_retaddr
29050 ret
29051 CFI_ENDPROC
29052 END(__write_lock_failed)
29053@@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
29054 FRAME
29055 0: LOCK_PREFIX
29056 READ_LOCK_SIZE(inc) (%__lock_ptr)
29057+
29058+#ifdef CONFIG_PAX_REFCOUNT
29059+ jno 1234f
29060+ LOCK_PREFIX
29061+ READ_LOCK_SIZE(dec) (%__lock_ptr)
29062+ int $4
29063+1234:
29064+ _ASM_EXTABLE(1234b, 1234b)
29065+#endif
29066+
29067 1: rep; nop
29068 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
29069 js 1b
29070 LOCK_PREFIX
29071 READ_LOCK_SIZE(dec) (%__lock_ptr)
29072+
29073+#ifdef CONFIG_PAX_REFCOUNT
29074+ jno 1234f
29075+ LOCK_PREFIX
29076+ READ_LOCK_SIZE(inc) (%__lock_ptr)
29077+ int $4
29078+1234:
29079+ _ASM_EXTABLE(1234b, 1234b)
29080+#endif
29081+
29082 js 0b
29083 ENDFRAME
29084+ pax_force_retaddr
29085 ret
29086 CFI_ENDPROC
29087 END(__read_lock_failed)
29088diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
29089index 5dff5f0..cadebf4 100644
29090--- a/arch/x86/lib/rwsem.S
29091+++ b/arch/x86/lib/rwsem.S
29092@@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
29093 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
29094 CFI_RESTORE __ASM_REG(dx)
29095 restore_common_regs
29096+ pax_force_retaddr
29097 ret
29098 CFI_ENDPROC
29099 ENDPROC(call_rwsem_down_read_failed)
29100@@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
29101 movq %rax,%rdi
29102 call rwsem_down_write_failed
29103 restore_common_regs
29104+ pax_force_retaddr
29105 ret
29106 CFI_ENDPROC
29107 ENDPROC(call_rwsem_down_write_failed)
29108@@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
29109 movq %rax,%rdi
29110 call rwsem_wake
29111 restore_common_regs
29112-1: ret
29113+1: pax_force_retaddr
29114+ ret
29115 CFI_ENDPROC
29116 ENDPROC(call_rwsem_wake)
29117
29118@@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
29119 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
29120 CFI_RESTORE __ASM_REG(dx)
29121 restore_common_regs
29122+ pax_force_retaddr
29123 ret
29124 CFI_ENDPROC
29125 ENDPROC(call_rwsem_downgrade_wake)
29126diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
29127index a63efd6..ccecad8 100644
29128--- a/arch/x86/lib/thunk_64.S
29129+++ b/arch/x86/lib/thunk_64.S
29130@@ -8,6 +8,7 @@
29131 #include <linux/linkage.h>
29132 #include <asm/dwarf2.h>
29133 #include <asm/calling.h>
29134+#include <asm/alternative-asm.h>
29135
29136 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
29137 .macro THUNK name, func, put_ret_addr_in_rdi=0
29138@@ -41,5 +42,6 @@
29139 SAVE_ARGS
29140 restore:
29141 RESTORE_ARGS
29142+ pax_force_retaddr
29143 ret
29144 CFI_ENDPROC
29145diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
29146index 3eb18ac..4b22130 100644
29147--- a/arch/x86/lib/usercopy_32.c
29148+++ b/arch/x86/lib/usercopy_32.c
29149@@ -42,11 +42,13 @@ do { \
29150 int __d0; \
29151 might_fault(); \
29152 __asm__ __volatile__( \
29153+ __COPYUSER_SET_ES \
29154 ASM_STAC "\n" \
29155 "0: rep; stosl\n" \
29156 " movl %2,%0\n" \
29157 "1: rep; stosb\n" \
29158 "2: " ASM_CLAC "\n" \
29159+ __COPYUSER_RESTORE_ES \
29160 ".section .fixup,\"ax\"\n" \
29161 "3: lea 0(%2,%0,4),%0\n" \
29162 " jmp 2b\n" \
29163@@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
29164
29165 #ifdef CONFIG_X86_INTEL_USERCOPY
29166 static unsigned long
29167-__copy_user_intel(void __user *to, const void *from, unsigned long size)
29168+__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
29169 {
29170 int d0, d1;
29171 __asm__ __volatile__(
29172@@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
29173 " .align 2,0x90\n"
29174 "3: movl 0(%4), %%eax\n"
29175 "4: movl 4(%4), %%edx\n"
29176- "5: movl %%eax, 0(%3)\n"
29177- "6: movl %%edx, 4(%3)\n"
29178+ "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
29179+ "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
29180 "7: movl 8(%4), %%eax\n"
29181 "8: movl 12(%4),%%edx\n"
29182- "9: movl %%eax, 8(%3)\n"
29183- "10: movl %%edx, 12(%3)\n"
29184+ "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
29185+ "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
29186 "11: movl 16(%4), %%eax\n"
29187 "12: movl 20(%4), %%edx\n"
29188- "13: movl %%eax, 16(%3)\n"
29189- "14: movl %%edx, 20(%3)\n"
29190+ "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
29191+ "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
29192 "15: movl 24(%4), %%eax\n"
29193 "16: movl 28(%4), %%edx\n"
29194- "17: movl %%eax, 24(%3)\n"
29195- "18: movl %%edx, 28(%3)\n"
29196+ "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
29197+ "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
29198 "19: movl 32(%4), %%eax\n"
29199 "20: movl 36(%4), %%edx\n"
29200- "21: movl %%eax, 32(%3)\n"
29201- "22: movl %%edx, 36(%3)\n"
29202+ "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
29203+ "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
29204 "23: movl 40(%4), %%eax\n"
29205 "24: movl 44(%4), %%edx\n"
29206- "25: movl %%eax, 40(%3)\n"
29207- "26: movl %%edx, 44(%3)\n"
29208+ "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
29209+ "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
29210 "27: movl 48(%4), %%eax\n"
29211 "28: movl 52(%4), %%edx\n"
29212- "29: movl %%eax, 48(%3)\n"
29213- "30: movl %%edx, 52(%3)\n"
29214+ "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
29215+ "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
29216 "31: movl 56(%4), %%eax\n"
29217 "32: movl 60(%4), %%edx\n"
29218- "33: movl %%eax, 56(%3)\n"
29219- "34: movl %%edx, 60(%3)\n"
29220+ "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
29221+ "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
29222 " addl $-64, %0\n"
29223 " addl $64, %4\n"
29224 " addl $64, %3\n"
29225@@ -149,10 +151,116 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
29226 " shrl $2, %0\n"
29227 " andl $3, %%eax\n"
29228 " cld\n"
29229+ __COPYUSER_SET_ES
29230 "99: rep; movsl\n"
29231 "36: movl %%eax, %0\n"
29232 "37: rep; movsb\n"
29233 "100:\n"
29234+ __COPYUSER_RESTORE_ES
29235+ ".section .fixup,\"ax\"\n"
29236+ "101: lea 0(%%eax,%0,4),%0\n"
29237+ " jmp 100b\n"
29238+ ".previous\n"
29239+ _ASM_EXTABLE(1b,100b)
29240+ _ASM_EXTABLE(2b,100b)
29241+ _ASM_EXTABLE(3b,100b)
29242+ _ASM_EXTABLE(4b,100b)
29243+ _ASM_EXTABLE(5b,100b)
29244+ _ASM_EXTABLE(6b,100b)
29245+ _ASM_EXTABLE(7b,100b)
29246+ _ASM_EXTABLE(8b,100b)
29247+ _ASM_EXTABLE(9b,100b)
29248+ _ASM_EXTABLE(10b,100b)
29249+ _ASM_EXTABLE(11b,100b)
29250+ _ASM_EXTABLE(12b,100b)
29251+ _ASM_EXTABLE(13b,100b)
29252+ _ASM_EXTABLE(14b,100b)
29253+ _ASM_EXTABLE(15b,100b)
29254+ _ASM_EXTABLE(16b,100b)
29255+ _ASM_EXTABLE(17b,100b)
29256+ _ASM_EXTABLE(18b,100b)
29257+ _ASM_EXTABLE(19b,100b)
29258+ _ASM_EXTABLE(20b,100b)
29259+ _ASM_EXTABLE(21b,100b)
29260+ _ASM_EXTABLE(22b,100b)
29261+ _ASM_EXTABLE(23b,100b)
29262+ _ASM_EXTABLE(24b,100b)
29263+ _ASM_EXTABLE(25b,100b)
29264+ _ASM_EXTABLE(26b,100b)
29265+ _ASM_EXTABLE(27b,100b)
29266+ _ASM_EXTABLE(28b,100b)
29267+ _ASM_EXTABLE(29b,100b)
29268+ _ASM_EXTABLE(30b,100b)
29269+ _ASM_EXTABLE(31b,100b)
29270+ _ASM_EXTABLE(32b,100b)
29271+ _ASM_EXTABLE(33b,100b)
29272+ _ASM_EXTABLE(34b,100b)
29273+ _ASM_EXTABLE(35b,100b)
29274+ _ASM_EXTABLE(36b,100b)
29275+ _ASM_EXTABLE(37b,100b)
29276+ _ASM_EXTABLE(99b,101b)
29277+ : "=&c"(size), "=&D" (d0), "=&S" (d1)
29278+ : "1"(to), "2"(from), "0"(size)
29279+ : "eax", "edx", "memory");
29280+ return size;
29281+}
29282+
29283+static unsigned long
29284+__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
29285+{
29286+ int d0, d1;
29287+ __asm__ __volatile__(
29288+ " .align 2,0x90\n"
29289+ "1: "__copyuser_seg" movl 32(%4), %%eax\n"
29290+ " cmpl $67, %0\n"
29291+ " jbe 3f\n"
29292+ "2: "__copyuser_seg" movl 64(%4), %%eax\n"
29293+ " .align 2,0x90\n"
29294+ "3: "__copyuser_seg" movl 0(%4), %%eax\n"
29295+ "4: "__copyuser_seg" movl 4(%4), %%edx\n"
29296+ "5: movl %%eax, 0(%3)\n"
29297+ "6: movl %%edx, 4(%3)\n"
29298+ "7: "__copyuser_seg" movl 8(%4), %%eax\n"
29299+ "8: "__copyuser_seg" movl 12(%4),%%edx\n"
29300+ "9: movl %%eax, 8(%3)\n"
29301+ "10: movl %%edx, 12(%3)\n"
29302+ "11: "__copyuser_seg" movl 16(%4), %%eax\n"
29303+ "12: "__copyuser_seg" movl 20(%4), %%edx\n"
29304+ "13: movl %%eax, 16(%3)\n"
29305+ "14: movl %%edx, 20(%3)\n"
29306+ "15: "__copyuser_seg" movl 24(%4), %%eax\n"
29307+ "16: "__copyuser_seg" movl 28(%4), %%edx\n"
29308+ "17: movl %%eax, 24(%3)\n"
29309+ "18: movl %%edx, 28(%3)\n"
29310+ "19: "__copyuser_seg" movl 32(%4), %%eax\n"
29311+ "20: "__copyuser_seg" movl 36(%4), %%edx\n"
29312+ "21: movl %%eax, 32(%3)\n"
29313+ "22: movl %%edx, 36(%3)\n"
29314+ "23: "__copyuser_seg" movl 40(%4), %%eax\n"
29315+ "24: "__copyuser_seg" movl 44(%4), %%edx\n"
29316+ "25: movl %%eax, 40(%3)\n"
29317+ "26: movl %%edx, 44(%3)\n"
29318+ "27: "__copyuser_seg" movl 48(%4), %%eax\n"
29319+ "28: "__copyuser_seg" movl 52(%4), %%edx\n"
29320+ "29: movl %%eax, 48(%3)\n"
29321+ "30: movl %%edx, 52(%3)\n"
29322+ "31: "__copyuser_seg" movl 56(%4), %%eax\n"
29323+ "32: "__copyuser_seg" movl 60(%4), %%edx\n"
29324+ "33: movl %%eax, 56(%3)\n"
29325+ "34: movl %%edx, 60(%3)\n"
29326+ " addl $-64, %0\n"
29327+ " addl $64, %4\n"
29328+ " addl $64, %3\n"
29329+ " cmpl $63, %0\n"
29330+ " ja 1b\n"
29331+ "35: movl %0, %%eax\n"
29332+ " shrl $2, %0\n"
29333+ " andl $3, %%eax\n"
29334+ " cld\n"
29335+ "99: rep; "__copyuser_seg" movsl\n"
29336+ "36: movl %%eax, %0\n"
29337+ "37: rep; "__copyuser_seg" movsb\n"
29338+ "100:\n"
29339 ".section .fixup,\"ax\"\n"
29340 "101: lea 0(%%eax,%0,4),%0\n"
29341 " jmp 100b\n"
29342@@ -207,41 +315,41 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
29343 int d0, d1;
29344 __asm__ __volatile__(
29345 " .align 2,0x90\n"
29346- "0: movl 32(%4), %%eax\n"
29347+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
29348 " cmpl $67, %0\n"
29349 " jbe 2f\n"
29350- "1: movl 64(%4), %%eax\n"
29351+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
29352 " .align 2,0x90\n"
29353- "2: movl 0(%4), %%eax\n"
29354- "21: movl 4(%4), %%edx\n"
29355+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
29356+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
29357 " movl %%eax, 0(%3)\n"
29358 " movl %%edx, 4(%3)\n"
29359- "3: movl 8(%4), %%eax\n"
29360- "31: movl 12(%4),%%edx\n"
29361+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
29362+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
29363 " movl %%eax, 8(%3)\n"
29364 " movl %%edx, 12(%3)\n"
29365- "4: movl 16(%4), %%eax\n"
29366- "41: movl 20(%4), %%edx\n"
29367+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
29368+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
29369 " movl %%eax, 16(%3)\n"
29370 " movl %%edx, 20(%3)\n"
29371- "10: movl 24(%4), %%eax\n"
29372- "51: movl 28(%4), %%edx\n"
29373+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
29374+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
29375 " movl %%eax, 24(%3)\n"
29376 " movl %%edx, 28(%3)\n"
29377- "11: movl 32(%4), %%eax\n"
29378- "61: movl 36(%4), %%edx\n"
29379+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
29380+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
29381 " movl %%eax, 32(%3)\n"
29382 " movl %%edx, 36(%3)\n"
29383- "12: movl 40(%4), %%eax\n"
29384- "71: movl 44(%4), %%edx\n"
29385+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
29386+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
29387 " movl %%eax, 40(%3)\n"
29388 " movl %%edx, 44(%3)\n"
29389- "13: movl 48(%4), %%eax\n"
29390- "81: movl 52(%4), %%edx\n"
29391+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
29392+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
29393 " movl %%eax, 48(%3)\n"
29394 " movl %%edx, 52(%3)\n"
29395- "14: movl 56(%4), %%eax\n"
29396- "91: movl 60(%4), %%edx\n"
29397+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
29398+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
29399 " movl %%eax, 56(%3)\n"
29400 " movl %%edx, 60(%3)\n"
29401 " addl $-64, %0\n"
29402@@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
29403 " shrl $2, %0\n"
29404 " andl $3, %%eax\n"
29405 " cld\n"
29406- "6: rep; movsl\n"
29407+ "6: rep; "__copyuser_seg" movsl\n"
29408 " movl %%eax,%0\n"
29409- "7: rep; movsb\n"
29410+ "7: rep; "__copyuser_seg" movsb\n"
29411 "8:\n"
29412 ".section .fixup,\"ax\"\n"
29413 "9: lea 0(%%eax,%0,4),%0\n"
29414@@ -305,41 +413,41 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
29415
29416 __asm__ __volatile__(
29417 " .align 2,0x90\n"
29418- "0: movl 32(%4), %%eax\n"
29419+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
29420 " cmpl $67, %0\n"
29421 " jbe 2f\n"
29422- "1: movl 64(%4), %%eax\n"
29423+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
29424 " .align 2,0x90\n"
29425- "2: movl 0(%4), %%eax\n"
29426- "21: movl 4(%4), %%edx\n"
29427+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
29428+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
29429 " movnti %%eax, 0(%3)\n"
29430 " movnti %%edx, 4(%3)\n"
29431- "3: movl 8(%4), %%eax\n"
29432- "31: movl 12(%4),%%edx\n"
29433+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
29434+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
29435 " movnti %%eax, 8(%3)\n"
29436 " movnti %%edx, 12(%3)\n"
29437- "4: movl 16(%4), %%eax\n"
29438- "41: movl 20(%4), %%edx\n"
29439+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
29440+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
29441 " movnti %%eax, 16(%3)\n"
29442 " movnti %%edx, 20(%3)\n"
29443- "10: movl 24(%4), %%eax\n"
29444- "51: movl 28(%4), %%edx\n"
29445+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
29446+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
29447 " movnti %%eax, 24(%3)\n"
29448 " movnti %%edx, 28(%3)\n"
29449- "11: movl 32(%4), %%eax\n"
29450- "61: movl 36(%4), %%edx\n"
29451+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
29452+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
29453 " movnti %%eax, 32(%3)\n"
29454 " movnti %%edx, 36(%3)\n"
29455- "12: movl 40(%4), %%eax\n"
29456- "71: movl 44(%4), %%edx\n"
29457+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
29458+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
29459 " movnti %%eax, 40(%3)\n"
29460 " movnti %%edx, 44(%3)\n"
29461- "13: movl 48(%4), %%eax\n"
29462- "81: movl 52(%4), %%edx\n"
29463+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
29464+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
29465 " movnti %%eax, 48(%3)\n"
29466 " movnti %%edx, 52(%3)\n"
29467- "14: movl 56(%4), %%eax\n"
29468- "91: movl 60(%4), %%edx\n"
29469+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
29470+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
29471 " movnti %%eax, 56(%3)\n"
29472 " movnti %%edx, 60(%3)\n"
29473 " addl $-64, %0\n"
29474@@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
29475 " shrl $2, %0\n"
29476 " andl $3, %%eax\n"
29477 " cld\n"
29478- "6: rep; movsl\n"
29479+ "6: rep; "__copyuser_seg" movsl\n"
29480 " movl %%eax,%0\n"
29481- "7: rep; movsb\n"
29482+ "7: rep; "__copyuser_seg" movsb\n"
29483 "8:\n"
29484 ".section .fixup,\"ax\"\n"
29485 "9: lea 0(%%eax,%0,4),%0\n"
29486@@ -399,41 +507,41 @@ static unsigned long __copy_user_intel_nocache(void *to,
29487
29488 __asm__ __volatile__(
29489 " .align 2,0x90\n"
29490- "0: movl 32(%4), %%eax\n"
29491+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
29492 " cmpl $67, %0\n"
29493 " jbe 2f\n"
29494- "1: movl 64(%4), %%eax\n"
29495+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
29496 " .align 2,0x90\n"
29497- "2: movl 0(%4), %%eax\n"
29498- "21: movl 4(%4), %%edx\n"
29499+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
29500+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
29501 " movnti %%eax, 0(%3)\n"
29502 " movnti %%edx, 4(%3)\n"
29503- "3: movl 8(%4), %%eax\n"
29504- "31: movl 12(%4),%%edx\n"
29505+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
29506+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
29507 " movnti %%eax, 8(%3)\n"
29508 " movnti %%edx, 12(%3)\n"
29509- "4: movl 16(%4), %%eax\n"
29510- "41: movl 20(%4), %%edx\n"
29511+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
29512+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
29513 " movnti %%eax, 16(%3)\n"
29514 " movnti %%edx, 20(%3)\n"
29515- "10: movl 24(%4), %%eax\n"
29516- "51: movl 28(%4), %%edx\n"
29517+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
29518+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
29519 " movnti %%eax, 24(%3)\n"
29520 " movnti %%edx, 28(%3)\n"
29521- "11: movl 32(%4), %%eax\n"
29522- "61: movl 36(%4), %%edx\n"
29523+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
29524+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
29525 " movnti %%eax, 32(%3)\n"
29526 " movnti %%edx, 36(%3)\n"
29527- "12: movl 40(%4), %%eax\n"
29528- "71: movl 44(%4), %%edx\n"
29529+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
29530+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
29531 " movnti %%eax, 40(%3)\n"
29532 " movnti %%edx, 44(%3)\n"
29533- "13: movl 48(%4), %%eax\n"
29534- "81: movl 52(%4), %%edx\n"
29535+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
29536+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
29537 " movnti %%eax, 48(%3)\n"
29538 " movnti %%edx, 52(%3)\n"
29539- "14: movl 56(%4), %%eax\n"
29540- "91: movl 60(%4), %%edx\n"
29541+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
29542+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
29543 " movnti %%eax, 56(%3)\n"
29544 " movnti %%edx, 60(%3)\n"
29545 " addl $-64, %0\n"
29546@@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
29547 " shrl $2, %0\n"
29548 " andl $3, %%eax\n"
29549 " cld\n"
29550- "6: rep; movsl\n"
29551+ "6: rep; "__copyuser_seg" movsl\n"
29552 " movl %%eax,%0\n"
29553- "7: rep; movsb\n"
29554+ "7: rep; "__copyuser_seg" movsb\n"
29555 "8:\n"
29556 ".section .fixup,\"ax\"\n"
29557 "9: lea 0(%%eax,%0,4),%0\n"
29558@@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
29559 */
29560 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
29561 unsigned long size);
29562-unsigned long __copy_user_intel(void __user *to, const void *from,
29563+unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
29564+ unsigned long size);
29565+unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
29566 unsigned long size);
29567 unsigned long __copy_user_zeroing_intel_nocache(void *to,
29568 const void __user *from, unsigned long size);
29569 #endif /* CONFIG_X86_INTEL_USERCOPY */
29570
29571 /* Generic arbitrary sized copy. */
29572-#define __copy_user(to, from, size) \
29573+#define __copy_user(to, from, size, prefix, set, restore) \
29574 do { \
29575 int __d0, __d1, __d2; \
29576 __asm__ __volatile__( \
29577+ set \
29578 " cmp $7,%0\n" \
29579 " jbe 1f\n" \
29580 " movl %1,%0\n" \
29581 " negl %0\n" \
29582 " andl $7,%0\n" \
29583 " subl %0,%3\n" \
29584- "4: rep; movsb\n" \
29585+ "4: rep; "prefix"movsb\n" \
29586 " movl %3,%0\n" \
29587 " shrl $2,%0\n" \
29588 " andl $3,%3\n" \
29589 " .align 2,0x90\n" \
29590- "0: rep; movsl\n" \
29591+ "0: rep; "prefix"movsl\n" \
29592 " movl %3,%0\n" \
29593- "1: rep; movsb\n" \
29594+ "1: rep; "prefix"movsb\n" \
29595 "2:\n" \
29596+ restore \
29597 ".section .fixup,\"ax\"\n" \
29598 "5: addl %3,%0\n" \
29599 " jmp 2b\n" \
29600@@ -538,14 +650,14 @@ do { \
29601 " negl %0\n" \
29602 " andl $7,%0\n" \
29603 " subl %0,%3\n" \
29604- "4: rep; movsb\n" \
29605+ "4: rep; "__copyuser_seg"movsb\n" \
29606 " movl %3,%0\n" \
29607 " shrl $2,%0\n" \
29608 " andl $3,%3\n" \
29609 " .align 2,0x90\n" \
29610- "0: rep; movsl\n" \
29611+ "0: rep; "__copyuser_seg"movsl\n" \
29612 " movl %3,%0\n" \
29613- "1: rep; movsb\n" \
29614+ "1: rep; "__copyuser_seg"movsb\n" \
29615 "2:\n" \
29616 ".section .fixup,\"ax\"\n" \
29617 "5: addl %3,%0\n" \
29618@@ -572,9 +684,9 @@ unsigned long __copy_to_user_ll(void __user *to, const void *from,
29619 {
29620 stac();
29621 if (movsl_is_ok(to, from, n))
29622- __copy_user(to, from, n);
29623+ __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
29624 else
29625- n = __copy_user_intel(to, from, n);
29626+ n = __generic_copy_to_user_intel(to, from, n);
29627 clac();
29628 return n;
29629 }
29630@@ -598,10 +710,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
29631 {
29632 stac();
29633 if (movsl_is_ok(to, from, n))
29634- __copy_user(to, from, n);
29635+ __copy_user(to, from, n, __copyuser_seg, "", "");
29636 else
29637- n = __copy_user_intel((void __user *)to,
29638- (const void *)from, n);
29639+ n = __generic_copy_from_user_intel(to, from, n);
29640 clac();
29641 return n;
29642 }
29643@@ -632,60 +743,38 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
29644 if (n > 64 && cpu_has_xmm2)
29645 n = __copy_user_intel_nocache(to, from, n);
29646 else
29647- __copy_user(to, from, n);
29648+ __copy_user(to, from, n, __copyuser_seg, "", "");
29649 #else
29650- __copy_user(to, from, n);
29651+ __copy_user(to, from, n, __copyuser_seg, "", "");
29652 #endif
29653 clac();
29654 return n;
29655 }
29656 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
29657
29658-/**
29659- * copy_to_user: - Copy a block of data into user space.
29660- * @to: Destination address, in user space.
29661- * @from: Source address, in kernel space.
29662- * @n: Number of bytes to copy.
29663- *
29664- * Context: User context only. This function may sleep.
29665- *
29666- * Copy data from kernel space to user space.
29667- *
29668- * Returns number of bytes that could not be copied.
29669- * On success, this will be zero.
29670- */
29671-unsigned long
29672-copy_to_user(void __user *to, const void *from, unsigned long n)
29673+#ifdef CONFIG_PAX_MEMORY_UDEREF
29674+void __set_fs(mm_segment_t x)
29675 {
29676- if (access_ok(VERIFY_WRITE, to, n))
29677- n = __copy_to_user(to, from, n);
29678- return n;
29679+ switch (x.seg) {
29680+ case 0:
29681+ loadsegment(gs, 0);
29682+ break;
29683+ case TASK_SIZE_MAX:
29684+ loadsegment(gs, __USER_DS);
29685+ break;
29686+ case -1UL:
29687+ loadsegment(gs, __KERNEL_DS);
29688+ break;
29689+ default:
29690+ BUG();
29691+ }
29692 }
29693-EXPORT_SYMBOL(copy_to_user);
29694+EXPORT_SYMBOL(__set_fs);
29695
29696-/**
29697- * copy_from_user: - Copy a block of data from user space.
29698- * @to: Destination address, in kernel space.
29699- * @from: Source address, in user space.
29700- * @n: Number of bytes to copy.
29701- *
29702- * Context: User context only. This function may sleep.
29703- *
29704- * Copy data from user space to kernel space.
29705- *
29706- * Returns number of bytes that could not be copied.
29707- * On success, this will be zero.
29708- *
29709- * If some data could not be copied, this function will pad the copied
29710- * data to the requested size using zero bytes.
29711- */
29712-unsigned long
29713-_copy_from_user(void *to, const void __user *from, unsigned long n)
29714+void set_fs(mm_segment_t x)
29715 {
29716- if (access_ok(VERIFY_READ, from, n))
29717- n = __copy_from_user(to, from, n);
29718- else
29719- memset(to, 0, n);
29720- return n;
29721+ current_thread_info()->addr_limit = x;
29722+ __set_fs(x);
29723 }
29724-EXPORT_SYMBOL(_copy_from_user);
29725+EXPORT_SYMBOL(set_fs);
29726+#endif
29727diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
29728index c905e89..01ab928 100644
29729--- a/arch/x86/lib/usercopy_64.c
29730+++ b/arch/x86/lib/usercopy_64.c
29731@@ -18,6 +18,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
29732 might_fault();
29733 /* no memory constraint because it doesn't change any memory gcc knows
29734 about */
29735+ pax_open_userland();
29736 stac();
29737 asm volatile(
29738 " testq %[size8],%[size8]\n"
29739@@ -39,9 +40,10 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
29740 _ASM_EXTABLE(0b,3b)
29741 _ASM_EXTABLE(1b,2b)
29742 : [size8] "=&c"(size), [dst] "=&D" (__d0)
29743- : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
29744+ : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
29745 [zero] "r" (0UL), [eight] "r" (8UL));
29746 clac();
29747+ pax_close_userland();
29748 return size;
29749 }
29750 EXPORT_SYMBOL(__clear_user);
29751@@ -54,12 +56,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
29752 }
29753 EXPORT_SYMBOL(clear_user);
29754
29755-unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
29756+unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
29757 {
29758- if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
29759- return copy_user_generic((__force void *)to, (__force void *)from, len);
29760- }
29761- return len;
29762+ if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
29763+ return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
29764+ return len;
29765 }
29766 EXPORT_SYMBOL(copy_in_user);
29767
29768@@ -69,11 +70,13 @@ EXPORT_SYMBOL(copy_in_user);
29769 * it is not necessary to optimize tail handling.
29770 */
29771 __visible unsigned long
29772-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
29773+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
29774 {
29775 char c;
29776 unsigned zero_len;
29777
29778+ clac();
29779+ pax_close_userland();
29780 for (; len; --len, to++) {
29781 if (__get_user_nocheck(c, from++, sizeof(char)))
29782 break;
29783@@ -84,6 +87,5 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
29784 for (c = 0, zero_len = len; zerorest && zero_len; --zero_len)
29785 if (__put_user_nocheck(c, to++, sizeof(char)))
29786 break;
29787- clac();
29788 return len;
29789 }
29790diff --git a/arch/x86/mm/Makefile b/arch/x86/mm/Makefile
29791index 23d8e5f..9ccc13a 100644
29792--- a/arch/x86/mm/Makefile
29793+++ b/arch/x86/mm/Makefile
29794@@ -28,3 +28,7 @@ obj-$(CONFIG_ACPI_NUMA) += srat.o
29795 obj-$(CONFIG_NUMA_EMU) += numa_emulation.o
29796
29797 obj-$(CONFIG_MEMTEST) += memtest.o
29798+
29799+quote:="
29800+obj-$(CONFIG_X86_64) += uderef_64.o
29801+CFLAGS_uderef_64.o := $(subst $(quote),,$(CONFIG_ARCH_HWEIGHT_CFLAGS))
29802diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
29803index 903ec1e..c4166b2 100644
29804--- a/arch/x86/mm/extable.c
29805+++ b/arch/x86/mm/extable.c
29806@@ -6,12 +6,24 @@
29807 static inline unsigned long
29808 ex_insn_addr(const struct exception_table_entry *x)
29809 {
29810- return (unsigned long)&x->insn + x->insn;
29811+ unsigned long reloc = 0;
29812+
29813+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
29814+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
29815+#endif
29816+
29817+ return (unsigned long)&x->insn + x->insn + reloc;
29818 }
29819 static inline unsigned long
29820 ex_fixup_addr(const struct exception_table_entry *x)
29821 {
29822- return (unsigned long)&x->fixup + x->fixup;
29823+ unsigned long reloc = 0;
29824+
29825+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
29826+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
29827+#endif
29828+
29829+ return (unsigned long)&x->fixup + x->fixup + reloc;
29830 }
29831
29832 int fixup_exception(struct pt_regs *regs)
29833@@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
29834 unsigned long new_ip;
29835
29836 #ifdef CONFIG_PNPBIOS
29837- if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
29838+ if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
29839 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
29840 extern u32 pnp_bios_is_utter_crap;
29841 pnp_bios_is_utter_crap = 1;
29842@@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
29843 i += 4;
29844 p->fixup -= i;
29845 i += 4;
29846+
29847+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
29848+ BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
29849+ p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
29850+ p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
29851+#endif
29852+
29853 }
29854 }
29855
29856diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
29857index 3aaeffc..42ea9fb 100644
29858--- a/arch/x86/mm/fault.c
29859+++ b/arch/x86/mm/fault.c
29860@@ -14,11 +14,18 @@
29861 #include <linux/hugetlb.h> /* hstate_index_to_shift */
29862 #include <linux/prefetch.h> /* prefetchw */
29863 #include <linux/context_tracking.h> /* exception_enter(), ... */
29864+#include <linux/unistd.h>
29865+#include <linux/compiler.h>
29866
29867 #include <asm/traps.h> /* dotraplinkage, ... */
29868 #include <asm/pgalloc.h> /* pgd_*(), ... */
29869 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
29870 #include <asm/fixmap.h> /* VSYSCALL_START */
29871+#include <asm/tlbflush.h>
29872+
29873+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29874+#include <asm/stacktrace.h>
29875+#endif
29876
29877 /*
29878 * Page fault error code bits:
29879@@ -56,7 +63,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
29880 int ret = 0;
29881
29882 /* kprobe_running() needs smp_processor_id() */
29883- if (kprobes_built_in() && !user_mode_vm(regs)) {
29884+ if (kprobes_built_in() && !user_mode(regs)) {
29885 preempt_disable();
29886 if (kprobe_running() && kprobe_fault_handler(regs, 14))
29887 ret = 1;
29888@@ -117,7 +124,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
29889 return !instr_lo || (instr_lo>>1) == 1;
29890 case 0x00:
29891 /* Prefetch instruction is 0x0F0D or 0x0F18 */
29892- if (probe_kernel_address(instr, opcode))
29893+ if (user_mode(regs)) {
29894+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
29895+ return 0;
29896+ } else if (probe_kernel_address(instr, opcode))
29897 return 0;
29898
29899 *prefetch = (instr_lo == 0xF) &&
29900@@ -151,7 +161,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
29901 while (instr < max_instr) {
29902 unsigned char opcode;
29903
29904- if (probe_kernel_address(instr, opcode))
29905+ if (user_mode(regs)) {
29906+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
29907+ break;
29908+ } else if (probe_kernel_address(instr, opcode))
29909 break;
29910
29911 instr++;
29912@@ -182,6 +195,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
29913 force_sig_info(si_signo, &info, tsk);
29914 }
29915
29916+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
29917+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
29918+#endif
29919+
29920+#ifdef CONFIG_PAX_EMUTRAMP
29921+static int pax_handle_fetch_fault(struct pt_regs *regs);
29922+#endif
29923+
29924+#ifdef CONFIG_PAX_PAGEEXEC
29925+static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
29926+{
29927+ pgd_t *pgd;
29928+ pud_t *pud;
29929+ pmd_t *pmd;
29930+
29931+ pgd = pgd_offset(mm, address);
29932+ if (!pgd_present(*pgd))
29933+ return NULL;
29934+ pud = pud_offset(pgd, address);
29935+ if (!pud_present(*pud))
29936+ return NULL;
29937+ pmd = pmd_offset(pud, address);
29938+ if (!pmd_present(*pmd))
29939+ return NULL;
29940+ return pmd;
29941+}
29942+#endif
29943+
29944 DEFINE_SPINLOCK(pgd_lock);
29945 LIST_HEAD(pgd_list);
29946
29947@@ -232,10 +273,27 @@ void vmalloc_sync_all(void)
29948 for (address = VMALLOC_START & PMD_MASK;
29949 address >= TASK_SIZE && address < FIXADDR_TOP;
29950 address += PMD_SIZE) {
29951+
29952+#ifdef CONFIG_PAX_PER_CPU_PGD
29953+ unsigned long cpu;
29954+#else
29955 struct page *page;
29956+#endif
29957
29958 spin_lock(&pgd_lock);
29959+
29960+#ifdef CONFIG_PAX_PER_CPU_PGD
29961+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
29962+ pgd_t *pgd = get_cpu_pgd(cpu, user);
29963+ pmd_t *ret;
29964+
29965+ ret = vmalloc_sync_one(pgd, address);
29966+ if (!ret)
29967+ break;
29968+ pgd = get_cpu_pgd(cpu, kernel);
29969+#else
29970 list_for_each_entry(page, &pgd_list, lru) {
29971+ pgd_t *pgd;
29972 spinlock_t *pgt_lock;
29973 pmd_t *ret;
29974
29975@@ -243,8 +301,14 @@ void vmalloc_sync_all(void)
29976 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
29977
29978 spin_lock(pgt_lock);
29979- ret = vmalloc_sync_one(page_address(page), address);
29980+ pgd = page_address(page);
29981+#endif
29982+
29983+ ret = vmalloc_sync_one(pgd, address);
29984+
29985+#ifndef CONFIG_PAX_PER_CPU_PGD
29986 spin_unlock(pgt_lock);
29987+#endif
29988
29989 if (!ret)
29990 break;
29991@@ -278,6 +342,12 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
29992 * an interrupt in the middle of a task switch..
29993 */
29994 pgd_paddr = read_cr3();
29995+
29996+#ifdef CONFIG_PAX_PER_CPU_PGD
29997+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (pgd_paddr & __PHYSICAL_MASK));
29998+ vmalloc_sync_one(__va(pgd_paddr + PAGE_SIZE), address);
29999+#endif
30000+
30001 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
30002 if (!pmd_k)
30003 return -1;
30004@@ -373,11 +443,25 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
30005 * happen within a race in page table update. In the later
30006 * case just flush:
30007 */
30008- pgd = pgd_offset(current->active_mm, address);
30009+
30010 pgd_ref = pgd_offset_k(address);
30011 if (pgd_none(*pgd_ref))
30012 return -1;
30013
30014+#ifdef CONFIG_PAX_PER_CPU_PGD
30015+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (read_cr3() & __PHYSICAL_MASK));
30016+ pgd = pgd_offset_cpu(smp_processor_id(), user, address);
30017+ if (pgd_none(*pgd)) {
30018+ set_pgd(pgd, *pgd_ref);
30019+ arch_flush_lazy_mmu_mode();
30020+ } else {
30021+ BUG_ON(pgd_page_vaddr(*pgd) != pgd_page_vaddr(*pgd_ref));
30022+ }
30023+ pgd = pgd_offset_cpu(smp_processor_id(), kernel, address);
30024+#else
30025+ pgd = pgd_offset(current->active_mm, address);
30026+#endif
30027+
30028 if (pgd_none(*pgd)) {
30029 set_pgd(pgd, *pgd_ref);
30030 arch_flush_lazy_mmu_mode();
30031@@ -543,7 +627,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
30032 static int is_errata100(struct pt_regs *regs, unsigned long address)
30033 {
30034 #ifdef CONFIG_X86_64
30035- if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
30036+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
30037 return 1;
30038 #endif
30039 return 0;
30040@@ -570,7 +654,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
30041 }
30042
30043 static const char nx_warning[] = KERN_CRIT
30044-"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
30045+"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
30046
30047 static void
30048 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
30049@@ -579,15 +663,27 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
30050 if (!oops_may_print())
30051 return;
30052
30053- if (error_code & PF_INSTR) {
30054+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
30055 unsigned int level;
30056
30057 pte_t *pte = lookup_address(address, &level);
30058
30059 if (pte && pte_present(*pte) && !pte_exec(*pte))
30060- printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
30061+ printk(nx_warning, from_kuid_munged(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
30062 }
30063
30064+#ifdef CONFIG_PAX_KERNEXEC
30065+ if (init_mm.start_code <= address && address < init_mm.end_code) {
30066+ if (current->signal->curr_ip)
30067+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
30068+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
30069+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
30070+ else
30071+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
30072+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
30073+ }
30074+#endif
30075+
30076 printk(KERN_ALERT "BUG: unable to handle kernel ");
30077 if (address < PAGE_SIZE)
30078 printk(KERN_CONT "NULL pointer dereference");
30079@@ -750,6 +846,22 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
30080 return;
30081 }
30082 #endif
30083+
30084+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
30085+ if (pax_is_fetch_fault(regs, error_code, address)) {
30086+
30087+#ifdef CONFIG_PAX_EMUTRAMP
30088+ switch (pax_handle_fetch_fault(regs)) {
30089+ case 2:
30090+ return;
30091+ }
30092+#endif
30093+
30094+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
30095+ do_group_exit(SIGKILL);
30096+ }
30097+#endif
30098+
30099 /* Kernel addresses are always protection faults: */
30100 if (address >= TASK_SIZE)
30101 error_code |= PF_PROT;
30102@@ -835,7 +947,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
30103 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
30104 printk(KERN_ERR
30105 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
30106- tsk->comm, tsk->pid, address);
30107+ tsk->comm, task_pid_nr(tsk), address);
30108 code = BUS_MCEERR_AR;
30109 }
30110 #endif
30111@@ -889,6 +1001,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
30112 return 1;
30113 }
30114
30115+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
30116+static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
30117+{
30118+ pte_t *pte;
30119+ pmd_t *pmd;
30120+ spinlock_t *ptl;
30121+ unsigned char pte_mask;
30122+
30123+ if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
30124+ !(mm->pax_flags & MF_PAX_PAGEEXEC))
30125+ return 0;
30126+
30127+ /* PaX: it's our fault, let's handle it if we can */
30128+
30129+ /* PaX: take a look at read faults before acquiring any locks */
30130+ if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
30131+ /* instruction fetch attempt from a protected page in user mode */
30132+ up_read(&mm->mmap_sem);
30133+
30134+#ifdef CONFIG_PAX_EMUTRAMP
30135+ switch (pax_handle_fetch_fault(regs)) {
30136+ case 2:
30137+ return 1;
30138+ }
30139+#endif
30140+
30141+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
30142+ do_group_exit(SIGKILL);
30143+ }
30144+
30145+ pmd = pax_get_pmd(mm, address);
30146+ if (unlikely(!pmd))
30147+ return 0;
30148+
30149+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
30150+ if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
30151+ pte_unmap_unlock(pte, ptl);
30152+ return 0;
30153+ }
30154+
30155+ if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
30156+ /* write attempt to a protected page in user mode */
30157+ pte_unmap_unlock(pte, ptl);
30158+ return 0;
30159+ }
30160+
30161+#ifdef CONFIG_SMP
30162+ if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
30163+#else
30164+ if (likely(address > get_limit(regs->cs)))
30165+#endif
30166+ {
30167+ set_pte(pte, pte_mkread(*pte));
30168+ __flush_tlb_one(address);
30169+ pte_unmap_unlock(pte, ptl);
30170+ up_read(&mm->mmap_sem);
30171+ return 1;
30172+ }
30173+
30174+ pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
30175+
30176+ /*
30177+ * PaX: fill DTLB with user rights and retry
30178+ */
30179+ __asm__ __volatile__ (
30180+ "orb %2,(%1)\n"
30181+#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
30182+/*
30183+ * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
30184+ * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
30185+ * page fault when examined during a TLB load attempt. this is true not only
30186+ * for PTEs holding a non-present entry but also present entries that will
30187+ * raise a page fault (such as those set up by PaX, or the copy-on-write
30188+ * mechanism). in effect it means that we do *not* need to flush the TLBs
30189+ * for our target pages since their PTEs are simply not in the TLBs at all.
30190+
30191+ * the best thing in omitting it is that we gain around 15-20% speed in the
30192+ * fast path of the page fault handler and can get rid of tracing since we
30193+ * can no longer flush unintended entries.
30194+ */
30195+ "invlpg (%0)\n"
30196+#endif
30197+ __copyuser_seg"testb $0,(%0)\n"
30198+ "xorb %3,(%1)\n"
30199+ :
30200+ : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
30201+ : "memory", "cc");
30202+ pte_unmap_unlock(pte, ptl);
30203+ up_read(&mm->mmap_sem);
30204+ return 1;
30205+}
30206+#endif
30207+
30208 /*
30209 * Handle a spurious fault caused by a stale TLB entry.
30210 *
30211@@ -955,6 +1160,9 @@ int show_unhandled_signals = 1;
30212 static inline int
30213 access_error(unsigned long error_code, struct vm_area_struct *vma)
30214 {
30215+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
30216+ return 1;
30217+
30218 if (error_code & PF_WRITE) {
30219 /* write, present and write, not present: */
30220 if (unlikely(!(vma->vm_flags & VM_WRITE)))
30221@@ -983,7 +1191,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
30222 if (error_code & PF_USER)
30223 return false;
30224
30225- if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
30226+ if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
30227 return false;
30228
30229 return true;
30230@@ -1010,6 +1218,22 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
30231 /* Get the faulting address: */
30232 address = read_cr2();
30233
30234+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30235+ if (!user_mode(regs) && address < 2 * pax_user_shadow_base) {
30236+ if (!search_exception_tables(regs->ip)) {
30237+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
30238+ bad_area_nosemaphore(regs, error_code, address);
30239+ return;
30240+ }
30241+ if (address < pax_user_shadow_base) {
30242+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
30243+ printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
30244+ show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
30245+ } else
30246+ address -= pax_user_shadow_base;
30247+ }
30248+#endif
30249+
30250 /*
30251 * Detect and handle instructions that would cause a page fault for
30252 * both a tracked kernel page and a userspace page.
30253@@ -1069,7 +1293,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
30254 * User-mode registers count as a user access even for any
30255 * potential system fault or CPU buglet:
30256 */
30257- if (user_mode_vm(regs)) {
30258+ if (user_mode(regs)) {
30259 local_irq_enable();
30260 error_code |= PF_USER;
30261 flags |= FAULT_FLAG_USER;
30262@@ -1135,6 +1359,11 @@ retry:
30263 might_sleep();
30264 }
30265
30266+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
30267+ if (pax_handle_pageexec_fault(regs, mm, address, error_code))
30268+ return;
30269+#endif
30270+
30271 vma = find_vma(mm, address);
30272 if (unlikely(!vma)) {
30273 bad_area(regs, error_code, address);
30274@@ -1146,18 +1375,24 @@ retry:
30275 bad_area(regs, error_code, address);
30276 return;
30277 }
30278- if (error_code & PF_USER) {
30279- /*
30280- * Accessing the stack below %sp is always a bug.
30281- * The large cushion allows instructions like enter
30282- * and pusha to work. ("enter $65535, $31" pushes
30283- * 32 pointers and then decrements %sp by 65535.)
30284- */
30285- if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
30286- bad_area(regs, error_code, address);
30287- return;
30288- }
30289+ /*
30290+ * Accessing the stack below %sp is always a bug.
30291+ * The large cushion allows instructions like enter
30292+ * and pusha to work. ("enter $65535, $31" pushes
30293+ * 32 pointers and then decrements %sp by 65535.)
30294+ */
30295+ if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
30296+ bad_area(regs, error_code, address);
30297+ return;
30298 }
30299+
30300+#ifdef CONFIG_PAX_SEGMEXEC
30301+ if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
30302+ bad_area(regs, error_code, address);
30303+ return;
30304+ }
30305+#endif
30306+
30307 if (unlikely(expand_stack(vma, address))) {
30308 bad_area(regs, error_code, address);
30309 return;
30310@@ -1231,3 +1466,292 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
30311 __do_page_fault(regs, error_code);
30312 exception_exit(prev_state);
30313 }
30314+
30315+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
30316+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
30317+{
30318+ struct mm_struct *mm = current->mm;
30319+ unsigned long ip = regs->ip;
30320+
30321+ if (v8086_mode(regs))
30322+ ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
30323+
30324+#ifdef CONFIG_PAX_PAGEEXEC
30325+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
30326+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
30327+ return true;
30328+ if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
30329+ return true;
30330+ return false;
30331+ }
30332+#endif
30333+
30334+#ifdef CONFIG_PAX_SEGMEXEC
30335+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
30336+ if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
30337+ return true;
30338+ return false;
30339+ }
30340+#endif
30341+
30342+ return false;
30343+}
30344+#endif
30345+
30346+#ifdef CONFIG_PAX_EMUTRAMP
30347+static int pax_handle_fetch_fault_32(struct pt_regs *regs)
30348+{
30349+ int err;
30350+
30351+ do { /* PaX: libffi trampoline emulation */
30352+ unsigned char mov, jmp;
30353+ unsigned int addr1, addr2;
30354+
30355+#ifdef CONFIG_X86_64
30356+ if ((regs->ip + 9) >> 32)
30357+ break;
30358+#endif
30359+
30360+ err = get_user(mov, (unsigned char __user *)regs->ip);
30361+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
30362+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
30363+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
30364+
30365+ if (err)
30366+ break;
30367+
30368+ if (mov == 0xB8 && jmp == 0xE9) {
30369+ regs->ax = addr1;
30370+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
30371+ return 2;
30372+ }
30373+ } while (0);
30374+
30375+ do { /* PaX: gcc trampoline emulation #1 */
30376+ unsigned char mov1, mov2;
30377+ unsigned short jmp;
30378+ unsigned int addr1, addr2;
30379+
30380+#ifdef CONFIG_X86_64
30381+ if ((regs->ip + 11) >> 32)
30382+ break;
30383+#endif
30384+
30385+ err = get_user(mov1, (unsigned char __user *)regs->ip);
30386+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
30387+ err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
30388+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
30389+ err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
30390+
30391+ if (err)
30392+ break;
30393+
30394+ if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
30395+ regs->cx = addr1;
30396+ regs->ax = addr2;
30397+ regs->ip = addr2;
30398+ return 2;
30399+ }
30400+ } while (0);
30401+
30402+ do { /* PaX: gcc trampoline emulation #2 */
30403+ unsigned char mov, jmp;
30404+ unsigned int addr1, addr2;
30405+
30406+#ifdef CONFIG_X86_64
30407+ if ((regs->ip + 9) >> 32)
30408+ break;
30409+#endif
30410+
30411+ err = get_user(mov, (unsigned char __user *)regs->ip);
30412+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
30413+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
30414+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
30415+
30416+ if (err)
30417+ break;
30418+
30419+ if (mov == 0xB9 && jmp == 0xE9) {
30420+ regs->cx = addr1;
30421+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
30422+ return 2;
30423+ }
30424+ } while (0);
30425+
30426+ return 1; /* PaX in action */
30427+}
30428+
30429+#ifdef CONFIG_X86_64
30430+static int pax_handle_fetch_fault_64(struct pt_regs *regs)
30431+{
30432+ int err;
30433+
30434+ do { /* PaX: libffi trampoline emulation */
30435+ unsigned short mov1, mov2, jmp1;
30436+ unsigned char stcclc, jmp2;
30437+ unsigned long addr1, addr2;
30438+
30439+ err = get_user(mov1, (unsigned short __user *)regs->ip);
30440+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
30441+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
30442+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
30443+ err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
30444+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
30445+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
30446+
30447+ if (err)
30448+ break;
30449+
30450+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
30451+ regs->r11 = addr1;
30452+ regs->r10 = addr2;
30453+ if (stcclc == 0xF8)
30454+ regs->flags &= ~X86_EFLAGS_CF;
30455+ else
30456+ regs->flags |= X86_EFLAGS_CF;
30457+ regs->ip = addr1;
30458+ return 2;
30459+ }
30460+ } while (0);
30461+
30462+ do { /* PaX: gcc trampoline emulation #1 */
30463+ unsigned short mov1, mov2, jmp1;
30464+ unsigned char jmp2;
30465+ unsigned int addr1;
30466+ unsigned long addr2;
30467+
30468+ err = get_user(mov1, (unsigned short __user *)regs->ip);
30469+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
30470+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
30471+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
30472+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
30473+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
30474+
30475+ if (err)
30476+ break;
30477+
30478+ if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
30479+ regs->r11 = addr1;
30480+ regs->r10 = addr2;
30481+ regs->ip = addr1;
30482+ return 2;
30483+ }
30484+ } while (0);
30485+
30486+ do { /* PaX: gcc trampoline emulation #2 */
30487+ unsigned short mov1, mov2, jmp1;
30488+ unsigned char jmp2;
30489+ unsigned long addr1, addr2;
30490+
30491+ err = get_user(mov1, (unsigned short __user *)regs->ip);
30492+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
30493+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
30494+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
30495+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
30496+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
30497+
30498+ if (err)
30499+ break;
30500+
30501+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
30502+ regs->r11 = addr1;
30503+ regs->r10 = addr2;
30504+ regs->ip = addr1;
30505+ return 2;
30506+ }
30507+ } while (0);
30508+
30509+ return 1; /* PaX in action */
30510+}
30511+#endif
30512+
30513+/*
30514+ * PaX: decide what to do with offenders (regs->ip = fault address)
30515+ *
30516+ * returns 1 when task should be killed
30517+ * 2 when gcc trampoline was detected
30518+ */
30519+static int pax_handle_fetch_fault(struct pt_regs *regs)
30520+{
30521+ if (v8086_mode(regs))
30522+ return 1;
30523+
30524+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
30525+ return 1;
30526+
30527+#ifdef CONFIG_X86_32
30528+ return pax_handle_fetch_fault_32(regs);
30529+#else
30530+ if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
30531+ return pax_handle_fetch_fault_32(regs);
30532+ else
30533+ return pax_handle_fetch_fault_64(regs);
30534+#endif
30535+}
30536+#endif
30537+
30538+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
30539+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
30540+{
30541+ long i;
30542+
30543+ printk(KERN_ERR "PAX: bytes at PC: ");
30544+ for (i = 0; i < 20; i++) {
30545+ unsigned char c;
30546+ if (get_user(c, (unsigned char __force_user *)pc+i))
30547+ printk(KERN_CONT "?? ");
30548+ else
30549+ printk(KERN_CONT "%02x ", c);
30550+ }
30551+ printk("\n");
30552+
30553+ printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
30554+ for (i = -1; i < 80 / (long)sizeof(long); i++) {
30555+ unsigned long c;
30556+ if (get_user(c, (unsigned long __force_user *)sp+i)) {
30557+#ifdef CONFIG_X86_32
30558+ printk(KERN_CONT "???????? ");
30559+#else
30560+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
30561+ printk(KERN_CONT "???????? ???????? ");
30562+ else
30563+ printk(KERN_CONT "???????????????? ");
30564+#endif
30565+ } else {
30566+#ifdef CONFIG_X86_64
30567+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
30568+ printk(KERN_CONT "%08x ", (unsigned int)c);
30569+ printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
30570+ } else
30571+#endif
30572+ printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
30573+ }
30574+ }
30575+ printk("\n");
30576+}
30577+#endif
30578+
30579+/**
30580+ * probe_kernel_write(): safely attempt to write to a location
30581+ * @dst: address to write to
30582+ * @src: pointer to the data that shall be written
30583+ * @size: size of the data chunk
30584+ *
30585+ * Safely write to address @dst from the buffer at @src. If a kernel fault
30586+ * happens, handle that and return -EFAULT.
30587+ */
30588+long notrace probe_kernel_write(void *dst, const void *src, size_t size)
30589+{
30590+ long ret;
30591+ mm_segment_t old_fs = get_fs();
30592+
30593+ set_fs(KERNEL_DS);
30594+ pagefault_disable();
30595+ pax_open_kernel();
30596+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
30597+ pax_close_kernel();
30598+ pagefault_enable();
30599+ set_fs(old_fs);
30600+
30601+ return ret ? -EFAULT : 0;
30602+}
30603diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
30604index dd74e46..7d26398 100644
30605--- a/arch/x86/mm/gup.c
30606+++ b/arch/x86/mm/gup.c
30607@@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
30608 addr = start;
30609 len = (unsigned long) nr_pages << PAGE_SHIFT;
30610 end = start + len;
30611- if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
30612+ if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
30613 (void __user *)start, len)))
30614 return 0;
30615
30616diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
30617index 4500142..53a363c 100644
30618--- a/arch/x86/mm/highmem_32.c
30619+++ b/arch/x86/mm/highmem_32.c
30620@@ -45,7 +45,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
30621 idx = type + KM_TYPE_NR*smp_processor_id();
30622 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
30623 BUG_ON(!pte_none(*(kmap_pte-idx)));
30624+
30625+ pax_open_kernel();
30626 set_pte(kmap_pte-idx, mk_pte(page, prot));
30627+ pax_close_kernel();
30628+
30629 arch_flush_lazy_mmu_mode();
30630
30631 return (void *)vaddr;
30632diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
30633index 9d980d8..6bbfacb 100644
30634--- a/arch/x86/mm/hugetlbpage.c
30635+++ b/arch/x86/mm/hugetlbpage.c
30636@@ -92,23 +92,30 @@ int pmd_huge_support(void)
30637 #ifdef HAVE_ARCH_HUGETLB_UNMAPPED_AREA
30638 static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
30639 unsigned long addr, unsigned long len,
30640- unsigned long pgoff, unsigned long flags)
30641+ unsigned long pgoff, unsigned long flags, unsigned long offset)
30642 {
30643 struct hstate *h = hstate_file(file);
30644 struct vm_unmapped_area_info info;
30645-
30646+
30647 info.flags = 0;
30648 info.length = len;
30649 info.low_limit = TASK_UNMAPPED_BASE;
30650+
30651+#ifdef CONFIG_PAX_RANDMMAP
30652+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
30653+ info.low_limit += current->mm->delta_mmap;
30654+#endif
30655+
30656 info.high_limit = TASK_SIZE;
30657 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
30658 info.align_offset = 0;
30659+ info.threadstack_offset = offset;
30660 return vm_unmapped_area(&info);
30661 }
30662
30663 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
30664 unsigned long addr0, unsigned long len,
30665- unsigned long pgoff, unsigned long flags)
30666+ unsigned long pgoff, unsigned long flags, unsigned long offset)
30667 {
30668 struct hstate *h = hstate_file(file);
30669 struct vm_unmapped_area_info info;
30670@@ -120,6 +127,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
30671 info.high_limit = current->mm->mmap_base;
30672 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
30673 info.align_offset = 0;
30674+ info.threadstack_offset = offset;
30675 addr = vm_unmapped_area(&info);
30676
30677 /*
30678@@ -132,6 +140,12 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
30679 VM_BUG_ON(addr != -ENOMEM);
30680 info.flags = 0;
30681 info.low_limit = TASK_UNMAPPED_BASE;
30682+
30683+#ifdef CONFIG_PAX_RANDMMAP
30684+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
30685+ info.low_limit += current->mm->delta_mmap;
30686+#endif
30687+
30688 info.high_limit = TASK_SIZE;
30689 addr = vm_unmapped_area(&info);
30690 }
30691@@ -146,10 +160,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
30692 struct hstate *h = hstate_file(file);
30693 struct mm_struct *mm = current->mm;
30694 struct vm_area_struct *vma;
30695+ unsigned long pax_task_size = TASK_SIZE;
30696+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
30697
30698 if (len & ~huge_page_mask(h))
30699 return -EINVAL;
30700- if (len > TASK_SIZE)
30701+
30702+#ifdef CONFIG_PAX_SEGMEXEC
30703+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
30704+ pax_task_size = SEGMEXEC_TASK_SIZE;
30705+#endif
30706+
30707+ pax_task_size -= PAGE_SIZE;
30708+
30709+ if (len > pax_task_size)
30710 return -ENOMEM;
30711
30712 if (flags & MAP_FIXED) {
30713@@ -158,19 +182,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
30714 return addr;
30715 }
30716
30717+#ifdef CONFIG_PAX_RANDMMAP
30718+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
30719+#endif
30720+
30721 if (addr) {
30722 addr = ALIGN(addr, huge_page_size(h));
30723 vma = find_vma(mm, addr);
30724- if (TASK_SIZE - len >= addr &&
30725- (!vma || addr + len <= vma->vm_start))
30726+ if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
30727 return addr;
30728 }
30729 if (mm->get_unmapped_area == arch_get_unmapped_area)
30730 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
30731- pgoff, flags);
30732+ pgoff, flags, offset);
30733 else
30734 return hugetlb_get_unmapped_area_topdown(file, addr, len,
30735- pgoff, flags);
30736+ pgoff, flags, offset);
30737 }
30738
30739 #endif /*HAVE_ARCH_HUGETLB_UNMAPPED_AREA*/
30740diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
30741index 04664cd..dae6e5d 100644
30742--- a/arch/x86/mm/init.c
30743+++ b/arch/x86/mm/init.c
30744@@ -4,6 +4,7 @@
30745 #include <linux/swap.h>
30746 #include <linux/memblock.h>
30747 #include <linux/bootmem.h> /* for max_low_pfn */
30748+#include <linux/tboot.h>
30749
30750 #include <asm/cacheflush.h>
30751 #include <asm/e820.h>
30752@@ -17,6 +18,8 @@
30753 #include <asm/proto.h>
30754 #include <asm/dma.h> /* for MAX_DMA_PFN */
30755 #include <asm/microcode.h>
30756+#include <asm/desc.h>
30757+#include <asm/bios_ebda.h>
30758
30759 #include "mm_internal.h"
30760
30761@@ -465,7 +468,18 @@ void __init init_mem_mapping(void)
30762 early_ioremap_page_table_range_init();
30763 #endif
30764
30765+#ifdef CONFIG_PAX_PER_CPU_PGD
30766+ clone_pgd_range(get_cpu_pgd(0, kernel) + KERNEL_PGD_BOUNDARY,
30767+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
30768+ KERNEL_PGD_PTRS);
30769+ clone_pgd_range(get_cpu_pgd(0, user) + KERNEL_PGD_BOUNDARY,
30770+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
30771+ KERNEL_PGD_PTRS);
30772+ load_cr3(get_cpu_pgd(0, kernel));
30773+#else
30774 load_cr3(swapper_pg_dir);
30775+#endif
30776+
30777 __flush_tlb_all();
30778
30779 early_memtest(0, max_pfn_mapped << PAGE_SHIFT);
30780@@ -481,10 +495,40 @@ void __init init_mem_mapping(void)
30781 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
30782 * mmio resources as well as potential bios/acpi data regions.
30783 */
30784+
30785+#ifdef CONFIG_GRKERNSEC_KMEM
30786+static unsigned int ebda_start __read_only;
30787+static unsigned int ebda_end __read_only;
30788+#endif
30789+
30790 int devmem_is_allowed(unsigned long pagenr)
30791 {
30792- if (pagenr < 256)
30793+#ifdef CONFIG_GRKERNSEC_KMEM
30794+ /* allow BDA */
30795+ if (!pagenr)
30796 return 1;
30797+ /* allow EBDA */
30798+ if (pagenr >= ebda_start && pagenr < ebda_end)
30799+ return 1;
30800+ /* if tboot is in use, allow access to its hardcoded serial log range */
30801+ if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
30802+ return 1;
30803+#else
30804+ if (!pagenr)
30805+ return 1;
30806+#ifdef CONFIG_VM86
30807+ if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
30808+ return 1;
30809+#endif
30810+#endif
30811+
30812+ if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
30813+ return 1;
30814+#ifdef CONFIG_GRKERNSEC_KMEM
30815+ /* throw out everything else below 1MB */
30816+ if (pagenr <= 256)
30817+ return 0;
30818+#endif
30819 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
30820 return 0;
30821 if (!page_is_ram(pagenr))
30822@@ -530,8 +574,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
30823 #endif
30824 }
30825
30826+#ifdef CONFIG_GRKERNSEC_KMEM
30827+static inline void gr_init_ebda(void)
30828+{
30829+ unsigned int ebda_addr;
30830+ unsigned int ebda_size = 0;
30831+
30832+ ebda_addr = get_bios_ebda();
30833+ if (ebda_addr) {
30834+ ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
30835+ ebda_size <<= 10;
30836+ }
30837+ if (ebda_addr && ebda_size) {
30838+ ebda_start = ebda_addr >> PAGE_SHIFT;
30839+ ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
30840+ } else {
30841+ ebda_start = 0x9f000 >> PAGE_SHIFT;
30842+ ebda_end = 0xa0000 >> PAGE_SHIFT;
30843+ }
30844+}
30845+#else
30846+static inline void gr_init_ebda(void) { }
30847+#endif
30848+
30849 void free_initmem(void)
30850 {
30851+#ifdef CONFIG_PAX_KERNEXEC
30852+#ifdef CONFIG_X86_32
30853+ /* PaX: limit KERNEL_CS to actual size */
30854+ unsigned long addr, limit;
30855+ struct desc_struct d;
30856+ int cpu;
30857+#else
30858+ pgd_t *pgd;
30859+ pud_t *pud;
30860+ pmd_t *pmd;
30861+ unsigned long addr, end;
30862+#endif
30863+#endif
30864+
30865+ gr_init_ebda();
30866+
30867+#ifdef CONFIG_PAX_KERNEXEC
30868+#ifdef CONFIG_X86_32
30869+ limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
30870+ limit = (limit - 1UL) >> PAGE_SHIFT;
30871+
30872+ memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
30873+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
30874+ pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
30875+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
30876+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
30877+ }
30878+
30879+ /* PaX: make KERNEL_CS read-only */
30880+ addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
30881+ if (!paravirt_enabled())
30882+ set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
30883+/*
30884+ for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
30885+ pgd = pgd_offset_k(addr);
30886+ pud = pud_offset(pgd, addr);
30887+ pmd = pmd_offset(pud, addr);
30888+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
30889+ }
30890+*/
30891+#ifdef CONFIG_X86_PAE
30892+ set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
30893+/*
30894+ for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
30895+ pgd = pgd_offset_k(addr);
30896+ pud = pud_offset(pgd, addr);
30897+ pmd = pmd_offset(pud, addr);
30898+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
30899+ }
30900+*/
30901+#endif
30902+
30903+#ifdef CONFIG_MODULES
30904+ set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
30905+#endif
30906+
30907+#else
30908+ /* PaX: make kernel code/rodata read-only, rest non-executable */
30909+ for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
30910+ pgd = pgd_offset_k(addr);
30911+ pud = pud_offset(pgd, addr);
30912+ pmd = pmd_offset(pud, addr);
30913+ if (!pmd_present(*pmd))
30914+ continue;
30915+ if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
30916+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
30917+ else
30918+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
30919+ }
30920+
30921+ addr = (unsigned long)__va(__pa(__START_KERNEL_map));
30922+ end = addr + KERNEL_IMAGE_SIZE;
30923+ for (; addr < end; addr += PMD_SIZE) {
30924+ pgd = pgd_offset_k(addr);
30925+ pud = pud_offset(pgd, addr);
30926+ pmd = pmd_offset(pud, addr);
30927+ if (!pmd_present(*pmd))
30928+ continue;
30929+ if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
30930+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
30931+ }
30932+#endif
30933+
30934+ flush_tlb_all();
30935+#endif
30936+
30937 free_init_pages("unused kernel",
30938 (unsigned long)(&__init_begin),
30939 (unsigned long)(&__init_end));
30940diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
30941index 4287f1f..3b99c71 100644
30942--- a/arch/x86/mm/init_32.c
30943+++ b/arch/x86/mm/init_32.c
30944@@ -62,33 +62,6 @@ static noinline int do_test_wp_bit(void);
30945 bool __read_mostly __vmalloc_start_set = false;
30946
30947 /*
30948- * Creates a middle page table and puts a pointer to it in the
30949- * given global directory entry. This only returns the gd entry
30950- * in non-PAE compilation mode, since the middle layer is folded.
30951- */
30952-static pmd_t * __init one_md_table_init(pgd_t *pgd)
30953-{
30954- pud_t *pud;
30955- pmd_t *pmd_table;
30956-
30957-#ifdef CONFIG_X86_PAE
30958- if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
30959- pmd_table = (pmd_t *)alloc_low_page();
30960- paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
30961- set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
30962- pud = pud_offset(pgd, 0);
30963- BUG_ON(pmd_table != pmd_offset(pud, 0));
30964-
30965- return pmd_table;
30966- }
30967-#endif
30968- pud = pud_offset(pgd, 0);
30969- pmd_table = pmd_offset(pud, 0);
30970-
30971- return pmd_table;
30972-}
30973-
30974-/*
30975 * Create a page table and place a pointer to it in a middle page
30976 * directory entry:
30977 */
30978@@ -98,13 +71,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
30979 pte_t *page_table = (pte_t *)alloc_low_page();
30980
30981 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
30982+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
30983+ set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
30984+#else
30985 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
30986+#endif
30987 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
30988 }
30989
30990 return pte_offset_kernel(pmd, 0);
30991 }
30992
30993+static pmd_t * __init one_md_table_init(pgd_t *pgd)
30994+{
30995+ pud_t *pud;
30996+ pmd_t *pmd_table;
30997+
30998+ pud = pud_offset(pgd, 0);
30999+ pmd_table = pmd_offset(pud, 0);
31000+
31001+ return pmd_table;
31002+}
31003+
31004 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
31005 {
31006 int pgd_idx = pgd_index(vaddr);
31007@@ -208,6 +196,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
31008 int pgd_idx, pmd_idx;
31009 unsigned long vaddr;
31010 pgd_t *pgd;
31011+ pud_t *pud;
31012 pmd_t *pmd;
31013 pte_t *pte = NULL;
31014 unsigned long count = page_table_range_init_count(start, end);
31015@@ -222,8 +211,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
31016 pgd = pgd_base + pgd_idx;
31017
31018 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
31019- pmd = one_md_table_init(pgd);
31020- pmd = pmd + pmd_index(vaddr);
31021+ pud = pud_offset(pgd, vaddr);
31022+ pmd = pmd_offset(pud, vaddr);
31023+
31024+#ifdef CONFIG_X86_PAE
31025+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
31026+#endif
31027+
31028 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
31029 pmd++, pmd_idx++) {
31030 pte = page_table_kmap_check(one_page_table_init(pmd),
31031@@ -235,11 +229,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
31032 }
31033 }
31034
31035-static inline int is_kernel_text(unsigned long addr)
31036+static inline int is_kernel_text(unsigned long start, unsigned long end)
31037 {
31038- if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
31039- return 1;
31040- return 0;
31041+ if ((start > ktla_ktva((unsigned long)_etext) ||
31042+ end <= ktla_ktva((unsigned long)_stext)) &&
31043+ (start > ktla_ktva((unsigned long)_einittext) ||
31044+ end <= ktla_ktva((unsigned long)_sinittext)) &&
31045+
31046+#ifdef CONFIG_ACPI_SLEEP
31047+ (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
31048+#endif
31049+
31050+ (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
31051+ return 0;
31052+ return 1;
31053 }
31054
31055 /*
31056@@ -256,9 +259,10 @@ kernel_physical_mapping_init(unsigned long start,
31057 unsigned long last_map_addr = end;
31058 unsigned long start_pfn, end_pfn;
31059 pgd_t *pgd_base = swapper_pg_dir;
31060- int pgd_idx, pmd_idx, pte_ofs;
31061+ unsigned int pgd_idx, pmd_idx, pte_ofs;
31062 unsigned long pfn;
31063 pgd_t *pgd;
31064+ pud_t *pud;
31065 pmd_t *pmd;
31066 pte_t *pte;
31067 unsigned pages_2m, pages_4k;
31068@@ -291,8 +295,13 @@ repeat:
31069 pfn = start_pfn;
31070 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
31071 pgd = pgd_base + pgd_idx;
31072- for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
31073- pmd = one_md_table_init(pgd);
31074+ for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
31075+ pud = pud_offset(pgd, 0);
31076+ pmd = pmd_offset(pud, 0);
31077+
31078+#ifdef CONFIG_X86_PAE
31079+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
31080+#endif
31081
31082 if (pfn >= end_pfn)
31083 continue;
31084@@ -304,14 +313,13 @@ repeat:
31085 #endif
31086 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
31087 pmd++, pmd_idx++) {
31088- unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
31089+ unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
31090
31091 /*
31092 * Map with big pages if possible, otherwise
31093 * create normal page tables:
31094 */
31095 if (use_pse) {
31096- unsigned int addr2;
31097 pgprot_t prot = PAGE_KERNEL_LARGE;
31098 /*
31099 * first pass will use the same initial
31100@@ -322,11 +330,7 @@ repeat:
31101 _PAGE_PSE);
31102
31103 pfn &= PMD_MASK >> PAGE_SHIFT;
31104- addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
31105- PAGE_OFFSET + PAGE_SIZE-1;
31106-
31107- if (is_kernel_text(addr) ||
31108- is_kernel_text(addr2))
31109+ if (is_kernel_text(address, address + PMD_SIZE))
31110 prot = PAGE_KERNEL_LARGE_EXEC;
31111
31112 pages_2m++;
31113@@ -343,7 +347,7 @@ repeat:
31114 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
31115 pte += pte_ofs;
31116 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
31117- pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
31118+ pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
31119 pgprot_t prot = PAGE_KERNEL;
31120 /*
31121 * first pass will use the same initial
31122@@ -351,7 +355,7 @@ repeat:
31123 */
31124 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
31125
31126- if (is_kernel_text(addr))
31127+ if (is_kernel_text(address, address + PAGE_SIZE))
31128 prot = PAGE_KERNEL_EXEC;
31129
31130 pages_4k++;
31131@@ -474,7 +478,7 @@ void __init native_pagetable_init(void)
31132
31133 pud = pud_offset(pgd, va);
31134 pmd = pmd_offset(pud, va);
31135- if (!pmd_present(*pmd))
31136+ if (!pmd_present(*pmd)) // PAX TODO || pmd_large(*pmd))
31137 break;
31138
31139 /* should not be large page here */
31140@@ -532,12 +536,10 @@ void __init early_ioremap_page_table_range_init(void)
31141
31142 static void __init pagetable_init(void)
31143 {
31144- pgd_t *pgd_base = swapper_pg_dir;
31145-
31146- permanent_kmaps_init(pgd_base);
31147+ permanent_kmaps_init(swapper_pg_dir);
31148 }
31149
31150-pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
31151+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
31152 EXPORT_SYMBOL_GPL(__supported_pte_mask);
31153
31154 /* user-defined highmem size */
31155@@ -787,10 +789,10 @@ void __init mem_init(void)
31156 ((unsigned long)&__init_end -
31157 (unsigned long)&__init_begin) >> 10,
31158
31159- (unsigned long)&_etext, (unsigned long)&_edata,
31160- ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
31161+ (unsigned long)&_sdata, (unsigned long)&_edata,
31162+ ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
31163
31164- (unsigned long)&_text, (unsigned long)&_etext,
31165+ ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
31166 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
31167
31168 /*
31169@@ -880,6 +882,7 @@ void set_kernel_text_rw(void)
31170 if (!kernel_set_to_readonly)
31171 return;
31172
31173+ start = ktla_ktva(start);
31174 pr_debug("Set kernel text: %lx - %lx for read write\n",
31175 start, start+size);
31176
31177@@ -894,6 +897,7 @@ void set_kernel_text_ro(void)
31178 if (!kernel_set_to_readonly)
31179 return;
31180
31181+ start = ktla_ktva(start);
31182 pr_debug("Set kernel text: %lx - %lx for read only\n",
31183 start, start+size);
31184
31185@@ -922,6 +926,7 @@ void mark_rodata_ro(void)
31186 unsigned long start = PFN_ALIGN(_text);
31187 unsigned long size = PFN_ALIGN(_etext) - start;
31188
31189+ start = ktla_ktva(start);
31190 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
31191 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
31192 size >> 10);
31193diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
31194index 104d56a..62ba13f1 100644
31195--- a/arch/x86/mm/init_64.c
31196+++ b/arch/x86/mm/init_64.c
31197@@ -151,7 +151,7 @@ early_param("gbpages", parse_direct_gbpages_on);
31198 * around without checking the pgd every time.
31199 */
31200
31201-pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
31202+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
31203 EXPORT_SYMBOL_GPL(__supported_pte_mask);
31204
31205 int force_personality32;
31206@@ -184,12 +184,29 @@ void sync_global_pgds(unsigned long start, unsigned long end)
31207
31208 for (address = start; address <= end; address += PGDIR_SIZE) {
31209 const pgd_t *pgd_ref = pgd_offset_k(address);
31210+
31211+#ifdef CONFIG_PAX_PER_CPU_PGD
31212+ unsigned long cpu;
31213+#else
31214 struct page *page;
31215+#endif
31216
31217 if (pgd_none(*pgd_ref))
31218 continue;
31219
31220 spin_lock(&pgd_lock);
31221+
31222+#ifdef CONFIG_PAX_PER_CPU_PGD
31223+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
31224+ pgd_t *pgd = pgd_offset_cpu(cpu, user, address);
31225+
31226+ if (pgd_none(*pgd))
31227+ set_pgd(pgd, *pgd_ref);
31228+ else
31229+ BUG_ON(pgd_page_vaddr(*pgd)
31230+ != pgd_page_vaddr(*pgd_ref));
31231+ pgd = pgd_offset_cpu(cpu, kernel, address);
31232+#else
31233 list_for_each_entry(page, &pgd_list, lru) {
31234 pgd_t *pgd;
31235 spinlock_t *pgt_lock;
31236@@ -198,6 +215,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
31237 /* the pgt_lock only for Xen */
31238 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
31239 spin_lock(pgt_lock);
31240+#endif
31241
31242 if (pgd_none(*pgd))
31243 set_pgd(pgd, *pgd_ref);
31244@@ -205,7 +223,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
31245 BUG_ON(pgd_page_vaddr(*pgd)
31246 != pgd_page_vaddr(*pgd_ref));
31247
31248+#ifndef CONFIG_PAX_PER_CPU_PGD
31249 spin_unlock(pgt_lock);
31250+#endif
31251+
31252 }
31253 spin_unlock(&pgd_lock);
31254 }
31255@@ -238,7 +259,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
31256 {
31257 if (pgd_none(*pgd)) {
31258 pud_t *pud = (pud_t *)spp_getpage();
31259- pgd_populate(&init_mm, pgd, pud);
31260+ pgd_populate_kernel(&init_mm, pgd, pud);
31261 if (pud != pud_offset(pgd, 0))
31262 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
31263 pud, pud_offset(pgd, 0));
31264@@ -250,7 +271,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
31265 {
31266 if (pud_none(*pud)) {
31267 pmd_t *pmd = (pmd_t *) spp_getpage();
31268- pud_populate(&init_mm, pud, pmd);
31269+ pud_populate_kernel(&init_mm, pud, pmd);
31270 if (pmd != pmd_offset(pud, 0))
31271 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
31272 pmd, pmd_offset(pud, 0));
31273@@ -279,7 +300,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
31274 pmd = fill_pmd(pud, vaddr);
31275 pte = fill_pte(pmd, vaddr);
31276
31277+ pax_open_kernel();
31278 set_pte(pte, new_pte);
31279+ pax_close_kernel();
31280
31281 /*
31282 * It's enough to flush this one mapping.
31283@@ -338,14 +361,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
31284 pgd = pgd_offset_k((unsigned long)__va(phys));
31285 if (pgd_none(*pgd)) {
31286 pud = (pud_t *) spp_getpage();
31287- set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
31288- _PAGE_USER));
31289+ set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
31290 }
31291 pud = pud_offset(pgd, (unsigned long)__va(phys));
31292 if (pud_none(*pud)) {
31293 pmd = (pmd_t *) spp_getpage();
31294- set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
31295- _PAGE_USER));
31296+ set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
31297 }
31298 pmd = pmd_offset(pud, phys);
31299 BUG_ON(!pmd_none(*pmd));
31300@@ -586,7 +607,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
31301 prot);
31302
31303 spin_lock(&init_mm.page_table_lock);
31304- pud_populate(&init_mm, pud, pmd);
31305+ pud_populate_kernel(&init_mm, pud, pmd);
31306 spin_unlock(&init_mm.page_table_lock);
31307 }
31308 __flush_tlb_all();
31309@@ -627,7 +648,7 @@ kernel_physical_mapping_init(unsigned long start,
31310 page_size_mask);
31311
31312 spin_lock(&init_mm.page_table_lock);
31313- pgd_populate(&init_mm, pgd, pud);
31314+ pgd_populate_kernel(&init_mm, pgd, pud);
31315 spin_unlock(&init_mm.page_table_lock);
31316 pgd_changed = true;
31317 }
31318@@ -1188,8 +1209,8 @@ int kern_addr_valid(unsigned long addr)
31319 static struct vm_area_struct gate_vma = {
31320 .vm_start = VSYSCALL_START,
31321 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
31322- .vm_page_prot = PAGE_READONLY_EXEC,
31323- .vm_flags = VM_READ | VM_EXEC
31324+ .vm_page_prot = PAGE_READONLY,
31325+ .vm_flags = VM_READ
31326 };
31327
31328 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
31329@@ -1223,7 +1244,7 @@ int in_gate_area_no_mm(unsigned long addr)
31330
31331 const char *arch_vma_name(struct vm_area_struct *vma)
31332 {
31333- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
31334+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
31335 return "[vdso]";
31336 if (vma == &gate_vma)
31337 return "[vsyscall]";
31338diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
31339index 7b179b4..6bd17777 100644
31340--- a/arch/x86/mm/iomap_32.c
31341+++ b/arch/x86/mm/iomap_32.c
31342@@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
31343 type = kmap_atomic_idx_push();
31344 idx = type + KM_TYPE_NR * smp_processor_id();
31345 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
31346+
31347+ pax_open_kernel();
31348 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
31349+ pax_close_kernel();
31350+
31351 arch_flush_lazy_mmu_mode();
31352
31353 return (void *)vaddr;
31354diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
31355index 799580c..72f9fe0 100644
31356--- a/arch/x86/mm/ioremap.c
31357+++ b/arch/x86/mm/ioremap.c
31358@@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
31359 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
31360 int is_ram = page_is_ram(pfn);
31361
31362- if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
31363+ if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
31364 return NULL;
31365 WARN_ON_ONCE(is_ram);
31366 }
31367@@ -256,7 +256,7 @@ EXPORT_SYMBOL(ioremap_prot);
31368 *
31369 * Caller must ensure there is only one unmapping for the same pointer.
31370 */
31371-void iounmap(volatile void __iomem *addr)
31372+void iounmap(const volatile void __iomem *addr)
31373 {
31374 struct vm_struct *p, *o;
31375
31376@@ -310,6 +310,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
31377
31378 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
31379 if (page_is_ram(start >> PAGE_SHIFT))
31380+#ifdef CONFIG_HIGHMEM
31381+ if ((start >> PAGE_SHIFT) < max_low_pfn)
31382+#endif
31383 return __va(phys);
31384
31385 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
31386@@ -322,6 +325,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
31387 void unxlate_dev_mem_ptr(unsigned long phys, void *addr)
31388 {
31389 if (page_is_ram(phys >> PAGE_SHIFT))
31390+#ifdef CONFIG_HIGHMEM
31391+ if ((phys >> PAGE_SHIFT) < max_low_pfn)
31392+#endif
31393 return;
31394
31395 iounmap((void __iomem *)((unsigned long)addr & PAGE_MASK));
31396@@ -339,7 +345,7 @@ static int __init early_ioremap_debug_setup(char *str)
31397 early_param("early_ioremap_debug", early_ioremap_debug_setup);
31398
31399 static __initdata int after_paging_init;
31400-static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
31401+static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
31402
31403 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
31404 {
31405@@ -376,8 +382,7 @@ void __init early_ioremap_init(void)
31406 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
31407
31408 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
31409- memset(bm_pte, 0, sizeof(bm_pte));
31410- pmd_populate_kernel(&init_mm, pmd, bm_pte);
31411+ pmd_populate_user(&init_mm, pmd, bm_pte);
31412
31413 /*
31414 * The boot-ioremap range spans multiple pmds, for which
31415diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
31416index d87dd6d..bf3fa66 100644
31417--- a/arch/x86/mm/kmemcheck/kmemcheck.c
31418+++ b/arch/x86/mm/kmemcheck/kmemcheck.c
31419@@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
31420 * memory (e.g. tracked pages)? For now, we need this to avoid
31421 * invoking kmemcheck for PnP BIOS calls.
31422 */
31423- if (regs->flags & X86_VM_MASK)
31424+ if (v8086_mode(regs))
31425 return false;
31426- if (regs->cs != __KERNEL_CS)
31427+ if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
31428 return false;
31429
31430 pte = kmemcheck_pte_lookup(address);
31431diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
31432index 25e7e13..1964579 100644
31433--- a/arch/x86/mm/mmap.c
31434+++ b/arch/x86/mm/mmap.c
31435@@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
31436 * Leave an at least ~128 MB hole with possible stack randomization.
31437 */
31438 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
31439-#define MAX_GAP (TASK_SIZE/6*5)
31440+#define MAX_GAP (pax_task_size/6*5)
31441
31442 static int mmap_is_legacy(void)
31443 {
31444@@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
31445 return rnd << PAGE_SHIFT;
31446 }
31447
31448-static unsigned long mmap_base(void)
31449+static unsigned long mmap_base(struct mm_struct *mm)
31450 {
31451 unsigned long gap = rlimit(RLIMIT_STACK);
31452+ unsigned long pax_task_size = TASK_SIZE;
31453+
31454+#ifdef CONFIG_PAX_SEGMEXEC
31455+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
31456+ pax_task_size = SEGMEXEC_TASK_SIZE;
31457+#endif
31458
31459 if (gap < MIN_GAP)
31460 gap = MIN_GAP;
31461 else if (gap > MAX_GAP)
31462 gap = MAX_GAP;
31463
31464- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
31465+ return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
31466 }
31467
31468 /*
31469 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
31470 * does, but not when emulating X86_32
31471 */
31472-static unsigned long mmap_legacy_base(void)
31473+static unsigned long mmap_legacy_base(struct mm_struct *mm)
31474 {
31475- if (mmap_is_ia32())
31476+ if (mmap_is_ia32()) {
31477+
31478+#ifdef CONFIG_PAX_SEGMEXEC
31479+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
31480+ return SEGMEXEC_TASK_UNMAPPED_BASE;
31481+ else
31482+#endif
31483+
31484 return TASK_UNMAPPED_BASE;
31485- else
31486+ } else
31487 return TASK_UNMAPPED_BASE + mmap_rnd();
31488 }
31489
31490@@ -112,8 +125,15 @@ static unsigned long mmap_legacy_base(void)
31491 */
31492 void arch_pick_mmap_layout(struct mm_struct *mm)
31493 {
31494- mm->mmap_legacy_base = mmap_legacy_base();
31495- mm->mmap_base = mmap_base();
31496+ mm->mmap_legacy_base = mmap_legacy_base(mm);
31497+ mm->mmap_base = mmap_base(mm);
31498+
31499+#ifdef CONFIG_PAX_RANDMMAP
31500+ if (mm->pax_flags & MF_PAX_RANDMMAP) {
31501+ mm->mmap_legacy_base += mm->delta_mmap;
31502+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
31503+ }
31504+#endif
31505
31506 if (mmap_is_legacy()) {
31507 mm->mmap_base = mm->mmap_legacy_base;
31508diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
31509index 0057a7a..95c7edd 100644
31510--- a/arch/x86/mm/mmio-mod.c
31511+++ b/arch/x86/mm/mmio-mod.c
31512@@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
31513 break;
31514 default:
31515 {
31516- unsigned char *ip = (unsigned char *)instptr;
31517+ unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
31518 my_trace->opcode = MMIO_UNKNOWN_OP;
31519 my_trace->width = 0;
31520 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
31521@@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
31522 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
31523 void __iomem *addr)
31524 {
31525- static atomic_t next_id;
31526+ static atomic_unchecked_t next_id;
31527 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
31528 /* These are page-unaligned. */
31529 struct mmiotrace_map map = {
31530@@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
31531 .private = trace
31532 },
31533 .phys = offset,
31534- .id = atomic_inc_return(&next_id)
31535+ .id = atomic_inc_return_unchecked(&next_id)
31536 };
31537 map.map_id = trace->id;
31538
31539@@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
31540 ioremap_trace_core(offset, size, addr);
31541 }
31542
31543-static void iounmap_trace_core(volatile void __iomem *addr)
31544+static void iounmap_trace_core(const volatile void __iomem *addr)
31545 {
31546 struct mmiotrace_map map = {
31547 .phys = 0,
31548@@ -328,7 +328,7 @@ not_enabled:
31549 }
31550 }
31551
31552-void mmiotrace_iounmap(volatile void __iomem *addr)
31553+void mmiotrace_iounmap(const volatile void __iomem *addr)
31554 {
31555 might_sleep();
31556 if (is_enabled()) /* recheck and proper locking in *_core() */
31557diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
31558index 8bf93ba..dbcd670 100644
31559--- a/arch/x86/mm/numa.c
31560+++ b/arch/x86/mm/numa.c
31561@@ -474,7 +474,7 @@ static bool __init numa_meminfo_cover_memory(const struct numa_meminfo *mi)
31562 return true;
31563 }
31564
31565-static int __init numa_register_memblks(struct numa_meminfo *mi)
31566+static int __init __intentional_overflow(-1) numa_register_memblks(struct numa_meminfo *mi)
31567 {
31568 unsigned long uninitialized_var(pfn_align);
31569 int i, nid;
31570diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
31571index d0b1773..4c3327c 100644
31572--- a/arch/x86/mm/pageattr-test.c
31573+++ b/arch/x86/mm/pageattr-test.c
31574@@ -36,7 +36,7 @@ enum {
31575
31576 static int pte_testbit(pte_t pte)
31577 {
31578- return pte_flags(pte) & _PAGE_UNUSED1;
31579+ return pte_flags(pte) & _PAGE_CPA_TEST;
31580 }
31581
31582 struct split_state {
31583diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
31584index bb32480..75f2f5e 100644
31585--- a/arch/x86/mm/pageattr.c
31586+++ b/arch/x86/mm/pageattr.c
31587@@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
31588 */
31589 #ifdef CONFIG_PCI_BIOS
31590 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
31591- pgprot_val(forbidden) |= _PAGE_NX;
31592+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
31593 #endif
31594
31595 /*
31596@@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
31597 * Does not cover __inittext since that is gone later on. On
31598 * 64bit we do not enforce !NX on the low mapping
31599 */
31600- if (within(address, (unsigned long)_text, (unsigned long)_etext))
31601- pgprot_val(forbidden) |= _PAGE_NX;
31602+ if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
31603+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
31604
31605+#ifdef CONFIG_DEBUG_RODATA
31606 /*
31607 * The .rodata section needs to be read-only. Using the pfn
31608 * catches all aliases.
31609@@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
31610 if (within(pfn, __pa_symbol(__start_rodata) >> PAGE_SHIFT,
31611 __pa_symbol(__end_rodata) >> PAGE_SHIFT))
31612 pgprot_val(forbidden) |= _PAGE_RW;
31613+#endif
31614
31615 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
31616 /*
31617@@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
31618 }
31619 #endif
31620
31621+#ifdef CONFIG_PAX_KERNEXEC
31622+ if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
31623+ pgprot_val(forbidden) |= _PAGE_RW;
31624+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
31625+ }
31626+#endif
31627+
31628 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
31629
31630 return prot;
31631@@ -400,23 +409,37 @@ EXPORT_SYMBOL_GPL(slow_virt_to_phys);
31632 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
31633 {
31634 /* change init_mm */
31635+ pax_open_kernel();
31636 set_pte_atomic(kpte, pte);
31637+
31638 #ifdef CONFIG_X86_32
31639 if (!SHARED_KERNEL_PMD) {
31640+
31641+#ifdef CONFIG_PAX_PER_CPU_PGD
31642+ unsigned long cpu;
31643+#else
31644 struct page *page;
31645+#endif
31646
31647+#ifdef CONFIG_PAX_PER_CPU_PGD
31648+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
31649+ pgd_t *pgd = get_cpu_pgd(cpu, kernel);
31650+#else
31651 list_for_each_entry(page, &pgd_list, lru) {
31652- pgd_t *pgd;
31653+ pgd_t *pgd = (pgd_t *)page_address(page);
31654+#endif
31655+
31656 pud_t *pud;
31657 pmd_t *pmd;
31658
31659- pgd = (pgd_t *)page_address(page) + pgd_index(address);
31660+ pgd += pgd_index(address);
31661 pud = pud_offset(pgd, address);
31662 pmd = pmd_offset(pud, address);
31663 set_pte_atomic((pte_t *)pmd, pte);
31664 }
31665 }
31666 #endif
31667+ pax_close_kernel();
31668 }
31669
31670 static int
31671diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
31672index 6574388..87e9bef 100644
31673--- a/arch/x86/mm/pat.c
31674+++ b/arch/x86/mm/pat.c
31675@@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
31676
31677 if (!entry) {
31678 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
31679- current->comm, current->pid, start, end - 1);
31680+ current->comm, task_pid_nr(current), start, end - 1);
31681 return -EINVAL;
31682 }
31683
31684@@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
31685
31686 while (cursor < to) {
31687 if (!devmem_is_allowed(pfn)) {
31688- printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
31689- current->comm, from, to - 1);
31690+ printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
31691+ current->comm, from, to - 1, cursor);
31692 return 0;
31693 }
31694 cursor += PAGE_SIZE;
31695@@ -577,7 +577,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
31696 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
31697 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
31698 "for [mem %#010Lx-%#010Lx]\n",
31699- current->comm, current->pid,
31700+ current->comm, task_pid_nr(current),
31701 cattr_name(flags),
31702 base, (unsigned long long)(base + size-1));
31703 return -EINVAL;
31704@@ -612,7 +612,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
31705 flags = lookup_memtype(paddr);
31706 if (want_flags != flags) {
31707 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
31708- current->comm, current->pid,
31709+ current->comm, task_pid_nr(current),
31710 cattr_name(want_flags),
31711 (unsigned long long)paddr,
31712 (unsigned long long)(paddr + size - 1),
31713@@ -634,7 +634,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
31714 free_memtype(paddr, paddr + size);
31715 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
31716 " for [mem %#010Lx-%#010Lx], got %s\n",
31717- current->comm, current->pid,
31718+ current->comm, task_pid_nr(current),
31719 cattr_name(want_flags),
31720 (unsigned long long)paddr,
31721 (unsigned long long)(paddr + size - 1),
31722diff --git a/arch/x86/mm/pat_rbtree.c b/arch/x86/mm/pat_rbtree.c
31723index 415f6c4..d319983 100644
31724--- a/arch/x86/mm/pat_rbtree.c
31725+++ b/arch/x86/mm/pat_rbtree.c
31726@@ -160,7 +160,7 @@ success:
31727
31728 failure:
31729 printk(KERN_INFO "%s:%d conflicting memory types "
31730- "%Lx-%Lx %s<->%s\n", current->comm, current->pid, start,
31731+ "%Lx-%Lx %s<->%s\n", current->comm, task_pid_nr(current), start,
31732 end, cattr_name(found_type), cattr_name(match->type));
31733 return -EBUSY;
31734 }
31735diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
31736index 9f0614d..92ae64a 100644
31737--- a/arch/x86/mm/pf_in.c
31738+++ b/arch/x86/mm/pf_in.c
31739@@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
31740 int i;
31741 enum reason_type rv = OTHERS;
31742
31743- p = (unsigned char *)ins_addr;
31744+ p = (unsigned char *)ktla_ktva(ins_addr);
31745 p += skip_prefix(p, &prf);
31746 p += get_opcode(p, &opcode);
31747
31748@@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
31749 struct prefix_bits prf;
31750 int i;
31751
31752- p = (unsigned char *)ins_addr;
31753+ p = (unsigned char *)ktla_ktva(ins_addr);
31754 p += skip_prefix(p, &prf);
31755 p += get_opcode(p, &opcode);
31756
31757@@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
31758 struct prefix_bits prf;
31759 int i;
31760
31761- p = (unsigned char *)ins_addr;
31762+ p = (unsigned char *)ktla_ktva(ins_addr);
31763 p += skip_prefix(p, &prf);
31764 p += get_opcode(p, &opcode);
31765
31766@@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
31767 struct prefix_bits prf;
31768 int i;
31769
31770- p = (unsigned char *)ins_addr;
31771+ p = (unsigned char *)ktla_ktva(ins_addr);
31772 p += skip_prefix(p, &prf);
31773 p += get_opcode(p, &opcode);
31774 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
31775@@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
31776 struct prefix_bits prf;
31777 int i;
31778
31779- p = (unsigned char *)ins_addr;
31780+ p = (unsigned char *)ktla_ktva(ins_addr);
31781 p += skip_prefix(p, &prf);
31782 p += get_opcode(p, &opcode);
31783 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
31784diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
31785index dfa537a..fd45c64 100644
31786--- a/arch/x86/mm/pgtable.c
31787+++ b/arch/x86/mm/pgtable.c
31788@@ -91,10 +91,67 @@ static inline void pgd_list_del(pgd_t *pgd)
31789 list_del(&page->lru);
31790 }
31791
31792-#define UNSHARED_PTRS_PER_PGD \
31793- (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
31794+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31795+pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
31796
31797+void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
31798+{
31799+ unsigned int count = USER_PGD_PTRS;
31800
31801+ if (!pax_user_shadow_base)
31802+ return;
31803+
31804+ while (count--)
31805+ *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
31806+}
31807+#endif
31808+
31809+#ifdef CONFIG_PAX_PER_CPU_PGD
31810+void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
31811+{
31812+ unsigned int count = USER_PGD_PTRS;
31813+
31814+ while (count--) {
31815+ pgd_t pgd;
31816+
31817+#ifdef CONFIG_X86_64
31818+ pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
31819+#else
31820+ pgd = *src++;
31821+#endif
31822+
31823+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31824+ pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
31825+#endif
31826+
31827+ *dst++ = pgd;
31828+ }
31829+
31830+}
31831+#endif
31832+
31833+#ifdef CONFIG_X86_64
31834+#define pxd_t pud_t
31835+#define pyd_t pgd_t
31836+#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
31837+#define pxd_free(mm, pud) pud_free((mm), (pud))
31838+#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
31839+#define pyd_offset(mm, address) pgd_offset((mm), (address))
31840+#define PYD_SIZE PGDIR_SIZE
31841+#else
31842+#define pxd_t pmd_t
31843+#define pyd_t pud_t
31844+#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
31845+#define pxd_free(mm, pud) pmd_free((mm), (pud))
31846+#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
31847+#define pyd_offset(mm, address) pud_offset((mm), (address))
31848+#define PYD_SIZE PUD_SIZE
31849+#endif
31850+
31851+#ifdef CONFIG_PAX_PER_CPU_PGD
31852+static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
31853+static inline void pgd_dtor(pgd_t *pgd) {}
31854+#else
31855 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
31856 {
31857 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
31858@@ -135,6 +192,7 @@ static void pgd_dtor(pgd_t *pgd)
31859 pgd_list_del(pgd);
31860 spin_unlock(&pgd_lock);
31861 }
31862+#endif
31863
31864 /*
31865 * List of all pgd's needed for non-PAE so it can invalidate entries
31866@@ -147,7 +205,7 @@ static void pgd_dtor(pgd_t *pgd)
31867 * -- nyc
31868 */
31869
31870-#ifdef CONFIG_X86_PAE
31871+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
31872 /*
31873 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
31874 * updating the top-level pagetable entries to guarantee the
31875@@ -159,7 +217,7 @@ static void pgd_dtor(pgd_t *pgd)
31876 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
31877 * and initialize the kernel pmds here.
31878 */
31879-#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
31880+#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
31881
31882 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
31883 {
31884@@ -177,36 +235,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
31885 */
31886 flush_tlb_mm(mm);
31887 }
31888+#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
31889+#define PREALLOCATED_PXDS USER_PGD_PTRS
31890 #else /* !CONFIG_X86_PAE */
31891
31892 /* No need to prepopulate any pagetable entries in non-PAE modes. */
31893-#define PREALLOCATED_PMDS 0
31894+#define PREALLOCATED_PXDS 0
31895
31896 #endif /* CONFIG_X86_PAE */
31897
31898-static void free_pmds(pmd_t *pmds[])
31899+static void free_pxds(pxd_t *pxds[])
31900 {
31901 int i;
31902
31903- for(i = 0; i < PREALLOCATED_PMDS; i++)
31904- if (pmds[i])
31905- free_page((unsigned long)pmds[i]);
31906+ for(i = 0; i < PREALLOCATED_PXDS; i++)
31907+ if (pxds[i])
31908+ free_page((unsigned long)pxds[i]);
31909 }
31910
31911-static int preallocate_pmds(pmd_t *pmds[])
31912+static int preallocate_pxds(pxd_t *pxds[])
31913 {
31914 int i;
31915 bool failed = false;
31916
31917- for(i = 0; i < PREALLOCATED_PMDS; i++) {
31918- pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
31919- if (pmd == NULL)
31920+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
31921+ pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
31922+ if (pxd == NULL)
31923 failed = true;
31924- pmds[i] = pmd;
31925+ pxds[i] = pxd;
31926 }
31927
31928 if (failed) {
31929- free_pmds(pmds);
31930+ free_pxds(pxds);
31931 return -ENOMEM;
31932 }
31933
31934@@ -219,49 +279,52 @@ static int preallocate_pmds(pmd_t *pmds[])
31935 * preallocate which never got a corresponding vma will need to be
31936 * freed manually.
31937 */
31938-static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
31939+static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
31940 {
31941 int i;
31942
31943- for(i = 0; i < PREALLOCATED_PMDS; i++) {
31944+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
31945 pgd_t pgd = pgdp[i];
31946
31947 if (pgd_val(pgd) != 0) {
31948- pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
31949+ pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
31950
31951- pgdp[i] = native_make_pgd(0);
31952+ set_pgd(pgdp + i, native_make_pgd(0));
31953
31954- paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
31955- pmd_free(mm, pmd);
31956+ paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
31957+ pxd_free(mm, pxd);
31958 }
31959 }
31960 }
31961
31962-static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
31963+static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
31964 {
31965- pud_t *pud;
31966+ pyd_t *pyd;
31967 int i;
31968
31969- if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
31970+ if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
31971 return;
31972
31973- pud = pud_offset(pgd, 0);
31974-
31975- for (i = 0; i < PREALLOCATED_PMDS; i++, pud++) {
31976- pmd_t *pmd = pmds[i];
31977+#ifdef CONFIG_X86_64
31978+ pyd = pyd_offset(mm, 0L);
31979+#else
31980+ pyd = pyd_offset(pgd, 0L);
31981+#endif
31982
31983+ for (i = 0; i < PREALLOCATED_PXDS; i++, pyd++) {
31984+ pxd_t *pxd = pxds[i];
31985 if (i >= KERNEL_PGD_BOUNDARY)
31986- memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
31987- sizeof(pmd_t) * PTRS_PER_PMD);
31988+ memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
31989+ sizeof(pxd_t) * PTRS_PER_PMD);
31990
31991- pud_populate(mm, pud, pmd);
31992+ pyd_populate(mm, pyd, pxd);
31993 }
31994 }
31995
31996 pgd_t *pgd_alloc(struct mm_struct *mm)
31997 {
31998 pgd_t *pgd;
31999- pmd_t *pmds[PREALLOCATED_PMDS];
32000+ pxd_t *pxds[PREALLOCATED_PXDS];
32001
32002 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
32003
32004@@ -270,11 +333,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
32005
32006 mm->pgd = pgd;
32007
32008- if (preallocate_pmds(pmds) != 0)
32009+ if (preallocate_pxds(pxds) != 0)
32010 goto out_free_pgd;
32011
32012 if (paravirt_pgd_alloc(mm) != 0)
32013- goto out_free_pmds;
32014+ goto out_free_pxds;
32015
32016 /*
32017 * Make sure that pre-populating the pmds is atomic with
32018@@ -284,14 +347,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
32019 spin_lock(&pgd_lock);
32020
32021 pgd_ctor(mm, pgd);
32022- pgd_prepopulate_pmd(mm, pgd, pmds);
32023+ pgd_prepopulate_pxd(mm, pgd, pxds);
32024
32025 spin_unlock(&pgd_lock);
32026
32027 return pgd;
32028
32029-out_free_pmds:
32030- free_pmds(pmds);
32031+out_free_pxds:
32032+ free_pxds(pxds);
32033 out_free_pgd:
32034 free_page((unsigned long)pgd);
32035 out:
32036@@ -300,7 +363,7 @@ out:
32037
32038 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
32039 {
32040- pgd_mop_up_pmds(mm, pgd);
32041+ pgd_mop_up_pxds(mm, pgd);
32042 pgd_dtor(pgd);
32043 paravirt_pgd_free(mm, pgd);
32044 free_page((unsigned long)pgd);
32045diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
32046index a69bcb8..19068ab 100644
32047--- a/arch/x86/mm/pgtable_32.c
32048+++ b/arch/x86/mm/pgtable_32.c
32049@@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
32050 return;
32051 }
32052 pte = pte_offset_kernel(pmd, vaddr);
32053+
32054+ pax_open_kernel();
32055 if (pte_val(pteval))
32056 set_pte_at(&init_mm, vaddr, pte, pteval);
32057 else
32058 pte_clear(&init_mm, vaddr, pte);
32059+ pax_close_kernel();
32060
32061 /*
32062 * It's enough to flush this one mapping.
32063diff --git a/arch/x86/mm/physaddr.c b/arch/x86/mm/physaddr.c
32064index e666cbb..61788c45 100644
32065--- a/arch/x86/mm/physaddr.c
32066+++ b/arch/x86/mm/physaddr.c
32067@@ -10,7 +10,7 @@
32068 #ifdef CONFIG_X86_64
32069
32070 #ifdef CONFIG_DEBUG_VIRTUAL
32071-unsigned long __phys_addr(unsigned long x)
32072+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
32073 {
32074 unsigned long y = x - __START_KERNEL_map;
32075
32076@@ -67,7 +67,7 @@ EXPORT_SYMBOL(__virt_addr_valid);
32077 #else
32078
32079 #ifdef CONFIG_DEBUG_VIRTUAL
32080-unsigned long __phys_addr(unsigned long x)
32081+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
32082 {
32083 unsigned long phys_addr = x - PAGE_OFFSET;
32084 /* VMALLOC_* aren't constants */
32085diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
32086index 90555bf..f5f1828 100644
32087--- a/arch/x86/mm/setup_nx.c
32088+++ b/arch/x86/mm/setup_nx.c
32089@@ -5,8 +5,10 @@
32090 #include <asm/pgtable.h>
32091 #include <asm/proto.h>
32092
32093+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
32094 static int disable_nx;
32095
32096+#ifndef CONFIG_PAX_PAGEEXEC
32097 /*
32098 * noexec = on|off
32099 *
32100@@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
32101 return 0;
32102 }
32103 early_param("noexec", noexec_setup);
32104+#endif
32105+
32106+#endif
32107
32108 void x86_configure_nx(void)
32109 {
32110+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
32111 if (cpu_has_nx && !disable_nx)
32112 __supported_pte_mask |= _PAGE_NX;
32113 else
32114+#endif
32115 __supported_pte_mask &= ~_PAGE_NX;
32116 }
32117
32118diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
32119index ae699b3..f1b2ad2 100644
32120--- a/arch/x86/mm/tlb.c
32121+++ b/arch/x86/mm/tlb.c
32122@@ -48,7 +48,11 @@ void leave_mm(int cpu)
32123 BUG();
32124 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
32125 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
32126+
32127+#ifndef CONFIG_PAX_PER_CPU_PGD
32128 load_cr3(swapper_pg_dir);
32129+#endif
32130+
32131 }
32132 }
32133 EXPORT_SYMBOL_GPL(leave_mm);
32134diff --git a/arch/x86/mm/uderef_64.c b/arch/x86/mm/uderef_64.c
32135new file mode 100644
32136index 0000000..dace51c
32137--- /dev/null
32138+++ b/arch/x86/mm/uderef_64.c
32139@@ -0,0 +1,37 @@
32140+#include <linux/mm.h>
32141+#include <asm/pgtable.h>
32142+#include <asm/uaccess.h>
32143+
32144+#ifdef CONFIG_PAX_MEMORY_UDEREF
32145+/* PaX: due to the special call convention these functions must
32146+ * - remain leaf functions under all configurations,
32147+ * - never be called directly, only dereferenced from the wrappers.
32148+ */
32149+void __pax_open_userland(void)
32150+{
32151+ unsigned int cpu;
32152+
32153+ if (unlikely(!segment_eq(get_fs(), USER_DS)))
32154+ return;
32155+
32156+ cpu = raw_get_cpu();
32157+ BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_KERNEL);
32158+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
32159+ raw_put_cpu_no_resched();
32160+}
32161+EXPORT_SYMBOL(__pax_open_userland);
32162+
32163+void __pax_close_userland(void)
32164+{
32165+ unsigned int cpu;
32166+
32167+ if (unlikely(!segment_eq(get_fs(), USER_DS)))
32168+ return;
32169+
32170+ cpu = raw_get_cpu();
32171+ BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_USER);
32172+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
32173+ raw_put_cpu_no_resched();
32174+}
32175+EXPORT_SYMBOL(__pax_close_userland);
32176+#endif
32177diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
32178index 877b9a1..a8ecf42 100644
32179--- a/arch/x86/net/bpf_jit.S
32180+++ b/arch/x86/net/bpf_jit.S
32181@@ -9,6 +9,7 @@
32182 */
32183 #include <linux/linkage.h>
32184 #include <asm/dwarf2.h>
32185+#include <asm/alternative-asm.h>
32186
32187 /*
32188 * Calling convention :
32189@@ -35,6 +36,7 @@ sk_load_word_positive_offset:
32190 jle bpf_slow_path_word
32191 mov (SKBDATA,%rsi),%eax
32192 bswap %eax /* ntohl() */
32193+ pax_force_retaddr
32194 ret
32195
32196 sk_load_half:
32197@@ -52,6 +54,7 @@ sk_load_half_positive_offset:
32198 jle bpf_slow_path_half
32199 movzwl (SKBDATA,%rsi),%eax
32200 rol $8,%ax # ntohs()
32201+ pax_force_retaddr
32202 ret
32203
32204 sk_load_byte:
32205@@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
32206 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
32207 jle bpf_slow_path_byte
32208 movzbl (SKBDATA,%rsi),%eax
32209+ pax_force_retaddr
32210 ret
32211
32212 /**
32213@@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
32214 movzbl (SKBDATA,%rsi),%ebx
32215 and $15,%bl
32216 shl $2,%bl
32217+ pax_force_retaddr
32218 ret
32219
32220 /* rsi contains offset and can be scratched */
32221@@ -109,6 +114,7 @@ bpf_slow_path_word:
32222 js bpf_error
32223 mov -12(%rbp),%eax
32224 bswap %eax
32225+ pax_force_retaddr
32226 ret
32227
32228 bpf_slow_path_half:
32229@@ -117,12 +123,14 @@ bpf_slow_path_half:
32230 mov -12(%rbp),%ax
32231 rol $8,%ax
32232 movzwl %ax,%eax
32233+ pax_force_retaddr
32234 ret
32235
32236 bpf_slow_path_byte:
32237 bpf_slow_path_common(1)
32238 js bpf_error
32239 movzbl -12(%rbp),%eax
32240+ pax_force_retaddr
32241 ret
32242
32243 bpf_slow_path_byte_msh:
32244@@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
32245 and $15,%al
32246 shl $2,%al
32247 xchg %eax,%ebx
32248+ pax_force_retaddr
32249 ret
32250
32251 #define sk_negative_common(SIZE) \
32252@@ -157,6 +166,7 @@ sk_load_word_negative_offset:
32253 sk_negative_common(4)
32254 mov (%rax), %eax
32255 bswap %eax
32256+ pax_force_retaddr
32257 ret
32258
32259 bpf_slow_path_half_neg:
32260@@ -168,6 +178,7 @@ sk_load_half_negative_offset:
32261 mov (%rax),%ax
32262 rol $8,%ax
32263 movzwl %ax,%eax
32264+ pax_force_retaddr
32265 ret
32266
32267 bpf_slow_path_byte_neg:
32268@@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
32269 .globl sk_load_byte_negative_offset
32270 sk_negative_common(1)
32271 movzbl (%rax), %eax
32272+ pax_force_retaddr
32273 ret
32274
32275 bpf_slow_path_byte_msh_neg:
32276@@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
32277 and $15,%al
32278 shl $2,%al
32279 xchg %eax,%ebx
32280+ pax_force_retaddr
32281 ret
32282
32283 bpf_error:
32284@@ -197,4 +210,5 @@ bpf_error:
32285 xor %eax,%eax
32286 mov -8(%rbp),%rbx
32287 leaveq
32288+ pax_force_retaddr
32289 ret
32290diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
32291index 516593e..29d3c55 100644
32292--- a/arch/x86/net/bpf_jit_comp.c
32293+++ b/arch/x86/net/bpf_jit_comp.c
32294@@ -50,13 +50,90 @@ static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
32295 return ptr + len;
32296 }
32297
32298+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
32299+#define MAX_INSTR_CODE_SIZE 96
32300+#else
32301+#define MAX_INSTR_CODE_SIZE 64
32302+#endif
32303+
32304 #define EMIT(bytes, len) do { prog = emit_code(prog, bytes, len); } while (0)
32305
32306 #define EMIT1(b1) EMIT(b1, 1)
32307 #define EMIT2(b1, b2) EMIT((b1) + ((b2) << 8), 2)
32308 #define EMIT3(b1, b2, b3) EMIT((b1) + ((b2) << 8) + ((b3) << 16), 3)
32309 #define EMIT4(b1, b2, b3, b4) EMIT((b1) + ((b2) << 8) + ((b3) << 16) + ((b4) << 24), 4)
32310+
32311+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
32312+/* original constant will appear in ecx */
32313+#define DILUTE_CONST_SEQUENCE(_off, _key) \
32314+do { \
32315+ /* mov ecx, randkey */ \
32316+ EMIT1(0xb9); \
32317+ EMIT(_key, 4); \
32318+ /* xor ecx, randkey ^ off */ \
32319+ EMIT2(0x81, 0xf1); \
32320+ EMIT((_key) ^ (_off), 4); \
32321+} while (0)
32322+
32323+#define EMIT1_off32(b1, _off) \
32324+do { \
32325+ switch (b1) { \
32326+ case 0x05: /* add eax, imm32 */ \
32327+ case 0x2d: /* sub eax, imm32 */ \
32328+ case 0x25: /* and eax, imm32 */ \
32329+ case 0x0d: /* or eax, imm32 */ \
32330+ case 0xb8: /* mov eax, imm32 */ \
32331+ case 0x35: /* xor eax, imm32 */ \
32332+ case 0x3d: /* cmp eax, imm32 */ \
32333+ case 0xa9: /* test eax, imm32 */ \
32334+ DILUTE_CONST_SEQUENCE(_off, randkey); \
32335+ EMIT2((b1) - 4, 0xc8); /* convert imm instruction to eax, ecx */\
32336+ break; \
32337+ case 0xbb: /* mov ebx, imm32 */ \
32338+ DILUTE_CONST_SEQUENCE(_off, randkey); \
32339+ /* mov ebx, ecx */ \
32340+ EMIT2(0x89, 0xcb); \
32341+ break; \
32342+ case 0xbe: /* mov esi, imm32 */ \
32343+ DILUTE_CONST_SEQUENCE(_off, randkey); \
32344+ /* mov esi, ecx */ \
32345+ EMIT2(0x89, 0xce); \
32346+ break; \
32347+ case 0xe8: /* call rel imm32, always to known funcs */ \
32348+ EMIT1(b1); \
32349+ EMIT(_off, 4); \
32350+ break; \
32351+ case 0xe9: /* jmp rel imm32 */ \
32352+ EMIT1(b1); \
32353+ EMIT(_off, 4); \
32354+ /* prevent fall-through, we're not called if off = 0 */ \
32355+ EMIT(0xcccccccc, 4); \
32356+ EMIT(0xcccccccc, 4); \
32357+ break; \
32358+ default: \
32359+ BUILD_BUG(); \
32360+ } \
32361+} while (0)
32362+
32363+#define EMIT2_off32(b1, b2, _off) \
32364+do { \
32365+ if ((b1) == 0x8d && (b2) == 0xb3) { /* lea esi, [rbx+imm32] */ \
32366+ EMIT2(0x8d, 0xb3); /* lea esi, [rbx+randkey] */ \
32367+ EMIT(randkey, 4); \
32368+ EMIT2(0x8d, 0xb6); /* lea esi, [esi+off-randkey] */ \
32369+ EMIT((_off) - randkey, 4); \
32370+ } else if ((b1) == 0x69 && (b2) == 0xc0) { /* imul eax, imm32 */\
32371+ DILUTE_CONST_SEQUENCE(_off, randkey); \
32372+ /* imul eax, ecx */ \
32373+ EMIT3(0x0f, 0xaf, 0xc1); \
32374+ } else { \
32375+ BUILD_BUG(); \
32376+ } \
32377+} while (0)
32378+#else
32379 #define EMIT1_off32(b1, off) do { EMIT1(b1); EMIT(off, 4);} while (0)
32380+#define EMIT2_off32(b1, b2, off) do { EMIT2(b1, b2); EMIT(off, 4);} while (0)
32381+#endif
32382
32383 #define CLEAR_A() EMIT2(0x31, 0xc0) /* xor %eax,%eax */
32384 #define CLEAR_X() EMIT2(0x31, 0xdb) /* xor %ebx,%ebx */
32385@@ -91,6 +168,24 @@ do { \
32386 #define X86_JBE 0x76
32387 #define X86_JA 0x77
32388
32389+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
32390+#define APPEND_FLOW_VERIFY() \
32391+do { \
32392+ /* mov ecx, randkey */ \
32393+ EMIT1(0xb9); \
32394+ EMIT(randkey, 4); \
32395+ /* cmp ecx, randkey */ \
32396+ EMIT2(0x81, 0xf9); \
32397+ EMIT(randkey, 4); \
32398+ /* jz after 8 int 3s */ \
32399+ EMIT2(0x74, 0x08); \
32400+ EMIT(0xcccccccc, 4); \
32401+ EMIT(0xcccccccc, 4); \
32402+} while (0)
32403+#else
32404+#define APPEND_FLOW_VERIFY() do { } while (0)
32405+#endif
32406+
32407 #define EMIT_COND_JMP(op, offset) \
32408 do { \
32409 if (is_near(offset)) \
32410@@ -98,6 +193,7 @@ do { \
32411 else { \
32412 EMIT2(0x0f, op + 0x10); \
32413 EMIT(offset, 4); /* jxx .+off32 */ \
32414+ APPEND_FLOW_VERIFY(); \
32415 } \
32416 } while (0)
32417
32418@@ -145,55 +241,54 @@ static int pkt_type_offset(void)
32419 return -1;
32420 }
32421
32422-struct bpf_binary_header {
32423- unsigned int pages;
32424- /* Note : for security reasons, bpf code will follow a randomly
32425- * sized amount of int3 instructions
32426- */
32427- u8 image[];
32428-};
32429-
32430-static struct bpf_binary_header *bpf_alloc_binary(unsigned int proglen,
32431+/* Note : for security reasons, bpf code will follow a randomly
32432+ * sized amount of int3 instructions
32433+ */
32434+static u8 *bpf_alloc_binary(unsigned int proglen,
32435 u8 **image_ptr)
32436 {
32437 unsigned int sz, hole;
32438- struct bpf_binary_header *header;
32439+ u8 *header;
32440
32441 /* Most of BPF filters are really small,
32442 * but if some of them fill a page, allow at least
32443 * 128 extra bytes to insert a random section of int3
32444 */
32445- sz = round_up(proglen + sizeof(*header) + 128, PAGE_SIZE);
32446- header = module_alloc(sz);
32447+ sz = round_up(proglen + 128, PAGE_SIZE);
32448+ header = module_alloc_exec(sz);
32449 if (!header)
32450 return NULL;
32451
32452+ pax_open_kernel();
32453 memset(header, 0xcc, sz); /* fill whole space with int3 instructions */
32454+ pax_close_kernel();
32455
32456- header->pages = sz / PAGE_SIZE;
32457- hole = sz - (proglen + sizeof(*header));
32458+ hole = PAGE_SIZE - (proglen & ~PAGE_MASK);
32459
32460 /* insert a random number of int3 instructions before BPF code */
32461- *image_ptr = &header->image[prandom_u32() % hole];
32462+ *image_ptr = &header[prandom_u32() % hole];
32463 return header;
32464 }
32465
32466 void bpf_jit_compile(struct sk_filter *fp)
32467 {
32468- u8 temp[64];
32469+ u8 temp[MAX_INSTR_CODE_SIZE];
32470 u8 *prog;
32471 unsigned int proglen, oldproglen = 0;
32472 int ilen, i;
32473 int t_offset, f_offset;
32474 u8 t_op, f_op, seen = 0, pass;
32475 u8 *image = NULL;
32476- struct bpf_binary_header *header = NULL;
32477+ u8 *header = NULL;
32478 u8 *func;
32479 int pc_ret0 = -1; /* bpf index of first RET #0 instruction (if any) */
32480 unsigned int cleanup_addr; /* epilogue code offset */
32481 unsigned int *addrs;
32482 const struct sock_filter *filter = fp->insns;
32483 int flen = fp->len;
32484+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
32485+ unsigned int randkey;
32486+#endif
32487
32488 if (!bpf_jit_enable)
32489 return;
32490@@ -202,11 +297,15 @@ void bpf_jit_compile(struct sk_filter *fp)
32491 if (addrs == NULL)
32492 return;
32493
32494+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
32495+ randkey = get_random_int();
32496+#endif
32497+
32498 /* Before first pass, make a rough estimation of addrs[]
32499- * each bpf instruction is translated to less than 64 bytes
32500+ * each bpf instruction is translated to less than MAX_INSTR_CODE_SIZE bytes
32501 */
32502 for (proglen = 0, i = 0; i < flen; i++) {
32503- proglen += 64;
32504+ proglen += MAX_INSTR_CODE_SIZE;
32505 addrs[i] = proglen;
32506 }
32507 cleanup_addr = proglen; /* epilogue address */
32508@@ -317,10 +416,8 @@ void bpf_jit_compile(struct sk_filter *fp)
32509 case BPF_S_ALU_MUL_K: /* A *= K */
32510 if (is_imm8(K))
32511 EMIT3(0x6b, 0xc0, K); /* imul imm8,%eax,%eax */
32512- else {
32513- EMIT2(0x69, 0xc0); /* imul imm32,%eax */
32514- EMIT(K, 4);
32515- }
32516+ else
32517+ EMIT2_off32(0x69, 0xc0, K); /* imul imm32,%eax */
32518 break;
32519 case BPF_S_ALU_DIV_X: /* A /= X; */
32520 seen |= SEEN_XREG;
32521@@ -360,13 +457,23 @@ void bpf_jit_compile(struct sk_filter *fp)
32522 break;
32523 case BPF_S_ALU_MOD_K: /* A %= K; */
32524 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
32525+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
32526+ DILUTE_CONST_SEQUENCE(K, randkey);
32527+#else
32528 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
32529+#endif
32530 EMIT2(0xf7, 0xf1); /* div %ecx */
32531 EMIT2(0x89, 0xd0); /* mov %edx,%eax */
32532 break;
32533 case BPF_S_ALU_DIV_K: /* A = reciprocal_divide(A, K); */
32534+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
32535+ DILUTE_CONST_SEQUENCE(K, randkey);
32536+ // imul rax, rcx
32537+ EMIT4(0x48, 0x0f, 0xaf, 0xc1);
32538+#else
32539 EMIT3(0x48, 0x69, 0xc0); /* imul imm32,%rax,%rax */
32540 EMIT(K, 4);
32541+#endif
32542 EMIT4(0x48, 0xc1, 0xe8, 0x20); /* shr $0x20,%rax */
32543 break;
32544 case BPF_S_ALU_AND_X:
32545@@ -637,8 +744,7 @@ common_load_ind: seen |= SEEN_DATAREF | SEEN_XREG;
32546 if (is_imm8(K)) {
32547 EMIT3(0x8d, 0x73, K); /* lea imm8(%rbx), %esi */
32548 } else {
32549- EMIT2(0x8d, 0xb3); /* lea imm32(%rbx),%esi */
32550- EMIT(K, 4);
32551+ EMIT2_off32(0x8d, 0xb3, K); /* lea imm32(%rbx),%esi */
32552 }
32553 } else {
32554 EMIT2(0x89,0xde); /* mov %ebx,%esi */
32555@@ -728,10 +834,12 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
32556 if (unlikely(proglen + ilen > oldproglen)) {
32557 pr_err("bpb_jit_compile fatal error\n");
32558 kfree(addrs);
32559- module_free(NULL, header);
32560+ module_free_exec(NULL, image);
32561 return;
32562 }
32563+ pax_open_kernel();
32564 memcpy(image + proglen, temp, ilen);
32565+ pax_close_kernel();
32566 }
32567 proglen += ilen;
32568 addrs[i] = proglen;
32569@@ -764,7 +872,6 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
32570
32571 if (image) {
32572 bpf_flush_icache(header, image + proglen);
32573- set_memory_ro((unsigned long)header, header->pages);
32574 fp->bpf_func = (void *)image;
32575 }
32576 out:
32577@@ -776,10 +883,9 @@ static void bpf_jit_free_deferred(struct work_struct *work)
32578 {
32579 struct sk_filter *fp = container_of(work, struct sk_filter, work);
32580 unsigned long addr = (unsigned long)fp->bpf_func & PAGE_MASK;
32581- struct bpf_binary_header *header = (void *)addr;
32582
32583- set_memory_rw(addr, header->pages);
32584- module_free(NULL, header);
32585+ set_memory_rw(addr, 1);
32586+ module_free_exec(NULL, (void *)addr);
32587 kfree(fp);
32588 }
32589
32590diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
32591index d6aa6e8..266395a 100644
32592--- a/arch/x86/oprofile/backtrace.c
32593+++ b/arch/x86/oprofile/backtrace.c
32594@@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
32595 struct stack_frame_ia32 *fp;
32596 unsigned long bytes;
32597
32598- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
32599+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
32600 if (bytes != sizeof(bufhead))
32601 return NULL;
32602
32603- fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
32604+ fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
32605
32606 oprofile_add_trace(bufhead[0].return_address);
32607
32608@@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
32609 struct stack_frame bufhead[2];
32610 unsigned long bytes;
32611
32612- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
32613+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
32614 if (bytes != sizeof(bufhead))
32615 return NULL;
32616
32617@@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
32618 {
32619 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
32620
32621- if (!user_mode_vm(regs)) {
32622+ if (!user_mode(regs)) {
32623 unsigned long stack = kernel_stack_pointer(regs);
32624 if (depth)
32625 dump_trace(NULL, regs, (unsigned long *)stack, 0,
32626diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
32627index 6890d84..1dad1f1 100644
32628--- a/arch/x86/oprofile/nmi_int.c
32629+++ b/arch/x86/oprofile/nmi_int.c
32630@@ -23,6 +23,7 @@
32631 #include <asm/nmi.h>
32632 #include <asm/msr.h>
32633 #include <asm/apic.h>
32634+#include <asm/pgtable.h>
32635
32636 #include "op_counter.h"
32637 #include "op_x86_model.h"
32638@@ -774,8 +775,11 @@ int __init op_nmi_init(struct oprofile_operations *ops)
32639 if (ret)
32640 return ret;
32641
32642- if (!model->num_virt_counters)
32643- model->num_virt_counters = model->num_counters;
32644+ if (!model->num_virt_counters) {
32645+ pax_open_kernel();
32646+ *(unsigned int *)&model->num_virt_counters = model->num_counters;
32647+ pax_close_kernel();
32648+ }
32649
32650 mux_init(ops);
32651
32652diff --git a/arch/x86/oprofile/op_model_amd.c b/arch/x86/oprofile/op_model_amd.c
32653index 50d86c0..7985318 100644
32654--- a/arch/x86/oprofile/op_model_amd.c
32655+++ b/arch/x86/oprofile/op_model_amd.c
32656@@ -519,9 +519,11 @@ static int op_amd_init(struct oprofile_operations *ops)
32657 num_counters = AMD64_NUM_COUNTERS;
32658 }
32659
32660- op_amd_spec.num_counters = num_counters;
32661- op_amd_spec.num_controls = num_counters;
32662- op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
32663+ pax_open_kernel();
32664+ *(unsigned int *)&op_amd_spec.num_counters = num_counters;
32665+ *(unsigned int *)&op_amd_spec.num_controls = num_counters;
32666+ *(unsigned int *)&op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
32667+ pax_close_kernel();
32668
32669 return 0;
32670 }
32671diff --git a/arch/x86/oprofile/op_model_ppro.c b/arch/x86/oprofile/op_model_ppro.c
32672index d90528e..0127e2b 100644
32673--- a/arch/x86/oprofile/op_model_ppro.c
32674+++ b/arch/x86/oprofile/op_model_ppro.c
32675@@ -19,6 +19,7 @@
32676 #include <asm/msr.h>
32677 #include <asm/apic.h>
32678 #include <asm/nmi.h>
32679+#include <asm/pgtable.h>
32680
32681 #include "op_x86_model.h"
32682 #include "op_counter.h"
32683@@ -221,8 +222,10 @@ static void arch_perfmon_setup_counters(void)
32684
32685 num_counters = min((int)eax.split.num_counters, OP_MAX_COUNTER);
32686
32687- op_arch_perfmon_spec.num_counters = num_counters;
32688- op_arch_perfmon_spec.num_controls = num_counters;
32689+ pax_open_kernel();
32690+ *(unsigned int *)&op_arch_perfmon_spec.num_counters = num_counters;
32691+ *(unsigned int *)&op_arch_perfmon_spec.num_controls = num_counters;
32692+ pax_close_kernel();
32693 }
32694
32695 static int arch_perfmon_init(struct oprofile_operations *ignore)
32696diff --git a/arch/x86/oprofile/op_x86_model.h b/arch/x86/oprofile/op_x86_model.h
32697index 71e8a67..6a313bb 100644
32698--- a/arch/x86/oprofile/op_x86_model.h
32699+++ b/arch/x86/oprofile/op_x86_model.h
32700@@ -52,7 +52,7 @@ struct op_x86_model_spec {
32701 void (*switch_ctrl)(struct op_x86_model_spec const *model,
32702 struct op_msrs const * const msrs);
32703 #endif
32704-};
32705+} __do_const;
32706
32707 struct op_counter_config;
32708
32709diff --git a/arch/x86/pci/irq.c b/arch/x86/pci/irq.c
32710index 372e9b8..e775a6c 100644
32711--- a/arch/x86/pci/irq.c
32712+++ b/arch/x86/pci/irq.c
32713@@ -50,7 +50,7 @@ struct irq_router {
32714 struct irq_router_handler {
32715 u16 vendor;
32716 int (*probe)(struct irq_router *r, struct pci_dev *router, u16 device);
32717-};
32718+} __do_const;
32719
32720 int (*pcibios_enable_irq)(struct pci_dev *dev) = pirq_enable_irq;
32721 void (*pcibios_disable_irq)(struct pci_dev *dev) = NULL;
32722@@ -794,7 +794,7 @@ static __init int pico_router_probe(struct irq_router *r, struct pci_dev *router
32723 return 0;
32724 }
32725
32726-static __initdata struct irq_router_handler pirq_routers[] = {
32727+static __initconst const struct irq_router_handler pirq_routers[] = {
32728 { PCI_VENDOR_ID_INTEL, intel_router_probe },
32729 { PCI_VENDOR_ID_AL, ali_router_probe },
32730 { PCI_VENDOR_ID_ITE, ite_router_probe },
32731@@ -821,7 +821,7 @@ static struct pci_dev *pirq_router_dev;
32732 static void __init pirq_find_router(struct irq_router *r)
32733 {
32734 struct irq_routing_table *rt = pirq_table;
32735- struct irq_router_handler *h;
32736+ const struct irq_router_handler *h;
32737
32738 #ifdef CONFIG_PCI_BIOS
32739 if (!rt->signature) {
32740@@ -1094,7 +1094,7 @@ static int __init fix_acer_tm360_irqrouting(const struct dmi_system_id *d)
32741 return 0;
32742 }
32743
32744-static struct dmi_system_id __initdata pciirq_dmi_table[] = {
32745+static const struct dmi_system_id __initconst pciirq_dmi_table[] = {
32746 {
32747 .callback = fix_broken_hp_bios_irq9,
32748 .ident = "HP Pavilion N5400 Series Laptop",
32749diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
32750index 903fded..94b0d88 100644
32751--- a/arch/x86/pci/mrst.c
32752+++ b/arch/x86/pci/mrst.c
32753@@ -241,7 +241,9 @@ int __init pci_mrst_init(void)
32754 pr_info("Intel MID platform detected, using MID PCI ops\n");
32755 pci_mmcfg_late_init();
32756 pcibios_enable_irq = mrst_pci_irq_enable;
32757- pci_root_ops = pci_mrst_ops;
32758+ pax_open_kernel();
32759+ memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
32760+ pax_close_kernel();
32761 pci_soc_mode = 1;
32762 /* Continue with standard init */
32763 return 1;
32764diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
32765index c77b24a..c979855 100644
32766--- a/arch/x86/pci/pcbios.c
32767+++ b/arch/x86/pci/pcbios.c
32768@@ -79,7 +79,7 @@ union bios32 {
32769 static struct {
32770 unsigned long address;
32771 unsigned short segment;
32772-} bios32_indirect = { 0, __KERNEL_CS };
32773+} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
32774
32775 /*
32776 * Returns the entry point for the given service, NULL on error
32777@@ -92,37 +92,80 @@ static unsigned long bios32_service(unsigned long service)
32778 unsigned long length; /* %ecx */
32779 unsigned long entry; /* %edx */
32780 unsigned long flags;
32781+ struct desc_struct d, *gdt;
32782
32783 local_irq_save(flags);
32784- __asm__("lcall *(%%edi); cld"
32785+
32786+ gdt = get_cpu_gdt_table(smp_processor_id());
32787+
32788+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
32789+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
32790+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
32791+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
32792+
32793+ __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
32794 : "=a" (return_code),
32795 "=b" (address),
32796 "=c" (length),
32797 "=d" (entry)
32798 : "0" (service),
32799 "1" (0),
32800- "D" (&bios32_indirect));
32801+ "D" (&bios32_indirect),
32802+ "r"(__PCIBIOS_DS)
32803+ : "memory");
32804+
32805+ pax_open_kernel();
32806+ gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
32807+ gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
32808+ gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
32809+ gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
32810+ pax_close_kernel();
32811+
32812 local_irq_restore(flags);
32813
32814 switch (return_code) {
32815- case 0:
32816- return address + entry;
32817- case 0x80: /* Not present */
32818- printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
32819- return 0;
32820- default: /* Shouldn't happen */
32821- printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
32822- service, return_code);
32823+ case 0: {
32824+ int cpu;
32825+ unsigned char flags;
32826+
32827+ printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
32828+ if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
32829+ printk(KERN_WARNING "bios32_service: not valid\n");
32830 return 0;
32831+ }
32832+ address = address + PAGE_OFFSET;
32833+ length += 16UL; /* some BIOSs underreport this... */
32834+ flags = 4;
32835+ if (length >= 64*1024*1024) {
32836+ length >>= PAGE_SHIFT;
32837+ flags |= 8;
32838+ }
32839+
32840+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
32841+ gdt = get_cpu_gdt_table(cpu);
32842+ pack_descriptor(&d, address, length, 0x9b, flags);
32843+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
32844+ pack_descriptor(&d, address, length, 0x93, flags);
32845+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
32846+ }
32847+ return entry;
32848+ }
32849+ case 0x80: /* Not present */
32850+ printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
32851+ return 0;
32852+ default: /* Shouldn't happen */
32853+ printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
32854+ service, return_code);
32855+ return 0;
32856 }
32857 }
32858
32859 static struct {
32860 unsigned long address;
32861 unsigned short segment;
32862-} pci_indirect = { 0, __KERNEL_CS };
32863+} pci_indirect __read_only = { 0, __PCIBIOS_CS };
32864
32865-static int pci_bios_present;
32866+static int pci_bios_present __read_only;
32867
32868 static int check_pcibios(void)
32869 {
32870@@ -131,11 +174,13 @@ static int check_pcibios(void)
32871 unsigned long flags, pcibios_entry;
32872
32873 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
32874- pci_indirect.address = pcibios_entry + PAGE_OFFSET;
32875+ pci_indirect.address = pcibios_entry;
32876
32877 local_irq_save(flags);
32878- __asm__(
32879- "lcall *(%%edi); cld\n\t"
32880+ __asm__("movw %w6, %%ds\n\t"
32881+ "lcall *%%ss:(%%edi); cld\n\t"
32882+ "push %%ss\n\t"
32883+ "pop %%ds\n\t"
32884 "jc 1f\n\t"
32885 "xor %%ah, %%ah\n"
32886 "1:"
32887@@ -144,7 +189,8 @@ static int check_pcibios(void)
32888 "=b" (ebx),
32889 "=c" (ecx)
32890 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
32891- "D" (&pci_indirect)
32892+ "D" (&pci_indirect),
32893+ "r" (__PCIBIOS_DS)
32894 : "memory");
32895 local_irq_restore(flags);
32896
32897@@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
32898
32899 switch (len) {
32900 case 1:
32901- __asm__("lcall *(%%esi); cld\n\t"
32902+ __asm__("movw %w6, %%ds\n\t"
32903+ "lcall *%%ss:(%%esi); cld\n\t"
32904+ "push %%ss\n\t"
32905+ "pop %%ds\n\t"
32906 "jc 1f\n\t"
32907 "xor %%ah, %%ah\n"
32908 "1:"
32909@@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
32910 : "1" (PCIBIOS_READ_CONFIG_BYTE),
32911 "b" (bx),
32912 "D" ((long)reg),
32913- "S" (&pci_indirect));
32914+ "S" (&pci_indirect),
32915+ "r" (__PCIBIOS_DS));
32916 /*
32917 * Zero-extend the result beyond 8 bits, do not trust the
32918 * BIOS having done it:
32919@@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
32920 *value &= 0xff;
32921 break;
32922 case 2:
32923- __asm__("lcall *(%%esi); cld\n\t"
32924+ __asm__("movw %w6, %%ds\n\t"
32925+ "lcall *%%ss:(%%esi); cld\n\t"
32926+ "push %%ss\n\t"
32927+ "pop %%ds\n\t"
32928 "jc 1f\n\t"
32929 "xor %%ah, %%ah\n"
32930 "1:"
32931@@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
32932 : "1" (PCIBIOS_READ_CONFIG_WORD),
32933 "b" (bx),
32934 "D" ((long)reg),
32935- "S" (&pci_indirect));
32936+ "S" (&pci_indirect),
32937+ "r" (__PCIBIOS_DS));
32938 /*
32939 * Zero-extend the result beyond 16 bits, do not trust the
32940 * BIOS having done it:
32941@@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
32942 *value &= 0xffff;
32943 break;
32944 case 4:
32945- __asm__("lcall *(%%esi); cld\n\t"
32946+ __asm__("movw %w6, %%ds\n\t"
32947+ "lcall *%%ss:(%%esi); cld\n\t"
32948+ "push %%ss\n\t"
32949+ "pop %%ds\n\t"
32950 "jc 1f\n\t"
32951 "xor %%ah, %%ah\n"
32952 "1:"
32953@@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
32954 : "1" (PCIBIOS_READ_CONFIG_DWORD),
32955 "b" (bx),
32956 "D" ((long)reg),
32957- "S" (&pci_indirect));
32958+ "S" (&pci_indirect),
32959+ "r" (__PCIBIOS_DS));
32960 break;
32961 }
32962
32963@@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
32964
32965 switch (len) {
32966 case 1:
32967- __asm__("lcall *(%%esi); cld\n\t"
32968+ __asm__("movw %w6, %%ds\n\t"
32969+ "lcall *%%ss:(%%esi); cld\n\t"
32970+ "push %%ss\n\t"
32971+ "pop %%ds\n\t"
32972 "jc 1f\n\t"
32973 "xor %%ah, %%ah\n"
32974 "1:"
32975@@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
32976 "c" (value),
32977 "b" (bx),
32978 "D" ((long)reg),
32979- "S" (&pci_indirect));
32980+ "S" (&pci_indirect),
32981+ "r" (__PCIBIOS_DS));
32982 break;
32983 case 2:
32984- __asm__("lcall *(%%esi); cld\n\t"
32985+ __asm__("movw %w6, %%ds\n\t"
32986+ "lcall *%%ss:(%%esi); cld\n\t"
32987+ "push %%ss\n\t"
32988+ "pop %%ds\n\t"
32989 "jc 1f\n\t"
32990 "xor %%ah, %%ah\n"
32991 "1:"
32992@@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
32993 "c" (value),
32994 "b" (bx),
32995 "D" ((long)reg),
32996- "S" (&pci_indirect));
32997+ "S" (&pci_indirect),
32998+ "r" (__PCIBIOS_DS));
32999 break;
33000 case 4:
33001- __asm__("lcall *(%%esi); cld\n\t"
33002+ __asm__("movw %w6, %%ds\n\t"
33003+ "lcall *%%ss:(%%esi); cld\n\t"
33004+ "push %%ss\n\t"
33005+ "pop %%ds\n\t"
33006 "jc 1f\n\t"
33007 "xor %%ah, %%ah\n"
33008 "1:"
33009@@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
33010 "c" (value),
33011 "b" (bx),
33012 "D" ((long)reg),
33013- "S" (&pci_indirect));
33014+ "S" (&pci_indirect),
33015+ "r" (__PCIBIOS_DS));
33016 break;
33017 }
33018
33019@@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
33020
33021 DBG("PCI: Fetching IRQ routing table... ");
33022 __asm__("push %%es\n\t"
33023+ "movw %w8, %%ds\n\t"
33024 "push %%ds\n\t"
33025 "pop %%es\n\t"
33026- "lcall *(%%esi); cld\n\t"
33027+ "lcall *%%ss:(%%esi); cld\n\t"
33028 "pop %%es\n\t"
33029+ "push %%ss\n\t"
33030+ "pop %%ds\n"
33031 "jc 1f\n\t"
33032 "xor %%ah, %%ah\n"
33033 "1:"
33034@@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
33035 "1" (0),
33036 "D" ((long) &opt),
33037 "S" (&pci_indirect),
33038- "m" (opt)
33039+ "m" (opt),
33040+ "r" (__PCIBIOS_DS)
33041 : "memory");
33042 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
33043 if (ret & 0xff00)
33044@@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
33045 {
33046 int ret;
33047
33048- __asm__("lcall *(%%esi); cld\n\t"
33049+ __asm__("movw %w5, %%ds\n\t"
33050+ "lcall *%%ss:(%%esi); cld\n\t"
33051+ "push %%ss\n\t"
33052+ "pop %%ds\n"
33053 "jc 1f\n\t"
33054 "xor %%ah, %%ah\n"
33055 "1:"
33056@@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
33057 : "0" (PCIBIOS_SET_PCI_HW_INT),
33058 "b" ((dev->bus->number << 8) | dev->devfn),
33059 "c" ((irq << 8) | (pin + 10)),
33060- "S" (&pci_indirect));
33061+ "S" (&pci_indirect),
33062+ "r" (__PCIBIOS_DS));
33063 return !(ret & 0xff00);
33064 }
33065 EXPORT_SYMBOL(pcibios_set_irq_routing);
33066diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
33067index 40e4469..d915bf9 100644
33068--- a/arch/x86/platform/efi/efi_32.c
33069+++ b/arch/x86/platform/efi/efi_32.c
33070@@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
33071 {
33072 struct desc_ptr gdt_descr;
33073
33074+#ifdef CONFIG_PAX_KERNEXEC
33075+ struct desc_struct d;
33076+#endif
33077+
33078 local_irq_save(efi_rt_eflags);
33079
33080 load_cr3(initial_page_table);
33081 __flush_tlb_all();
33082
33083+#ifdef CONFIG_PAX_KERNEXEC
33084+ pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
33085+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
33086+ pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
33087+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
33088+#endif
33089+
33090 gdt_descr.address = __pa(get_cpu_gdt_table(0));
33091 gdt_descr.size = GDT_SIZE - 1;
33092 load_gdt(&gdt_descr);
33093@@ -58,11 +69,24 @@ void efi_call_phys_epilog(void)
33094 {
33095 struct desc_ptr gdt_descr;
33096
33097+#ifdef CONFIG_PAX_KERNEXEC
33098+ struct desc_struct d;
33099+
33100+ memset(&d, 0, sizeof d);
33101+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
33102+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
33103+#endif
33104+
33105 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
33106 gdt_descr.size = GDT_SIZE - 1;
33107 load_gdt(&gdt_descr);
33108
33109+#ifdef CONFIG_PAX_PER_CPU_PGD
33110+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
33111+#else
33112 load_cr3(swapper_pg_dir);
33113+#endif
33114+
33115 __flush_tlb_all();
33116
33117 local_irq_restore(efi_rt_eflags);
33118diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c
33119index 39a0e7f1..872396e 100644
33120--- a/arch/x86/platform/efi/efi_64.c
33121+++ b/arch/x86/platform/efi/efi_64.c
33122@@ -76,6 +76,11 @@ void __init efi_call_phys_prelog(void)
33123 vaddress = (unsigned long)__va(pgd * PGDIR_SIZE);
33124 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), *pgd_offset_k(vaddress));
33125 }
33126+
33127+#ifdef CONFIG_PAX_PER_CPU_PGD
33128+ load_cr3(swapper_pg_dir);
33129+#endif
33130+
33131 __flush_tlb_all();
33132 }
33133
33134@@ -89,6 +94,11 @@ void __init efi_call_phys_epilog(void)
33135 for (pgd = 0; pgd < n_pgds; pgd++)
33136 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), save_pgd[pgd]);
33137 kfree(save_pgd);
33138+
33139+#ifdef CONFIG_PAX_PER_CPU_PGD
33140+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
33141+#endif
33142+
33143 __flush_tlb_all();
33144 local_irq_restore(efi_flags);
33145 early_code_mapping_set_exec(0);
33146diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
33147index fbe66e6..eae5e38 100644
33148--- a/arch/x86/platform/efi/efi_stub_32.S
33149+++ b/arch/x86/platform/efi/efi_stub_32.S
33150@@ -6,7 +6,9 @@
33151 */
33152
33153 #include <linux/linkage.h>
33154+#include <linux/init.h>
33155 #include <asm/page_types.h>
33156+#include <asm/segment.h>
33157
33158 /*
33159 * efi_call_phys(void *, ...) is a function with variable parameters.
33160@@ -20,7 +22,7 @@
33161 * service functions will comply with gcc calling convention, too.
33162 */
33163
33164-.text
33165+__INIT
33166 ENTRY(efi_call_phys)
33167 /*
33168 * 0. The function can only be called in Linux kernel. So CS has been
33169@@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
33170 * The mapping of lower virtual memory has been created in prelog and
33171 * epilog.
33172 */
33173- movl $1f, %edx
33174- subl $__PAGE_OFFSET, %edx
33175- jmp *%edx
33176+#ifdef CONFIG_PAX_KERNEXEC
33177+ movl $(__KERNEXEC_EFI_DS), %edx
33178+ mov %edx, %ds
33179+ mov %edx, %es
33180+ mov %edx, %ss
33181+ addl $2f,(1f)
33182+ ljmp *(1f)
33183+
33184+__INITDATA
33185+1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
33186+.previous
33187+
33188+2:
33189+ subl $2b,(1b)
33190+#else
33191+ jmp 1f-__PAGE_OFFSET
33192 1:
33193+#endif
33194
33195 /*
33196 * 2. Now on the top of stack is the return
33197@@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
33198 * parameter 2, ..., param n. To make things easy, we save the return
33199 * address of efi_call_phys in a global variable.
33200 */
33201- popl %edx
33202- movl %edx, saved_return_addr
33203- /* get the function pointer into ECX*/
33204- popl %ecx
33205- movl %ecx, efi_rt_function_ptr
33206- movl $2f, %edx
33207- subl $__PAGE_OFFSET, %edx
33208- pushl %edx
33209+ popl (saved_return_addr)
33210+ popl (efi_rt_function_ptr)
33211
33212 /*
33213 * 3. Clear PG bit in %CR0.
33214@@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
33215 /*
33216 * 5. Call the physical function.
33217 */
33218- jmp *%ecx
33219+ call *(efi_rt_function_ptr-__PAGE_OFFSET)
33220
33221-2:
33222 /*
33223 * 6. After EFI runtime service returns, control will return to
33224 * following instruction. We'd better readjust stack pointer first.
33225@@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
33226 movl %cr0, %edx
33227 orl $0x80000000, %edx
33228 movl %edx, %cr0
33229- jmp 1f
33230-1:
33231+
33232 /*
33233 * 8. Now restore the virtual mode from flat mode by
33234 * adding EIP with PAGE_OFFSET.
33235 */
33236- movl $1f, %edx
33237- jmp *%edx
33238+#ifdef CONFIG_PAX_KERNEXEC
33239+ movl $(__KERNEL_DS), %edx
33240+ mov %edx, %ds
33241+ mov %edx, %es
33242+ mov %edx, %ss
33243+ ljmp $(__KERNEL_CS),$1f
33244+#else
33245+ jmp 1f+__PAGE_OFFSET
33246+#endif
33247 1:
33248
33249 /*
33250 * 9. Balance the stack. And because EAX contain the return value,
33251 * we'd better not clobber it.
33252 */
33253- leal efi_rt_function_ptr, %edx
33254- movl (%edx), %ecx
33255- pushl %ecx
33256+ pushl (efi_rt_function_ptr)
33257
33258 /*
33259- * 10. Push the saved return address onto the stack and return.
33260+ * 10. Return to the saved return address.
33261 */
33262- leal saved_return_addr, %edx
33263- movl (%edx), %ecx
33264- pushl %ecx
33265- ret
33266+ jmpl *(saved_return_addr)
33267 ENDPROC(efi_call_phys)
33268 .previous
33269
33270-.data
33271+__INITDATA
33272 saved_return_addr:
33273 .long 0
33274 efi_rt_function_ptr:
33275diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
33276index 4c07cca..2c8427d 100644
33277--- a/arch/x86/platform/efi/efi_stub_64.S
33278+++ b/arch/x86/platform/efi/efi_stub_64.S
33279@@ -7,6 +7,7 @@
33280 */
33281
33282 #include <linux/linkage.h>
33283+#include <asm/alternative-asm.h>
33284
33285 #define SAVE_XMM \
33286 mov %rsp, %rax; \
33287@@ -40,6 +41,7 @@ ENTRY(efi_call0)
33288 call *%rdi
33289 addq $32, %rsp
33290 RESTORE_XMM
33291+ pax_force_retaddr 0, 1
33292 ret
33293 ENDPROC(efi_call0)
33294
33295@@ -50,6 +52,7 @@ ENTRY(efi_call1)
33296 call *%rdi
33297 addq $32, %rsp
33298 RESTORE_XMM
33299+ pax_force_retaddr 0, 1
33300 ret
33301 ENDPROC(efi_call1)
33302
33303@@ -60,6 +63,7 @@ ENTRY(efi_call2)
33304 call *%rdi
33305 addq $32, %rsp
33306 RESTORE_XMM
33307+ pax_force_retaddr 0, 1
33308 ret
33309 ENDPROC(efi_call2)
33310
33311@@ -71,6 +75,7 @@ ENTRY(efi_call3)
33312 call *%rdi
33313 addq $32, %rsp
33314 RESTORE_XMM
33315+ pax_force_retaddr 0, 1
33316 ret
33317 ENDPROC(efi_call3)
33318
33319@@ -83,6 +88,7 @@ ENTRY(efi_call4)
33320 call *%rdi
33321 addq $32, %rsp
33322 RESTORE_XMM
33323+ pax_force_retaddr 0, 1
33324 ret
33325 ENDPROC(efi_call4)
33326
33327@@ -96,6 +102,7 @@ ENTRY(efi_call5)
33328 call *%rdi
33329 addq $48, %rsp
33330 RESTORE_XMM
33331+ pax_force_retaddr 0, 1
33332 ret
33333 ENDPROC(efi_call5)
33334
33335@@ -112,5 +119,6 @@ ENTRY(efi_call6)
33336 call *%rdi
33337 addq $48, %rsp
33338 RESTORE_XMM
33339+ pax_force_retaddr 0, 1
33340 ret
33341 ENDPROC(efi_call6)
33342diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
33343index 3ca5957..7909c18 100644
33344--- a/arch/x86/platform/mrst/mrst.c
33345+++ b/arch/x86/platform/mrst/mrst.c
33346@@ -78,13 +78,15 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
33347 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
33348 int sfi_mrtc_num;
33349
33350-static void mrst_power_off(void)
33351+static __noreturn void mrst_power_off(void)
33352 {
33353+ BUG();
33354 }
33355
33356-static void mrst_reboot(void)
33357+static __noreturn void mrst_reboot(void)
33358 {
33359 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
33360+ BUG();
33361 }
33362
33363 /* parse all the mtimer info to a static mtimer array */
33364diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
33365index d6ee929..3637cb5 100644
33366--- a/arch/x86/platform/olpc/olpc_dt.c
33367+++ b/arch/x86/platform/olpc/olpc_dt.c
33368@@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
33369 return res;
33370 }
33371
33372-static struct of_pdt_ops prom_olpc_ops __initdata = {
33373+static struct of_pdt_ops prom_olpc_ops __initconst = {
33374 .nextprop = olpc_dt_nextprop,
33375 .getproplen = olpc_dt_getproplen,
33376 .getproperty = olpc_dt_getproperty,
33377diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
33378index 424f4c9..f2a2988 100644
33379--- a/arch/x86/power/cpu.c
33380+++ b/arch/x86/power/cpu.c
33381@@ -137,11 +137,8 @@ static void do_fpu_end(void)
33382 static void fix_processor_context(void)
33383 {
33384 int cpu = smp_processor_id();
33385- struct tss_struct *t = &per_cpu(init_tss, cpu);
33386-#ifdef CONFIG_X86_64
33387- struct desc_struct *desc = get_cpu_gdt_table(cpu);
33388- tss_desc tss;
33389-#endif
33390+ struct tss_struct *t = init_tss + cpu;
33391+
33392 set_tss_desc(cpu, t); /*
33393 * This just modifies memory; should not be
33394 * necessary. But... This is necessary, because
33395@@ -150,10 +147,6 @@ static void fix_processor_context(void)
33396 */
33397
33398 #ifdef CONFIG_X86_64
33399- memcpy(&tss, &desc[GDT_ENTRY_TSS], sizeof(tss_desc));
33400- tss.type = 0x9; /* The available 64-bit TSS (see AMD vol 2, pg 91 */
33401- write_gdt_entry(desc, GDT_ENTRY_TSS, &tss, DESC_TSS);
33402-
33403 syscall_init(); /* This sets MSR_*STAR and related */
33404 #endif
33405 load_TR_desc(); /* This does ltr */
33406diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
33407index a44f457..9140171 100644
33408--- a/arch/x86/realmode/init.c
33409+++ b/arch/x86/realmode/init.c
33410@@ -70,7 +70,13 @@ void __init setup_real_mode(void)
33411 __va(real_mode_header->trampoline_header);
33412
33413 #ifdef CONFIG_X86_32
33414- trampoline_header->start = __pa_symbol(startup_32_smp);
33415+ trampoline_header->start = __pa_symbol(ktla_ktva(startup_32_smp));
33416+
33417+#ifdef CONFIG_PAX_KERNEXEC
33418+ trampoline_header->start -= LOAD_PHYSICAL_ADDR;
33419+#endif
33420+
33421+ trampoline_header->boot_cs = __BOOT_CS;
33422 trampoline_header->gdt_limit = __BOOT_DS + 7;
33423 trampoline_header->gdt_base = __pa_symbol(boot_gdt);
33424 #else
33425@@ -86,7 +92,7 @@ void __init setup_real_mode(void)
33426 *trampoline_cr4_features = read_cr4();
33427
33428 trampoline_pgd = (u64 *) __va(real_mode_header->trampoline_pgd);
33429- trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd;
33430+ trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd & ~_PAGE_NX;
33431 trampoline_pgd[511] = init_level4_pgt[511].pgd;
33432 #endif
33433 }
33434diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
33435index 8869287..d577672 100644
33436--- a/arch/x86/realmode/rm/Makefile
33437+++ b/arch/x86/realmode/rm/Makefile
33438@@ -78,5 +78,8 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ -D_WAKEUP \
33439 $(call cc-option, -fno-unit-at-a-time)) \
33440 $(call cc-option, -fno-stack-protector) \
33441 $(call cc-option, -mpreferred-stack-boundary=2)
33442+ifdef CONSTIFY_PLUGIN
33443+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
33444+endif
33445 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
33446 GCOV_PROFILE := n
33447diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
33448index a28221d..93c40f1 100644
33449--- a/arch/x86/realmode/rm/header.S
33450+++ b/arch/x86/realmode/rm/header.S
33451@@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
33452 #endif
33453 /* APM/BIOS reboot */
33454 .long pa_machine_real_restart_asm
33455-#ifdef CONFIG_X86_64
33456+#ifdef CONFIG_X86_32
33457+ .long __KERNEL_CS
33458+#else
33459 .long __KERNEL32_CS
33460 #endif
33461 END(real_mode_header)
33462diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
33463index c1b2791..f9e31c7 100644
33464--- a/arch/x86/realmode/rm/trampoline_32.S
33465+++ b/arch/x86/realmode/rm/trampoline_32.S
33466@@ -25,6 +25,12 @@
33467 #include <asm/page_types.h>
33468 #include "realmode.h"
33469
33470+#ifdef CONFIG_PAX_KERNEXEC
33471+#define ta(X) (X)
33472+#else
33473+#define ta(X) (pa_ ## X)
33474+#endif
33475+
33476 .text
33477 .code16
33478
33479@@ -39,8 +45,6 @@ ENTRY(trampoline_start)
33480
33481 cli # We should be safe anyway
33482
33483- movl tr_start, %eax # where we need to go
33484-
33485 movl $0xA5A5A5A5, trampoline_status
33486 # write marker for master knows we're running
33487
33488@@ -56,7 +60,7 @@ ENTRY(trampoline_start)
33489 movw $1, %dx # protected mode (PE) bit
33490 lmsw %dx # into protected mode
33491
33492- ljmpl $__BOOT_CS, $pa_startup_32
33493+ ljmpl *(trampoline_header)
33494
33495 .section ".text32","ax"
33496 .code32
33497@@ -67,7 +71,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
33498 .balign 8
33499 GLOBAL(trampoline_header)
33500 tr_start: .space 4
33501- tr_gdt_pad: .space 2
33502+ tr_boot_cs: .space 2
33503 tr_gdt: .space 6
33504 END(trampoline_header)
33505
33506diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
33507index bb360dc..d0fd8f8 100644
33508--- a/arch/x86/realmode/rm/trampoline_64.S
33509+++ b/arch/x86/realmode/rm/trampoline_64.S
33510@@ -94,6 +94,7 @@ ENTRY(startup_32)
33511 movl %edx, %gs
33512
33513 movl pa_tr_cr4, %eax
33514+ andl $~X86_CR4_PCIDE, %eax
33515 movl %eax, %cr4 # Enable PAE mode
33516
33517 # Setup trampoline 4 level pagetables
33518@@ -107,7 +108,7 @@ ENTRY(startup_32)
33519 wrmsr
33520
33521 # Enable paging and in turn activate Long Mode
33522- movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
33523+ movl $(X86_CR0_PG | X86_CR0_PE), %eax
33524 movl %eax, %cr0
33525
33526 /*
33527diff --git a/arch/x86/tools/Makefile b/arch/x86/tools/Makefile
33528index e812034..c747134 100644
33529--- a/arch/x86/tools/Makefile
33530+++ b/arch/x86/tools/Makefile
33531@@ -37,7 +37,7 @@ $(obj)/test_get_len.o: $(srctree)/arch/x86/lib/insn.c $(srctree)/arch/x86/lib/in
33532
33533 $(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
33534
33535-HOST_EXTRACFLAGS += -I$(srctree)/tools/include
33536+HOST_EXTRACFLAGS += -I$(srctree)/tools/include -ggdb
33537 hostprogs-y += relocs
33538 relocs-objs := relocs_32.o relocs_64.o relocs_common.o
33539 relocs: $(obj)/relocs
33540diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
33541index f7bab68..b6d9886 100644
33542--- a/arch/x86/tools/relocs.c
33543+++ b/arch/x86/tools/relocs.c
33544@@ -1,5 +1,7 @@
33545 /* This is included from relocs_32/64.c */
33546
33547+#include "../../../include/generated/autoconf.h"
33548+
33549 #define ElfW(type) _ElfW(ELF_BITS, type)
33550 #define _ElfW(bits, type) __ElfW(bits, type)
33551 #define __ElfW(bits, type) Elf##bits##_##type
33552@@ -11,6 +13,7 @@
33553 #define Elf_Sym ElfW(Sym)
33554
33555 static Elf_Ehdr ehdr;
33556+static Elf_Phdr *phdr;
33557
33558 struct relocs {
33559 uint32_t *offset;
33560@@ -383,9 +386,39 @@ static void read_ehdr(FILE *fp)
33561 }
33562 }
33563
33564+static void read_phdrs(FILE *fp)
33565+{
33566+ unsigned int i;
33567+
33568+ phdr = calloc(ehdr.e_phnum, sizeof(Elf_Phdr));
33569+ if (!phdr) {
33570+ die("Unable to allocate %d program headers\n",
33571+ ehdr.e_phnum);
33572+ }
33573+ if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
33574+ die("Seek to %d failed: %s\n",
33575+ ehdr.e_phoff, strerror(errno));
33576+ }
33577+ if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
33578+ die("Cannot read ELF program headers: %s\n",
33579+ strerror(errno));
33580+ }
33581+ for(i = 0; i < ehdr.e_phnum; i++) {
33582+ phdr[i].p_type = elf_word_to_cpu(phdr[i].p_type);
33583+ phdr[i].p_offset = elf_off_to_cpu(phdr[i].p_offset);
33584+ phdr[i].p_vaddr = elf_addr_to_cpu(phdr[i].p_vaddr);
33585+ phdr[i].p_paddr = elf_addr_to_cpu(phdr[i].p_paddr);
33586+ phdr[i].p_filesz = elf_word_to_cpu(phdr[i].p_filesz);
33587+ phdr[i].p_memsz = elf_word_to_cpu(phdr[i].p_memsz);
33588+ phdr[i].p_flags = elf_word_to_cpu(phdr[i].p_flags);
33589+ phdr[i].p_align = elf_word_to_cpu(phdr[i].p_align);
33590+ }
33591+
33592+}
33593+
33594 static void read_shdrs(FILE *fp)
33595 {
33596- int i;
33597+ unsigned int i;
33598 Elf_Shdr shdr;
33599
33600 secs = calloc(ehdr.e_shnum, sizeof(struct section));
33601@@ -420,7 +453,7 @@ static void read_shdrs(FILE *fp)
33602
33603 static void read_strtabs(FILE *fp)
33604 {
33605- int i;
33606+ unsigned int i;
33607 for (i = 0; i < ehdr.e_shnum; i++) {
33608 struct section *sec = &secs[i];
33609 if (sec->shdr.sh_type != SHT_STRTAB) {
33610@@ -445,7 +478,7 @@ static void read_strtabs(FILE *fp)
33611
33612 static void read_symtabs(FILE *fp)
33613 {
33614- int i,j;
33615+ unsigned int i,j;
33616 for (i = 0; i < ehdr.e_shnum; i++) {
33617 struct section *sec = &secs[i];
33618 if (sec->shdr.sh_type != SHT_SYMTAB) {
33619@@ -476,9 +509,11 @@ static void read_symtabs(FILE *fp)
33620 }
33621
33622
33623-static void read_relocs(FILE *fp)
33624+static void read_relocs(FILE *fp, int use_real_mode)
33625 {
33626- int i,j;
33627+ unsigned int i,j;
33628+ uint32_t base;
33629+
33630 for (i = 0; i < ehdr.e_shnum; i++) {
33631 struct section *sec = &secs[i];
33632 if (sec->shdr.sh_type != SHT_REL_TYPE) {
33633@@ -498,9 +533,22 @@ static void read_relocs(FILE *fp)
33634 die("Cannot read symbol table: %s\n",
33635 strerror(errno));
33636 }
33637+ base = 0;
33638+
33639+#ifdef CONFIG_X86_32
33640+ for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
33641+ if (phdr[j].p_type != PT_LOAD )
33642+ continue;
33643+ 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)
33644+ continue;
33645+ base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
33646+ break;
33647+ }
33648+#endif
33649+
33650 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf_Rel); j++) {
33651 Elf_Rel *rel = &sec->reltab[j];
33652- rel->r_offset = elf_addr_to_cpu(rel->r_offset);
33653+ rel->r_offset = elf_addr_to_cpu(rel->r_offset) + base;
33654 rel->r_info = elf_xword_to_cpu(rel->r_info);
33655 #if (SHT_REL_TYPE == SHT_RELA)
33656 rel->r_addend = elf_xword_to_cpu(rel->r_addend);
33657@@ -512,7 +560,7 @@ static void read_relocs(FILE *fp)
33658
33659 static void print_absolute_symbols(void)
33660 {
33661- int i;
33662+ unsigned int i;
33663 const char *format;
33664
33665 if (ELF_BITS == 64)
33666@@ -525,7 +573,7 @@ static void print_absolute_symbols(void)
33667 for (i = 0; i < ehdr.e_shnum; i++) {
33668 struct section *sec = &secs[i];
33669 char *sym_strtab;
33670- int j;
33671+ unsigned int j;
33672
33673 if (sec->shdr.sh_type != SHT_SYMTAB) {
33674 continue;
33675@@ -552,7 +600,7 @@ static void print_absolute_symbols(void)
33676
33677 static void print_absolute_relocs(void)
33678 {
33679- int i, printed = 0;
33680+ unsigned int i, printed = 0;
33681 const char *format;
33682
33683 if (ELF_BITS == 64)
33684@@ -565,7 +613,7 @@ static void print_absolute_relocs(void)
33685 struct section *sec_applies, *sec_symtab;
33686 char *sym_strtab;
33687 Elf_Sym *sh_symtab;
33688- int j;
33689+ unsigned int j;
33690 if (sec->shdr.sh_type != SHT_REL_TYPE) {
33691 continue;
33692 }
33693@@ -642,13 +690,13 @@ static void add_reloc(struct relocs *r, uint32_t offset)
33694 static void walk_relocs(int (*process)(struct section *sec, Elf_Rel *rel,
33695 Elf_Sym *sym, const char *symname))
33696 {
33697- int i;
33698+ unsigned int i;
33699 /* Walk through the relocations */
33700 for (i = 0; i < ehdr.e_shnum; i++) {
33701 char *sym_strtab;
33702 Elf_Sym *sh_symtab;
33703 struct section *sec_applies, *sec_symtab;
33704- int j;
33705+ unsigned int j;
33706 struct section *sec = &secs[i];
33707
33708 if (sec->shdr.sh_type != SHT_REL_TYPE) {
33709@@ -812,6 +860,23 @@ static int do_reloc32(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
33710 {
33711 unsigned r_type = ELF32_R_TYPE(rel->r_info);
33712 int shn_abs = (sym->st_shndx == SHN_ABS) && !is_reloc(S_REL, symname);
33713+ char *sym_strtab = sec->link->link->strtab;
33714+
33715+ /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
33716+ if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
33717+ return 0;
33718+
33719+#ifdef CONFIG_PAX_KERNEXEC
33720+ /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
33721+ if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
33722+ return 0;
33723+ if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
33724+ return 0;
33725+ if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
33726+ return 0;
33727+ if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
33728+ return 0;
33729+#endif
33730
33731 switch (r_type) {
33732 case R_386_NONE:
33733@@ -950,7 +1015,7 @@ static int write32_as_text(uint32_t v, FILE *f)
33734
33735 static void emit_relocs(int as_text, int use_real_mode)
33736 {
33737- int i;
33738+ unsigned int i;
33739 int (*write_reloc)(uint32_t, FILE *) = write32;
33740 int (*do_reloc)(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
33741 const char *symname);
33742@@ -1026,10 +1091,11 @@ void process(FILE *fp, int use_real_mode, int as_text,
33743 {
33744 regex_init(use_real_mode);
33745 read_ehdr(fp);
33746+ read_phdrs(fp);
33747 read_shdrs(fp);
33748 read_strtabs(fp);
33749 read_symtabs(fp);
33750- read_relocs(fp);
33751+ read_relocs(fp, use_real_mode);
33752 if (ELF_BITS == 64)
33753 percpu_init();
33754 if (show_absolute_syms) {
33755diff --git a/arch/x86/um/tls_32.c b/arch/x86/um/tls_32.c
33756index 80ffa5b..a33bd15 100644
33757--- a/arch/x86/um/tls_32.c
33758+++ b/arch/x86/um/tls_32.c
33759@@ -260,7 +260,7 @@ out:
33760 if (unlikely(task == current &&
33761 !t->arch.tls_array[idx - GDT_ENTRY_TLS_MIN].flushed)) {
33762 printk(KERN_ERR "get_tls_entry: task with pid %d got here "
33763- "without flushed TLS.", current->pid);
33764+ "without flushed TLS.", task_pid_nr(current));
33765 }
33766
33767 return 0;
33768diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
33769index fd14be1..e3c79c0 100644
33770--- a/arch/x86/vdso/Makefile
33771+++ b/arch/x86/vdso/Makefile
33772@@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
33773 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
33774 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
33775
33776-VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
33777+VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
33778 GCOV_PROFILE := n
33779
33780 #
33781diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
33782index d6bfb87..876ee18 100644
33783--- a/arch/x86/vdso/vdso32-setup.c
33784+++ b/arch/x86/vdso/vdso32-setup.c
33785@@ -25,6 +25,7 @@
33786 #include <asm/tlbflush.h>
33787 #include <asm/vdso.h>
33788 #include <asm/proto.h>
33789+#include <asm/mman.h>
33790
33791 enum {
33792 VDSO_DISABLED = 0,
33793@@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
33794 void enable_sep_cpu(void)
33795 {
33796 int cpu = get_cpu();
33797- struct tss_struct *tss = &per_cpu(init_tss, cpu);
33798+ struct tss_struct *tss = init_tss + cpu;
33799
33800 if (!boot_cpu_has(X86_FEATURE_SEP)) {
33801 put_cpu();
33802@@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
33803 gate_vma.vm_start = FIXADDR_USER_START;
33804 gate_vma.vm_end = FIXADDR_USER_END;
33805 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
33806- gate_vma.vm_page_prot = __P101;
33807+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
33808
33809 return 0;
33810 }
33811@@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
33812 if (compat)
33813 addr = VDSO_HIGH_BASE;
33814 else {
33815- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
33816+ addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
33817 if (IS_ERR_VALUE(addr)) {
33818 ret = addr;
33819 goto up_fail;
33820 }
33821 }
33822
33823- current->mm->context.vdso = (void *)addr;
33824+ current->mm->context.vdso = addr;
33825
33826 if (compat_uses_vma || !compat) {
33827 /*
33828@@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
33829 }
33830
33831 current_thread_info()->sysenter_return =
33832- VDSO32_SYMBOL(addr, SYSENTER_RETURN);
33833+ (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
33834
33835 up_fail:
33836 if (ret)
33837- current->mm->context.vdso = NULL;
33838+ current->mm->context.vdso = 0;
33839
33840 up_write(&mm->mmap_sem);
33841
33842@@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
33843
33844 const char *arch_vma_name(struct vm_area_struct *vma)
33845 {
33846- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
33847+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
33848 return "[vdso]";
33849+
33850+#ifdef CONFIG_PAX_SEGMEXEC
33851+ if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
33852+ return "[vdso]";
33853+#endif
33854+
33855 return NULL;
33856 }
33857
33858@@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
33859 * Check to see if the corresponding task was created in compat vdso
33860 * mode.
33861 */
33862- if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
33863+ if (mm && mm->context.vdso == VDSO_HIGH_BASE)
33864 return &gate_vma;
33865 return NULL;
33866 }
33867diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
33868index 431e875..cbb23f3 100644
33869--- a/arch/x86/vdso/vma.c
33870+++ b/arch/x86/vdso/vma.c
33871@@ -16,8 +16,6 @@
33872 #include <asm/vdso.h>
33873 #include <asm/page.h>
33874
33875-unsigned int __read_mostly vdso_enabled = 1;
33876-
33877 extern char vdso_start[], vdso_end[];
33878 extern unsigned short vdso_sync_cpuid;
33879
33880@@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
33881 * unaligned here as a result of stack start randomization.
33882 */
33883 addr = PAGE_ALIGN(addr);
33884- addr = align_vdso_addr(addr);
33885
33886 return addr;
33887 }
33888@@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
33889 unsigned size)
33890 {
33891 struct mm_struct *mm = current->mm;
33892- unsigned long addr;
33893+ unsigned long addr = 0;
33894 int ret;
33895
33896- if (!vdso_enabled)
33897- return 0;
33898-
33899 down_write(&mm->mmap_sem);
33900+
33901+#ifdef CONFIG_PAX_RANDMMAP
33902+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
33903+#endif
33904+
33905 addr = vdso_addr(mm->start_stack, size);
33906+ addr = align_vdso_addr(addr);
33907 addr = get_unmapped_area(NULL, addr, size, 0, 0);
33908 if (IS_ERR_VALUE(addr)) {
33909 ret = addr;
33910 goto up_fail;
33911 }
33912
33913- current->mm->context.vdso = (void *)addr;
33914+ mm->context.vdso = addr;
33915
33916 ret = install_special_mapping(mm, addr, size,
33917 VM_READ|VM_EXEC|
33918 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
33919 pages);
33920- if (ret) {
33921- current->mm->context.vdso = NULL;
33922- goto up_fail;
33923- }
33924+ if (ret)
33925+ mm->context.vdso = 0;
33926
33927 up_fail:
33928 up_write(&mm->mmap_sem);
33929@@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
33930 vdsox32_size);
33931 }
33932 #endif
33933-
33934-static __init int vdso_setup(char *s)
33935-{
33936- vdso_enabled = simple_strtoul(s, NULL, 0);
33937- return 0;
33938-}
33939-__setup("vdso=", vdso_setup);
33940diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
33941index fa6ade7..73da73a5 100644
33942--- a/arch/x86/xen/enlighten.c
33943+++ b/arch/x86/xen/enlighten.c
33944@@ -123,8 +123,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
33945
33946 struct shared_info xen_dummy_shared_info;
33947
33948-void *xen_initial_gdt;
33949-
33950 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
33951 __read_mostly int xen_have_vector_callback;
33952 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
33953@@ -541,8 +539,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
33954 {
33955 unsigned long va = dtr->address;
33956 unsigned int size = dtr->size + 1;
33957- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
33958- unsigned long frames[pages];
33959+ unsigned long frames[65536 / PAGE_SIZE];
33960 int f;
33961
33962 /*
33963@@ -590,8 +587,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
33964 {
33965 unsigned long va = dtr->address;
33966 unsigned int size = dtr->size + 1;
33967- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
33968- unsigned long frames[pages];
33969+ unsigned long frames[(GDT_SIZE + PAGE_SIZE - 1) / PAGE_SIZE];
33970 int f;
33971
33972 /*
33973@@ -599,7 +595,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
33974 * 8-byte entries, or 16 4k pages..
33975 */
33976
33977- BUG_ON(size > 65536);
33978+ BUG_ON(size > GDT_SIZE);
33979 BUG_ON(va & ~PAGE_MASK);
33980
33981 for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) {
33982@@ -988,7 +984,7 @@ static u32 xen_safe_apic_wait_icr_idle(void)
33983 return 0;
33984 }
33985
33986-static void set_xen_basic_apic_ops(void)
33987+static void __init set_xen_basic_apic_ops(void)
33988 {
33989 apic->read = xen_apic_read;
33990 apic->write = xen_apic_write;
33991@@ -1293,30 +1289,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
33992 #endif
33993 };
33994
33995-static void xen_reboot(int reason)
33996+static __noreturn void xen_reboot(int reason)
33997 {
33998 struct sched_shutdown r = { .reason = reason };
33999
34000- if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
34001- BUG();
34002+ HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
34003+ BUG();
34004 }
34005
34006-static void xen_restart(char *msg)
34007+static __noreturn void xen_restart(char *msg)
34008 {
34009 xen_reboot(SHUTDOWN_reboot);
34010 }
34011
34012-static void xen_emergency_restart(void)
34013+static __noreturn void xen_emergency_restart(void)
34014 {
34015 xen_reboot(SHUTDOWN_reboot);
34016 }
34017
34018-static void xen_machine_halt(void)
34019+static __noreturn void xen_machine_halt(void)
34020 {
34021 xen_reboot(SHUTDOWN_poweroff);
34022 }
34023
34024-static void xen_machine_power_off(void)
34025+static __noreturn void xen_machine_power_off(void)
34026 {
34027 if (pm_power_off)
34028 pm_power_off();
34029@@ -1467,7 +1463,17 @@ asmlinkage void __init xen_start_kernel(void)
34030 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
34031
34032 /* Work out if we support NX */
34033- x86_configure_nx();
34034+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
34035+ if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
34036+ (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
34037+ unsigned l, h;
34038+
34039+ __supported_pte_mask |= _PAGE_NX;
34040+ rdmsr(MSR_EFER, l, h);
34041+ l |= EFER_NX;
34042+ wrmsr(MSR_EFER, l, h);
34043+ }
34044+#endif
34045
34046 xen_setup_features();
34047
34048@@ -1498,13 +1504,6 @@ asmlinkage void __init xen_start_kernel(void)
34049
34050 machine_ops = xen_machine_ops;
34051
34052- /*
34053- * The only reliable way to retain the initial address of the
34054- * percpu gdt_page is to remember it here, so we can go and
34055- * mark it RW later, when the initial percpu area is freed.
34056- */
34057- xen_initial_gdt = &per_cpu(gdt_page, 0);
34058-
34059 xen_smp_init();
34060
34061 #ifdef CONFIG_ACPI_NUMA
34062diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
34063index fdc3ba2..23cae00 100644
34064--- a/arch/x86/xen/mmu.c
34065+++ b/arch/x86/xen/mmu.c
34066@@ -379,7 +379,7 @@ static pteval_t pte_mfn_to_pfn(pteval_t val)
34067 return val;
34068 }
34069
34070-static pteval_t pte_pfn_to_mfn(pteval_t val)
34071+static pteval_t __intentional_overflow(-1) pte_pfn_to_mfn(pteval_t val)
34072 {
34073 if (val & _PAGE_PRESENT) {
34074 unsigned long pfn = (val & PTE_PFN_MASK) >> PAGE_SHIFT;
34075@@ -1894,6 +1894,9 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
34076 /* L3_k[510] -> level2_kernel_pgt
34077 * L3_i[511] -> level2_fixmap_pgt */
34078 convert_pfn_mfn(level3_kernel_pgt);
34079+ convert_pfn_mfn(level3_vmalloc_start_pgt);
34080+ convert_pfn_mfn(level3_vmalloc_end_pgt);
34081+ convert_pfn_mfn(level3_vmemmap_pgt);
34082
34083 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
34084 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
34085@@ -1923,8 +1926,12 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
34086 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
34087 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
34088 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
34089+ set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
34090+ set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
34091+ set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
34092 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
34093 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
34094+ set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
34095 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
34096 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
34097
34098@@ -2108,6 +2115,7 @@ static void __init xen_post_allocator_init(void)
34099 pv_mmu_ops.set_pud = xen_set_pud;
34100 #if PAGETABLE_LEVELS == 4
34101 pv_mmu_ops.set_pgd = xen_set_pgd;
34102+ pv_mmu_ops.set_pgd_batched = xen_set_pgd;
34103 #endif
34104
34105 /* This will work as long as patching hasn't happened yet
34106@@ -2186,6 +2194,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
34107 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
34108 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
34109 .set_pgd = xen_set_pgd_hyper,
34110+ .set_pgd_batched = xen_set_pgd_hyper,
34111
34112 .alloc_pud = xen_alloc_pmd_init,
34113 .release_pud = xen_release_pmd_init,
34114diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
34115index 31d0475..51af671 100644
34116--- a/arch/x86/xen/smp.c
34117+++ b/arch/x86/xen/smp.c
34118@@ -274,17 +274,13 @@ static void __init xen_smp_prepare_boot_cpu(void)
34119 native_smp_prepare_boot_cpu();
34120
34121 if (xen_pv_domain()) {
34122- /* We've switched to the "real" per-cpu gdt, so make sure the
34123- old memory can be recycled */
34124- make_lowmem_page_readwrite(xen_initial_gdt);
34125-
34126 #ifdef CONFIG_X86_32
34127 /*
34128 * Xen starts us with XEN_FLAT_RING1_DS, but linux code
34129 * expects __USER_DS
34130 */
34131- loadsegment(ds, __USER_DS);
34132- loadsegment(es, __USER_DS);
34133+ loadsegment(ds, __KERNEL_DS);
34134+ loadsegment(es, __KERNEL_DS);
34135 #endif
34136
34137 xen_filter_cpu_maps();
34138@@ -364,7 +360,7 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
34139 ctxt->user_regs.ss = __KERNEL_DS;
34140 #ifdef CONFIG_X86_32
34141 ctxt->user_regs.fs = __KERNEL_PERCPU;
34142- ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
34143+ savesegment(gs, ctxt->user_regs.gs);
34144 #else
34145 ctxt->gs_base_kernel = per_cpu_offset(cpu);
34146 #endif
34147@@ -374,8 +370,8 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
34148
34149 {
34150 ctxt->user_regs.eflags = 0x1000; /* IOPL_RING1 */
34151- ctxt->user_regs.ds = __USER_DS;
34152- ctxt->user_regs.es = __USER_DS;
34153+ ctxt->user_regs.ds = __KERNEL_DS;
34154+ ctxt->user_regs.es = __KERNEL_DS;
34155
34156 xen_copy_trap_info(ctxt->trap_ctxt);
34157
34158@@ -420,13 +416,12 @@ static int xen_cpu_up(unsigned int cpu, struct task_struct *idle)
34159 int rc;
34160
34161 per_cpu(current_task, cpu) = idle;
34162+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
34163 #ifdef CONFIG_X86_32
34164 irq_ctx_init(cpu);
34165 #else
34166 clear_tsk_thread_flag(idle, TIF_FORK);
34167- per_cpu(kernel_stack, cpu) =
34168- (unsigned long)task_stack_page(idle) -
34169- KERNEL_STACK_OFFSET + THREAD_SIZE;
34170+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
34171 #endif
34172 xen_setup_runstate_info(cpu);
34173 xen_setup_timer(cpu);
34174@@ -702,7 +697,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
34175
34176 void __init xen_smp_init(void)
34177 {
34178- smp_ops = xen_smp_ops;
34179+ memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
34180 xen_fill_possible_map();
34181 }
34182
34183diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
34184index 33ca6e4..0ded929 100644
34185--- a/arch/x86/xen/xen-asm_32.S
34186+++ b/arch/x86/xen/xen-asm_32.S
34187@@ -84,14 +84,14 @@ ENTRY(xen_iret)
34188 ESP_OFFSET=4 # bytes pushed onto stack
34189
34190 /*
34191- * Store vcpu_info pointer for easy access. Do it this way to
34192- * avoid having to reload %fs
34193+ * Store vcpu_info pointer for easy access.
34194 */
34195 #ifdef CONFIG_SMP
34196- GET_THREAD_INFO(%eax)
34197- movl %ss:TI_cpu(%eax), %eax
34198- movl %ss:__per_cpu_offset(,%eax,4), %eax
34199- mov %ss:xen_vcpu(%eax), %eax
34200+ push %fs
34201+ mov $(__KERNEL_PERCPU), %eax
34202+ mov %eax, %fs
34203+ mov PER_CPU_VAR(xen_vcpu), %eax
34204+ pop %fs
34205 #else
34206 movl %ss:xen_vcpu, %eax
34207 #endif
34208diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
34209index 7faed58..ba4427c 100644
34210--- a/arch/x86/xen/xen-head.S
34211+++ b/arch/x86/xen/xen-head.S
34212@@ -19,6 +19,17 @@ ENTRY(startup_xen)
34213 #ifdef CONFIG_X86_32
34214 mov %esi,xen_start_info
34215 mov $init_thread_union+THREAD_SIZE,%esp
34216+#ifdef CONFIG_SMP
34217+ movl $cpu_gdt_table,%edi
34218+ movl $__per_cpu_load,%eax
34219+ movw %ax,__KERNEL_PERCPU + 2(%edi)
34220+ rorl $16,%eax
34221+ movb %al,__KERNEL_PERCPU + 4(%edi)
34222+ movb %ah,__KERNEL_PERCPU + 7(%edi)
34223+ movl $__per_cpu_end - 1,%eax
34224+ subl $__per_cpu_start,%eax
34225+ movw %ax,__KERNEL_PERCPU + 0(%edi)
34226+#endif
34227 #else
34228 mov %rsi,xen_start_info
34229 mov $init_thread_union+THREAD_SIZE,%rsp
34230diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
34231index 95f8c61..611d6e8 100644
34232--- a/arch/x86/xen/xen-ops.h
34233+++ b/arch/x86/xen/xen-ops.h
34234@@ -10,8 +10,6 @@
34235 extern const char xen_hypervisor_callback[];
34236 extern const char xen_failsafe_callback[];
34237
34238-extern void *xen_initial_gdt;
34239-
34240 struct trap_info;
34241 void xen_copy_trap_info(struct trap_info *traps);
34242
34243diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
34244index 525bd3d..ef888b1 100644
34245--- a/arch/xtensa/variants/dc232b/include/variant/core.h
34246+++ b/arch/xtensa/variants/dc232b/include/variant/core.h
34247@@ -119,9 +119,9 @@
34248 ----------------------------------------------------------------------*/
34249
34250 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
34251-#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
34252 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
34253 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
34254+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
34255
34256 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
34257 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
34258diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
34259index 2f33760..835e50a 100644
34260--- a/arch/xtensa/variants/fsf/include/variant/core.h
34261+++ b/arch/xtensa/variants/fsf/include/variant/core.h
34262@@ -11,6 +11,7 @@
34263 #ifndef _XTENSA_CORE_H
34264 #define _XTENSA_CORE_H
34265
34266+#include <linux/const.h>
34267
34268 /****************************************************************************
34269 Parameters Useful for Any Code, USER or PRIVILEGED
34270@@ -112,9 +113,9 @@
34271 ----------------------------------------------------------------------*/
34272
34273 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
34274-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
34275 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
34276 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
34277+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
34278
34279 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
34280 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
34281diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
34282index af00795..2bb8105 100644
34283--- a/arch/xtensa/variants/s6000/include/variant/core.h
34284+++ b/arch/xtensa/variants/s6000/include/variant/core.h
34285@@ -11,6 +11,7 @@
34286 #ifndef _XTENSA_CORE_CONFIGURATION_H
34287 #define _XTENSA_CORE_CONFIGURATION_H
34288
34289+#include <linux/const.h>
34290
34291 /****************************************************************************
34292 Parameters Useful for Any Code, USER or PRIVILEGED
34293@@ -118,9 +119,9 @@
34294 ----------------------------------------------------------------------*/
34295
34296 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
34297-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
34298 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
34299 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
34300+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
34301
34302 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
34303 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
34304diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
34305index 4e491d9..c8e18e4 100644
34306--- a/block/blk-cgroup.c
34307+++ b/block/blk-cgroup.c
34308@@ -812,7 +812,7 @@ static void blkcg_css_free(struct cgroup_subsys_state *css)
34309 static struct cgroup_subsys_state *
34310 blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
34311 {
34312- static atomic64_t id_seq = ATOMIC64_INIT(0);
34313+ static atomic64_unchecked_t id_seq = ATOMIC64_INIT(0);
34314 struct blkcg *blkcg;
34315
34316 if (!parent_css) {
34317@@ -826,7 +826,7 @@ blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
34318
34319 blkcg->cfq_weight = CFQ_WEIGHT_DEFAULT;
34320 blkcg->cfq_leaf_weight = CFQ_WEIGHT_DEFAULT;
34321- blkcg->id = atomic64_inc_return(&id_seq); /* root is 0, start from 1 */
34322+ blkcg->id = atomic64_inc_return_unchecked(&id_seq); /* root is 0, start from 1 */
34323 done:
34324 spin_lock_init(&blkcg->lock);
34325 INIT_RADIX_TREE(&blkcg->blkg_tree, GFP_ATOMIC);
34326diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
34327index 4b8d9b54..a7178c0 100644
34328--- a/block/blk-iopoll.c
34329+++ b/block/blk-iopoll.c
34330@@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
34331 }
34332 EXPORT_SYMBOL(blk_iopoll_complete);
34333
34334-static void blk_iopoll_softirq(struct softirq_action *h)
34335+static __latent_entropy void blk_iopoll_softirq(void)
34336 {
34337 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
34338 int rearm = 0, budget = blk_iopoll_budget;
34339diff --git a/block/blk-map.c b/block/blk-map.c
34340index 623e1cd..ca1e109 100644
34341--- a/block/blk-map.c
34342+++ b/block/blk-map.c
34343@@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
34344 if (!len || !kbuf)
34345 return -EINVAL;
34346
34347- do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
34348+ do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
34349 if (do_copy)
34350 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
34351 else
34352diff --git a/block/blk-softirq.c b/block/blk-softirq.c
34353index ec9e606..3f38839 100644
34354--- a/block/blk-softirq.c
34355+++ b/block/blk-softirq.c
34356@@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
34357 * Softirq action handler - move entries to local list and loop over them
34358 * while passing them to the queue registered handler.
34359 */
34360-static void blk_done_softirq(struct softirq_action *h)
34361+static __latent_entropy void blk_done_softirq(void)
34362 {
34363 struct list_head *cpu_list, local_list;
34364
34365diff --git a/block/bsg.c b/block/bsg.c
34366index 420a5a9..23834aa 100644
34367--- a/block/bsg.c
34368+++ b/block/bsg.c
34369@@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
34370 struct sg_io_v4 *hdr, struct bsg_device *bd,
34371 fmode_t has_write_perm)
34372 {
34373+ unsigned char tmpcmd[sizeof(rq->__cmd)];
34374+ unsigned char *cmdptr;
34375+
34376 if (hdr->request_len > BLK_MAX_CDB) {
34377 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
34378 if (!rq->cmd)
34379 return -ENOMEM;
34380- }
34381+ cmdptr = rq->cmd;
34382+ } else
34383+ cmdptr = tmpcmd;
34384
34385- if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
34386+ if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
34387 hdr->request_len))
34388 return -EFAULT;
34389
34390+ if (cmdptr != rq->cmd)
34391+ memcpy(rq->cmd, cmdptr, hdr->request_len);
34392+
34393 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
34394 if (blk_verify_command(rq->cmd, has_write_perm))
34395 return -EPERM;
34396diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
34397index fbd5a67..5d631b5 100644
34398--- a/block/compat_ioctl.c
34399+++ b/block/compat_ioctl.c
34400@@ -341,7 +341,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
34401 err |= __get_user(f->spec1, &uf->spec1);
34402 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
34403 err |= __get_user(name, &uf->name);
34404- f->name = compat_ptr(name);
34405+ f->name = (void __force_kernel *)compat_ptr(name);
34406 if (err) {
34407 err = -EFAULT;
34408 goto out;
34409diff --git a/block/genhd.c b/block/genhd.c
34410index 791f419..89f21c4 100644
34411--- a/block/genhd.c
34412+++ b/block/genhd.c
34413@@ -467,21 +467,24 @@ static char *bdevt_str(dev_t devt, char *buf)
34414
34415 /*
34416 * Register device numbers dev..(dev+range-1)
34417- * range must be nonzero
34418+ * Noop if @range is zero.
34419 * The hash chain is sorted on range, so that subranges can override.
34420 */
34421 void blk_register_region(dev_t devt, unsigned long range, struct module *module,
34422 struct kobject *(*probe)(dev_t, int *, void *),
34423 int (*lock)(dev_t, void *), void *data)
34424 {
34425- kobj_map(bdev_map, devt, range, module, probe, lock, data);
34426+ if (range)
34427+ kobj_map(bdev_map, devt, range, module, probe, lock, data);
34428 }
34429
34430 EXPORT_SYMBOL(blk_register_region);
34431
34432+/* undo blk_register_region(), noop if @range is zero */
34433 void blk_unregister_region(dev_t devt, unsigned long range)
34434 {
34435- kobj_unmap(bdev_map, devt, range);
34436+ if (range)
34437+ kobj_unmap(bdev_map, devt, range);
34438 }
34439
34440 EXPORT_SYMBOL(blk_unregister_region);
34441diff --git a/block/partitions/efi.c b/block/partitions/efi.c
34442index a8287b4..241a48e 100644
34443--- a/block/partitions/efi.c
34444+++ b/block/partitions/efi.c
34445@@ -292,14 +292,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
34446 if (!gpt)
34447 return NULL;
34448
34449+ if (!le32_to_cpu(gpt->num_partition_entries))
34450+ return NULL;
34451+ pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
34452+ if (!pte)
34453+ return NULL;
34454+
34455 count = le32_to_cpu(gpt->num_partition_entries) *
34456 le32_to_cpu(gpt->sizeof_partition_entry);
34457- if (!count)
34458- return NULL;
34459- pte = kmalloc(count, GFP_KERNEL);
34460- if (!pte)
34461- return NULL;
34462-
34463 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
34464 (u8 *) pte, count) < count) {
34465 kfree(pte);
34466diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
34467index a5ffcc9..e057498 100644
34468--- a/block/scsi_ioctl.c
34469+++ b/block/scsi_ioctl.c
34470@@ -67,7 +67,7 @@ static int scsi_get_bus(struct request_queue *q, int __user *p)
34471 return put_user(0, p);
34472 }
34473
34474-static int sg_get_timeout(struct request_queue *q)
34475+static int __intentional_overflow(-1) sg_get_timeout(struct request_queue *q)
34476 {
34477 return jiffies_to_clock_t(q->sg_timeout);
34478 }
34479@@ -224,8 +224,20 @@ EXPORT_SYMBOL(blk_verify_command);
34480 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
34481 struct sg_io_hdr *hdr, fmode_t mode)
34482 {
34483- if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
34484+ unsigned char tmpcmd[sizeof(rq->__cmd)];
34485+ unsigned char *cmdptr;
34486+
34487+ if (rq->cmd != rq->__cmd)
34488+ cmdptr = rq->cmd;
34489+ else
34490+ cmdptr = tmpcmd;
34491+
34492+ if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
34493 return -EFAULT;
34494+
34495+ if (cmdptr != rq->cmd)
34496+ memcpy(rq->cmd, cmdptr, hdr->cmd_len);
34497+
34498 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
34499 return -EPERM;
34500
34501@@ -434,6 +446,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
34502 int err;
34503 unsigned int in_len, out_len, bytes, opcode, cmdlen;
34504 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
34505+ unsigned char tmpcmd[sizeof(rq->__cmd)];
34506+ unsigned char *cmdptr;
34507
34508 if (!sic)
34509 return -EINVAL;
34510@@ -467,9 +481,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
34511 */
34512 err = -EFAULT;
34513 rq->cmd_len = cmdlen;
34514- if (copy_from_user(rq->cmd, sic->data, cmdlen))
34515+
34516+ if (rq->cmd != rq->__cmd)
34517+ cmdptr = rq->cmd;
34518+ else
34519+ cmdptr = tmpcmd;
34520+
34521+ if (copy_from_user(cmdptr, sic->data, cmdlen))
34522 goto error;
34523
34524+ if (rq->cmd != cmdptr)
34525+ memcpy(rq->cmd, cmdptr, cmdlen);
34526+
34527 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
34528 goto error;
34529
34530diff --git a/crypto/cryptd.c b/crypto/cryptd.c
34531index 7bdd61b..afec999 100644
34532--- a/crypto/cryptd.c
34533+++ b/crypto/cryptd.c
34534@@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
34535
34536 struct cryptd_blkcipher_request_ctx {
34537 crypto_completion_t complete;
34538-};
34539+} __no_const;
34540
34541 struct cryptd_hash_ctx {
34542 struct crypto_shash *child;
34543@@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
34544
34545 struct cryptd_aead_request_ctx {
34546 crypto_completion_t complete;
34547-};
34548+} __no_const;
34549
34550 static void cryptd_queue_worker(struct work_struct *work);
34551
34552diff --git a/crypto/pcrypt.c b/crypto/pcrypt.c
34553index f8c920c..ab2cb5a 100644
34554--- a/crypto/pcrypt.c
34555+++ b/crypto/pcrypt.c
34556@@ -440,7 +440,7 @@ static int pcrypt_sysfs_add(struct padata_instance *pinst, const char *name)
34557 int ret;
34558
34559 pinst->kobj.kset = pcrypt_kset;
34560- ret = kobject_add(&pinst->kobj, NULL, name);
34561+ ret = kobject_add(&pinst->kobj, NULL, "%s", name);
34562 if (!ret)
34563 kobject_uevent(&pinst->kobj, KOBJ_ADD);
34564
34565diff --git a/drivers/acpi/apei/apei-internal.h b/drivers/acpi/apei/apei-internal.h
34566index f220d64..d359ad6 100644
34567--- a/drivers/acpi/apei/apei-internal.h
34568+++ b/drivers/acpi/apei/apei-internal.h
34569@@ -20,7 +20,7 @@ typedef int (*apei_exec_ins_func_t)(struct apei_exec_context *ctx,
34570 struct apei_exec_ins_type {
34571 u32 flags;
34572 apei_exec_ins_func_t run;
34573-};
34574+} __do_const;
34575
34576 struct apei_exec_context {
34577 u32 ip;
34578diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
34579index 33dc6a0..4b24b47 100644
34580--- a/drivers/acpi/apei/cper.c
34581+++ b/drivers/acpi/apei/cper.c
34582@@ -39,12 +39,12 @@
34583 */
34584 u64 cper_next_record_id(void)
34585 {
34586- static atomic64_t seq;
34587+ static atomic64_unchecked_t seq;
34588
34589- if (!atomic64_read(&seq))
34590- atomic64_set(&seq, ((u64)get_seconds()) << 32);
34591+ if (!atomic64_read_unchecked(&seq))
34592+ atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
34593
34594- return atomic64_inc_return(&seq);
34595+ return atomic64_inc_return_unchecked(&seq);
34596 }
34597 EXPORT_SYMBOL_GPL(cper_next_record_id);
34598
34599diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c
34600index 8ec37bb..b0716e5 100644
34601--- a/drivers/acpi/apei/ghes.c
34602+++ b/drivers/acpi/apei/ghes.c
34603@@ -498,7 +498,7 @@ static void __ghes_print_estatus(const char *pfx,
34604 const struct acpi_hest_generic *generic,
34605 const struct acpi_hest_generic_status *estatus)
34606 {
34607- static atomic_t seqno;
34608+ static atomic_unchecked_t seqno;
34609 unsigned int curr_seqno;
34610 char pfx_seq[64];
34611
34612@@ -509,7 +509,7 @@ static void __ghes_print_estatus(const char *pfx,
34613 else
34614 pfx = KERN_ERR;
34615 }
34616- curr_seqno = atomic_inc_return(&seqno);
34617+ curr_seqno = atomic_inc_return_unchecked(&seqno);
34618 snprintf(pfx_seq, sizeof(pfx_seq), "%s{%u}" HW_ERR, pfx, curr_seqno);
34619 printk("%s""Hardware error from APEI Generic Hardware Error Source: %d\n",
34620 pfx_seq, generic->header.source_id);
34621diff --git a/drivers/acpi/bgrt.c b/drivers/acpi/bgrt.c
34622index a83e3c6..c3d617f 100644
34623--- a/drivers/acpi/bgrt.c
34624+++ b/drivers/acpi/bgrt.c
34625@@ -86,8 +86,10 @@ static int __init bgrt_init(void)
34626 if (!bgrt_image)
34627 return -ENODEV;
34628
34629- bin_attr_image.private = bgrt_image;
34630- bin_attr_image.size = bgrt_image_size;
34631+ pax_open_kernel();
34632+ *(void **)&bin_attr_image.private = bgrt_image;
34633+ *(size_t *)&bin_attr_image.size = bgrt_image_size;
34634+ pax_close_kernel();
34635
34636 bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
34637 if (!bgrt_kobj)
34638diff --git a/drivers/acpi/blacklist.c b/drivers/acpi/blacklist.c
34639index 9515f18..4b149c9 100644
34640--- a/drivers/acpi/blacklist.c
34641+++ b/drivers/acpi/blacklist.c
34642@@ -52,7 +52,7 @@ struct acpi_blacklist_item {
34643 u32 is_critical_error;
34644 };
34645
34646-static struct dmi_system_id acpi_osi_dmi_table[] __initdata;
34647+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst;
34648
34649 /*
34650 * POLICY: If *anything* doesn't work, put it on the blacklist.
34651@@ -199,7 +199,7 @@ static int __init dmi_disable_osi_win8(const struct dmi_system_id *d)
34652 return 0;
34653 }
34654
34655-static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
34656+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst = {
34657 {
34658 .callback = dmi_disable_osi_vista,
34659 .ident = "Fujitsu Siemens",
34660diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
34661index f98dd00..7b69865 100644
34662--- a/drivers/acpi/processor_idle.c
34663+++ b/drivers/acpi/processor_idle.c
34664@@ -992,7 +992,7 @@ static int acpi_processor_setup_cpuidle_states(struct acpi_processor *pr)
34665 {
34666 int i, count = CPUIDLE_DRIVER_STATE_START;
34667 struct acpi_processor_cx *cx;
34668- struct cpuidle_state *state;
34669+ cpuidle_state_no_const *state;
34670 struct cpuidle_driver *drv = &acpi_idle_driver;
34671
34672 if (!pr->flags.power_setup_done)
34673diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
34674index 05306a5..733d1f0 100644
34675--- a/drivers/acpi/sysfs.c
34676+++ b/drivers/acpi/sysfs.c
34677@@ -423,11 +423,11 @@ static u32 num_counters;
34678 static struct attribute **all_attrs;
34679 static u32 acpi_gpe_count;
34680
34681-static struct attribute_group interrupt_stats_attr_group = {
34682+static attribute_group_no_const interrupt_stats_attr_group = {
34683 .name = "interrupts",
34684 };
34685
34686-static struct kobj_attribute *counter_attrs;
34687+static kobj_attribute_no_const *counter_attrs;
34688
34689 static void delete_gpe_attr_array(void)
34690 {
34691diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
34692index aaac4fb..e325c00 100644
34693--- a/drivers/ata/libahci.c
34694+++ b/drivers/ata/libahci.c
34695@@ -1239,7 +1239,7 @@ int ahci_kick_engine(struct ata_port *ap)
34696 }
34697 EXPORT_SYMBOL_GPL(ahci_kick_engine);
34698
34699-static int ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
34700+static int __intentional_overflow(-1) ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
34701 struct ata_taskfile *tf, int is_cmd, u16 flags,
34702 unsigned long timeout_msec)
34703 {
34704diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
34705index 83b1a9f..005b1ec 100644
34706--- a/drivers/ata/libata-core.c
34707+++ b/drivers/ata/libata-core.c
34708@@ -98,7 +98,7 @@ static unsigned int ata_dev_set_xfermode(struct ata_device *dev);
34709 static void ata_dev_xfermask(struct ata_device *dev);
34710 static unsigned long ata_dev_blacklisted(const struct ata_device *dev);
34711
34712-atomic_t ata_print_id = ATOMIC_INIT(0);
34713+atomic_unchecked_t ata_print_id = ATOMIC_INIT(0);
34714
34715 struct ata_force_param {
34716 const char *name;
34717@@ -4808,7 +4808,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
34718 struct ata_port *ap;
34719 unsigned int tag;
34720
34721- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
34722+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
34723 ap = qc->ap;
34724
34725 qc->flags = 0;
34726@@ -4824,7 +4824,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
34727 struct ata_port *ap;
34728 struct ata_link *link;
34729
34730- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
34731+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
34732 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
34733 ap = qc->ap;
34734 link = qc->dev->link;
34735@@ -5943,6 +5943,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
34736 return;
34737
34738 spin_lock(&lock);
34739+ pax_open_kernel();
34740
34741 for (cur = ops->inherits; cur; cur = cur->inherits) {
34742 void **inherit = (void **)cur;
34743@@ -5956,8 +5957,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
34744 if (IS_ERR(*pp))
34745 *pp = NULL;
34746
34747- ops->inherits = NULL;
34748+ *(struct ata_port_operations **)&ops->inherits = NULL;
34749
34750+ pax_close_kernel();
34751 spin_unlock(&lock);
34752 }
34753
34754@@ -6150,7 +6152,7 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht)
34755
34756 /* give ports names and add SCSI hosts */
34757 for (i = 0; i < host->n_ports; i++) {
34758- host->ports[i]->print_id = atomic_inc_return(&ata_print_id);
34759+ host->ports[i]->print_id = atomic_inc_return_unchecked(&ata_print_id);
34760 host->ports[i]->local_port_no = i + 1;
34761 }
34762
34763diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
34764index db6dfcf..770d1f0 100644
34765--- a/drivers/ata/libata-scsi.c
34766+++ b/drivers/ata/libata-scsi.c
34767@@ -4113,7 +4113,7 @@ int ata_sas_port_init(struct ata_port *ap)
34768
34769 if (rc)
34770 return rc;
34771- ap->print_id = atomic_inc_return(&ata_print_id);
34772+ ap->print_id = atomic_inc_return_unchecked(&ata_print_id);
34773 return 0;
34774 }
34775 EXPORT_SYMBOL_GPL(ata_sas_port_init);
34776diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h
34777index 45b5ab3..98446b8 100644
34778--- a/drivers/ata/libata.h
34779+++ b/drivers/ata/libata.h
34780@@ -53,7 +53,7 @@ enum {
34781 ATA_DNXFER_QUIET = (1 << 31),
34782 };
34783
34784-extern atomic_t ata_print_id;
34785+extern atomic_unchecked_t ata_print_id;
34786 extern int atapi_passthru16;
34787 extern int libata_fua;
34788 extern int libata_noacpi;
34789diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
34790index 853f610..97d24da 100644
34791--- a/drivers/ata/pata_arasan_cf.c
34792+++ b/drivers/ata/pata_arasan_cf.c
34793@@ -865,7 +865,9 @@ static int arasan_cf_probe(struct platform_device *pdev)
34794 /* Handle platform specific quirks */
34795 if (quirk) {
34796 if (quirk & CF_BROKEN_PIO) {
34797- ap->ops->set_piomode = NULL;
34798+ pax_open_kernel();
34799+ *(void **)&ap->ops->set_piomode = NULL;
34800+ pax_close_kernel();
34801 ap->pio_mask = 0;
34802 }
34803 if (quirk & CF_BROKEN_MWDMA)
34804diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
34805index f9b983a..887b9d8 100644
34806--- a/drivers/atm/adummy.c
34807+++ b/drivers/atm/adummy.c
34808@@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
34809 vcc->pop(vcc, skb);
34810 else
34811 dev_kfree_skb_any(skb);
34812- atomic_inc(&vcc->stats->tx);
34813+ atomic_inc_unchecked(&vcc->stats->tx);
34814
34815 return 0;
34816 }
34817diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
34818index 62a7607..cc4be104 100644
34819--- a/drivers/atm/ambassador.c
34820+++ b/drivers/atm/ambassador.c
34821@@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
34822 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
34823
34824 // VC layer stats
34825- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
34826+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
34827
34828 // free the descriptor
34829 kfree (tx_descr);
34830@@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
34831 dump_skb ("<<<", vc, skb);
34832
34833 // VC layer stats
34834- atomic_inc(&atm_vcc->stats->rx);
34835+ atomic_inc_unchecked(&atm_vcc->stats->rx);
34836 __net_timestamp(skb);
34837 // end of our responsibility
34838 atm_vcc->push (atm_vcc, skb);
34839@@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
34840 } else {
34841 PRINTK (KERN_INFO, "dropped over-size frame");
34842 // should we count this?
34843- atomic_inc(&atm_vcc->stats->rx_drop);
34844+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
34845 }
34846
34847 } else {
34848@@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
34849 }
34850
34851 if (check_area (skb->data, skb->len)) {
34852- atomic_inc(&atm_vcc->stats->tx_err);
34853+ atomic_inc_unchecked(&atm_vcc->stats->tx_err);
34854 return -ENOMEM; // ?
34855 }
34856
34857diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
34858index 0e3f8f9..765a7a5 100644
34859--- a/drivers/atm/atmtcp.c
34860+++ b/drivers/atm/atmtcp.c
34861@@ -206,7 +206,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
34862 if (vcc->pop) vcc->pop(vcc,skb);
34863 else dev_kfree_skb(skb);
34864 if (dev_data) return 0;
34865- atomic_inc(&vcc->stats->tx_err);
34866+ atomic_inc_unchecked(&vcc->stats->tx_err);
34867 return -ENOLINK;
34868 }
34869 size = skb->len+sizeof(struct atmtcp_hdr);
34870@@ -214,7 +214,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
34871 if (!new_skb) {
34872 if (vcc->pop) vcc->pop(vcc,skb);
34873 else dev_kfree_skb(skb);
34874- atomic_inc(&vcc->stats->tx_err);
34875+ atomic_inc_unchecked(&vcc->stats->tx_err);
34876 return -ENOBUFS;
34877 }
34878 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
34879@@ -225,8 +225,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
34880 if (vcc->pop) vcc->pop(vcc,skb);
34881 else dev_kfree_skb(skb);
34882 out_vcc->push(out_vcc,new_skb);
34883- atomic_inc(&vcc->stats->tx);
34884- atomic_inc(&out_vcc->stats->rx);
34885+ atomic_inc_unchecked(&vcc->stats->tx);
34886+ atomic_inc_unchecked(&out_vcc->stats->rx);
34887 return 0;
34888 }
34889
34890@@ -299,7 +299,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
34891 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
34892 read_unlock(&vcc_sklist_lock);
34893 if (!out_vcc) {
34894- atomic_inc(&vcc->stats->tx_err);
34895+ atomic_inc_unchecked(&vcc->stats->tx_err);
34896 goto done;
34897 }
34898 skb_pull(skb,sizeof(struct atmtcp_hdr));
34899@@ -311,8 +311,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
34900 __net_timestamp(new_skb);
34901 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
34902 out_vcc->push(out_vcc,new_skb);
34903- atomic_inc(&vcc->stats->tx);
34904- atomic_inc(&out_vcc->stats->rx);
34905+ atomic_inc_unchecked(&vcc->stats->tx);
34906+ atomic_inc_unchecked(&out_vcc->stats->rx);
34907 done:
34908 if (vcc->pop) vcc->pop(vcc,skb);
34909 else dev_kfree_skb(skb);
34910diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
34911index b1955ba..b179940 100644
34912--- a/drivers/atm/eni.c
34913+++ b/drivers/atm/eni.c
34914@@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
34915 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
34916 vcc->dev->number);
34917 length = 0;
34918- atomic_inc(&vcc->stats->rx_err);
34919+ atomic_inc_unchecked(&vcc->stats->rx_err);
34920 }
34921 else {
34922 length = ATM_CELL_SIZE-1; /* no HEC */
34923@@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
34924 size);
34925 }
34926 eff = length = 0;
34927- atomic_inc(&vcc->stats->rx_err);
34928+ atomic_inc_unchecked(&vcc->stats->rx_err);
34929 }
34930 else {
34931 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
34932@@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
34933 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
34934 vcc->dev->number,vcc->vci,length,size << 2,descr);
34935 length = eff = 0;
34936- atomic_inc(&vcc->stats->rx_err);
34937+ atomic_inc_unchecked(&vcc->stats->rx_err);
34938 }
34939 }
34940 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
34941@@ -767,7 +767,7 @@ rx_dequeued++;
34942 vcc->push(vcc,skb);
34943 pushed++;
34944 }
34945- atomic_inc(&vcc->stats->rx);
34946+ atomic_inc_unchecked(&vcc->stats->rx);
34947 }
34948 wake_up(&eni_dev->rx_wait);
34949 }
34950@@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
34951 PCI_DMA_TODEVICE);
34952 if (vcc->pop) vcc->pop(vcc,skb);
34953 else dev_kfree_skb_irq(skb);
34954- atomic_inc(&vcc->stats->tx);
34955+ atomic_inc_unchecked(&vcc->stats->tx);
34956 wake_up(&eni_dev->tx_wait);
34957 dma_complete++;
34958 }
34959diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
34960index b41c948..a002b17 100644
34961--- a/drivers/atm/firestream.c
34962+++ b/drivers/atm/firestream.c
34963@@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
34964 }
34965 }
34966
34967- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
34968+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
34969
34970 fs_dprintk (FS_DEBUG_TXMEM, "i");
34971 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
34972@@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
34973 #endif
34974 skb_put (skb, qe->p1 & 0xffff);
34975 ATM_SKB(skb)->vcc = atm_vcc;
34976- atomic_inc(&atm_vcc->stats->rx);
34977+ atomic_inc_unchecked(&atm_vcc->stats->rx);
34978 __net_timestamp(skb);
34979 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
34980 atm_vcc->push (atm_vcc, skb);
34981@@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
34982 kfree (pe);
34983 }
34984 if (atm_vcc)
34985- atomic_inc(&atm_vcc->stats->rx_drop);
34986+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
34987 break;
34988 case 0x1f: /* Reassembly abort: no buffers. */
34989 /* Silently increment error counter. */
34990 if (atm_vcc)
34991- atomic_inc(&atm_vcc->stats->rx_drop);
34992+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
34993 break;
34994 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
34995 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
34996diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
34997index 204814e..cede831 100644
34998--- a/drivers/atm/fore200e.c
34999+++ b/drivers/atm/fore200e.c
35000@@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
35001 #endif
35002 /* check error condition */
35003 if (*entry->status & STATUS_ERROR)
35004- atomic_inc(&vcc->stats->tx_err);
35005+ atomic_inc_unchecked(&vcc->stats->tx_err);
35006 else
35007- atomic_inc(&vcc->stats->tx);
35008+ atomic_inc_unchecked(&vcc->stats->tx);
35009 }
35010 }
35011
35012@@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
35013 if (skb == NULL) {
35014 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
35015
35016- atomic_inc(&vcc->stats->rx_drop);
35017+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35018 return -ENOMEM;
35019 }
35020
35021@@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
35022
35023 dev_kfree_skb_any(skb);
35024
35025- atomic_inc(&vcc->stats->rx_drop);
35026+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35027 return -ENOMEM;
35028 }
35029
35030 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
35031
35032 vcc->push(vcc, skb);
35033- atomic_inc(&vcc->stats->rx);
35034+ atomic_inc_unchecked(&vcc->stats->rx);
35035
35036 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
35037
35038@@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
35039 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
35040 fore200e->atm_dev->number,
35041 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
35042- atomic_inc(&vcc->stats->rx_err);
35043+ atomic_inc_unchecked(&vcc->stats->rx_err);
35044 }
35045 }
35046
35047@@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
35048 goto retry_here;
35049 }
35050
35051- atomic_inc(&vcc->stats->tx_err);
35052+ atomic_inc_unchecked(&vcc->stats->tx_err);
35053
35054 fore200e->tx_sat++;
35055 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
35056diff --git a/drivers/atm/he.c b/drivers/atm/he.c
35057index 8557adc..3fb5d55 100644
35058--- a/drivers/atm/he.c
35059+++ b/drivers/atm/he.c
35060@@ -1691,7 +1691,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
35061
35062 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
35063 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
35064- atomic_inc(&vcc->stats->rx_drop);
35065+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35066 goto return_host_buffers;
35067 }
35068
35069@@ -1718,7 +1718,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
35070 RBRQ_LEN_ERR(he_dev->rbrq_head)
35071 ? "LEN_ERR" : "",
35072 vcc->vpi, vcc->vci);
35073- atomic_inc(&vcc->stats->rx_err);
35074+ atomic_inc_unchecked(&vcc->stats->rx_err);
35075 goto return_host_buffers;
35076 }
35077
35078@@ -1770,7 +1770,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
35079 vcc->push(vcc, skb);
35080 spin_lock(&he_dev->global_lock);
35081
35082- atomic_inc(&vcc->stats->rx);
35083+ atomic_inc_unchecked(&vcc->stats->rx);
35084
35085 return_host_buffers:
35086 ++pdus_assembled;
35087@@ -2096,7 +2096,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
35088 tpd->vcc->pop(tpd->vcc, tpd->skb);
35089 else
35090 dev_kfree_skb_any(tpd->skb);
35091- atomic_inc(&tpd->vcc->stats->tx_err);
35092+ atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
35093 }
35094 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
35095 return;
35096@@ -2508,7 +2508,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35097 vcc->pop(vcc, skb);
35098 else
35099 dev_kfree_skb_any(skb);
35100- atomic_inc(&vcc->stats->tx_err);
35101+ atomic_inc_unchecked(&vcc->stats->tx_err);
35102 return -EINVAL;
35103 }
35104
35105@@ -2519,7 +2519,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35106 vcc->pop(vcc, skb);
35107 else
35108 dev_kfree_skb_any(skb);
35109- atomic_inc(&vcc->stats->tx_err);
35110+ atomic_inc_unchecked(&vcc->stats->tx_err);
35111 return -EINVAL;
35112 }
35113 #endif
35114@@ -2531,7 +2531,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35115 vcc->pop(vcc, skb);
35116 else
35117 dev_kfree_skb_any(skb);
35118- atomic_inc(&vcc->stats->tx_err);
35119+ atomic_inc_unchecked(&vcc->stats->tx_err);
35120 spin_unlock_irqrestore(&he_dev->global_lock, flags);
35121 return -ENOMEM;
35122 }
35123@@ -2573,7 +2573,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35124 vcc->pop(vcc, skb);
35125 else
35126 dev_kfree_skb_any(skb);
35127- atomic_inc(&vcc->stats->tx_err);
35128+ atomic_inc_unchecked(&vcc->stats->tx_err);
35129 spin_unlock_irqrestore(&he_dev->global_lock, flags);
35130 return -ENOMEM;
35131 }
35132@@ -2604,7 +2604,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35133 __enqueue_tpd(he_dev, tpd, cid);
35134 spin_unlock_irqrestore(&he_dev->global_lock, flags);
35135
35136- atomic_inc(&vcc->stats->tx);
35137+ atomic_inc_unchecked(&vcc->stats->tx);
35138
35139 return 0;
35140 }
35141diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
35142index 1dc0519..1aadaf7 100644
35143--- a/drivers/atm/horizon.c
35144+++ b/drivers/atm/horizon.c
35145@@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
35146 {
35147 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
35148 // VC layer stats
35149- atomic_inc(&vcc->stats->rx);
35150+ atomic_inc_unchecked(&vcc->stats->rx);
35151 __net_timestamp(skb);
35152 // end of our responsibility
35153 vcc->push (vcc, skb);
35154@@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
35155 dev->tx_iovec = NULL;
35156
35157 // VC layer stats
35158- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
35159+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
35160
35161 // free the skb
35162 hrz_kfree_skb (skb);
35163diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
35164index 272f009..a18ba55 100644
35165--- a/drivers/atm/idt77252.c
35166+++ b/drivers/atm/idt77252.c
35167@@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
35168 else
35169 dev_kfree_skb(skb);
35170
35171- atomic_inc(&vcc->stats->tx);
35172+ atomic_inc_unchecked(&vcc->stats->tx);
35173 }
35174
35175 atomic_dec(&scq->used);
35176@@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
35177 if ((sb = dev_alloc_skb(64)) == NULL) {
35178 printk("%s: Can't allocate buffers for aal0.\n",
35179 card->name);
35180- atomic_add(i, &vcc->stats->rx_drop);
35181+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
35182 break;
35183 }
35184 if (!atm_charge(vcc, sb->truesize)) {
35185 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
35186 card->name);
35187- atomic_add(i - 1, &vcc->stats->rx_drop);
35188+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
35189 dev_kfree_skb(sb);
35190 break;
35191 }
35192@@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
35193 ATM_SKB(sb)->vcc = vcc;
35194 __net_timestamp(sb);
35195 vcc->push(vcc, sb);
35196- atomic_inc(&vcc->stats->rx);
35197+ atomic_inc_unchecked(&vcc->stats->rx);
35198
35199 cell += ATM_CELL_PAYLOAD;
35200 }
35201@@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
35202 "(CDC: %08x)\n",
35203 card->name, len, rpp->len, readl(SAR_REG_CDC));
35204 recycle_rx_pool_skb(card, rpp);
35205- atomic_inc(&vcc->stats->rx_err);
35206+ atomic_inc_unchecked(&vcc->stats->rx_err);
35207 return;
35208 }
35209 if (stat & SAR_RSQE_CRC) {
35210 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
35211 recycle_rx_pool_skb(card, rpp);
35212- atomic_inc(&vcc->stats->rx_err);
35213+ atomic_inc_unchecked(&vcc->stats->rx_err);
35214 return;
35215 }
35216 if (skb_queue_len(&rpp->queue) > 1) {
35217@@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
35218 RXPRINTK("%s: Can't alloc RX skb.\n",
35219 card->name);
35220 recycle_rx_pool_skb(card, rpp);
35221- atomic_inc(&vcc->stats->rx_err);
35222+ atomic_inc_unchecked(&vcc->stats->rx_err);
35223 return;
35224 }
35225 if (!atm_charge(vcc, skb->truesize)) {
35226@@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
35227 __net_timestamp(skb);
35228
35229 vcc->push(vcc, skb);
35230- atomic_inc(&vcc->stats->rx);
35231+ atomic_inc_unchecked(&vcc->stats->rx);
35232
35233 return;
35234 }
35235@@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
35236 __net_timestamp(skb);
35237
35238 vcc->push(vcc, skb);
35239- atomic_inc(&vcc->stats->rx);
35240+ atomic_inc_unchecked(&vcc->stats->rx);
35241
35242 if (skb->truesize > SAR_FB_SIZE_3)
35243 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
35244@@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
35245 if (vcc->qos.aal != ATM_AAL0) {
35246 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
35247 card->name, vpi, vci);
35248- atomic_inc(&vcc->stats->rx_drop);
35249+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35250 goto drop;
35251 }
35252
35253 if ((sb = dev_alloc_skb(64)) == NULL) {
35254 printk("%s: Can't allocate buffers for AAL0.\n",
35255 card->name);
35256- atomic_inc(&vcc->stats->rx_err);
35257+ atomic_inc_unchecked(&vcc->stats->rx_err);
35258 goto drop;
35259 }
35260
35261@@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
35262 ATM_SKB(sb)->vcc = vcc;
35263 __net_timestamp(sb);
35264 vcc->push(vcc, sb);
35265- atomic_inc(&vcc->stats->rx);
35266+ atomic_inc_unchecked(&vcc->stats->rx);
35267
35268 drop:
35269 skb_pull(queue, 64);
35270@@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
35271
35272 if (vc == NULL) {
35273 printk("%s: NULL connection in send().\n", card->name);
35274- atomic_inc(&vcc->stats->tx_err);
35275+ atomic_inc_unchecked(&vcc->stats->tx_err);
35276 dev_kfree_skb(skb);
35277 return -EINVAL;
35278 }
35279 if (!test_bit(VCF_TX, &vc->flags)) {
35280 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
35281- atomic_inc(&vcc->stats->tx_err);
35282+ atomic_inc_unchecked(&vcc->stats->tx_err);
35283 dev_kfree_skb(skb);
35284 return -EINVAL;
35285 }
35286@@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
35287 break;
35288 default:
35289 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
35290- atomic_inc(&vcc->stats->tx_err);
35291+ atomic_inc_unchecked(&vcc->stats->tx_err);
35292 dev_kfree_skb(skb);
35293 return -EINVAL;
35294 }
35295
35296 if (skb_shinfo(skb)->nr_frags != 0) {
35297 printk("%s: No scatter-gather yet.\n", card->name);
35298- atomic_inc(&vcc->stats->tx_err);
35299+ atomic_inc_unchecked(&vcc->stats->tx_err);
35300 dev_kfree_skb(skb);
35301 return -EINVAL;
35302 }
35303@@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
35304
35305 err = queue_skb(card, vc, skb, oam);
35306 if (err) {
35307- atomic_inc(&vcc->stats->tx_err);
35308+ atomic_inc_unchecked(&vcc->stats->tx_err);
35309 dev_kfree_skb(skb);
35310 return err;
35311 }
35312@@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
35313 skb = dev_alloc_skb(64);
35314 if (!skb) {
35315 printk("%s: Out of memory in send_oam().\n", card->name);
35316- atomic_inc(&vcc->stats->tx_err);
35317+ atomic_inc_unchecked(&vcc->stats->tx_err);
35318 return -ENOMEM;
35319 }
35320 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
35321diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
35322index 4217f29..88f547a 100644
35323--- a/drivers/atm/iphase.c
35324+++ b/drivers/atm/iphase.c
35325@@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
35326 status = (u_short) (buf_desc_ptr->desc_mode);
35327 if (status & (RX_CER | RX_PTE | RX_OFL))
35328 {
35329- atomic_inc(&vcc->stats->rx_err);
35330+ atomic_inc_unchecked(&vcc->stats->rx_err);
35331 IF_ERR(printk("IA: bad packet, dropping it");)
35332 if (status & RX_CER) {
35333 IF_ERR(printk(" cause: packet CRC error\n");)
35334@@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
35335 len = dma_addr - buf_addr;
35336 if (len > iadev->rx_buf_sz) {
35337 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
35338- atomic_inc(&vcc->stats->rx_err);
35339+ atomic_inc_unchecked(&vcc->stats->rx_err);
35340 goto out_free_desc;
35341 }
35342
35343@@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
35344 ia_vcc = INPH_IA_VCC(vcc);
35345 if (ia_vcc == NULL)
35346 {
35347- atomic_inc(&vcc->stats->rx_err);
35348+ atomic_inc_unchecked(&vcc->stats->rx_err);
35349 atm_return(vcc, skb->truesize);
35350 dev_kfree_skb_any(skb);
35351 goto INCR_DLE;
35352@@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
35353 if ((length > iadev->rx_buf_sz) || (length >
35354 (skb->len - sizeof(struct cpcs_trailer))))
35355 {
35356- atomic_inc(&vcc->stats->rx_err);
35357+ atomic_inc_unchecked(&vcc->stats->rx_err);
35358 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
35359 length, skb->len);)
35360 atm_return(vcc, skb->truesize);
35361@@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
35362
35363 IF_RX(printk("rx_dle_intr: skb push");)
35364 vcc->push(vcc,skb);
35365- atomic_inc(&vcc->stats->rx);
35366+ atomic_inc_unchecked(&vcc->stats->rx);
35367 iadev->rx_pkt_cnt++;
35368 }
35369 INCR_DLE:
35370@@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
35371 {
35372 struct k_sonet_stats *stats;
35373 stats = &PRIV(_ia_dev[board])->sonet_stats;
35374- printk("section_bip: %d\n", atomic_read(&stats->section_bip));
35375- printk("line_bip : %d\n", atomic_read(&stats->line_bip));
35376- printk("path_bip : %d\n", atomic_read(&stats->path_bip));
35377- printk("line_febe : %d\n", atomic_read(&stats->line_febe));
35378- printk("path_febe : %d\n", atomic_read(&stats->path_febe));
35379- printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
35380- printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
35381- printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
35382- printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
35383+ printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
35384+ printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
35385+ printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
35386+ printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
35387+ printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
35388+ printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
35389+ printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
35390+ printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
35391+ printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
35392 }
35393 ia_cmds.status = 0;
35394 break;
35395@@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
35396 if ((desc == 0) || (desc > iadev->num_tx_desc))
35397 {
35398 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
35399- atomic_inc(&vcc->stats->tx);
35400+ atomic_inc_unchecked(&vcc->stats->tx);
35401 if (vcc->pop)
35402 vcc->pop(vcc, skb);
35403 else
35404@@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
35405 ATM_DESC(skb) = vcc->vci;
35406 skb_queue_tail(&iadev->tx_dma_q, skb);
35407
35408- atomic_inc(&vcc->stats->tx);
35409+ atomic_inc_unchecked(&vcc->stats->tx);
35410 iadev->tx_pkt_cnt++;
35411 /* Increment transaction counter */
35412 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
35413
35414 #if 0
35415 /* add flow control logic */
35416- if (atomic_read(&vcc->stats->tx) % 20 == 0) {
35417+ if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
35418 if (iavcc->vc_desc_cnt > 10) {
35419 vcc->tx_quota = vcc->tx_quota * 3 / 4;
35420 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
35421diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
35422index fa7d701..1e404c7 100644
35423--- a/drivers/atm/lanai.c
35424+++ b/drivers/atm/lanai.c
35425@@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
35426 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
35427 lanai_endtx(lanai, lvcc);
35428 lanai_free_skb(lvcc->tx.atmvcc, skb);
35429- atomic_inc(&lvcc->tx.atmvcc->stats->tx);
35430+ atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
35431 }
35432
35433 /* Try to fill the buffer - don't call unless there is backlog */
35434@@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
35435 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
35436 __net_timestamp(skb);
35437 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
35438- atomic_inc(&lvcc->rx.atmvcc->stats->rx);
35439+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
35440 out:
35441 lvcc->rx.buf.ptr = end;
35442 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
35443@@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
35444 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
35445 "vcc %d\n", lanai->number, (unsigned int) s, vci);
35446 lanai->stats.service_rxnotaal5++;
35447- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
35448+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
35449 return 0;
35450 }
35451 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
35452@@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
35453 int bytes;
35454 read_unlock(&vcc_sklist_lock);
35455 DPRINTK("got trashed rx pdu on vci %d\n", vci);
35456- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
35457+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
35458 lvcc->stats.x.aal5.service_trash++;
35459 bytes = (SERVICE_GET_END(s) * 16) -
35460 (((unsigned long) lvcc->rx.buf.ptr) -
35461@@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
35462 }
35463 if (s & SERVICE_STREAM) {
35464 read_unlock(&vcc_sklist_lock);
35465- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
35466+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
35467 lvcc->stats.x.aal5.service_stream++;
35468 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
35469 "PDU on VCI %d!\n", lanai->number, vci);
35470@@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
35471 return 0;
35472 }
35473 DPRINTK("got rx crc error on vci %d\n", vci);
35474- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
35475+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
35476 lvcc->stats.x.aal5.service_rxcrc++;
35477 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
35478 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
35479diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
35480index 5aca5f4..ce3a6b0 100644
35481--- a/drivers/atm/nicstar.c
35482+++ b/drivers/atm/nicstar.c
35483@@ -1640,7 +1640,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
35484 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
35485 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
35486 card->index);
35487- atomic_inc(&vcc->stats->tx_err);
35488+ atomic_inc_unchecked(&vcc->stats->tx_err);
35489 dev_kfree_skb_any(skb);
35490 return -EINVAL;
35491 }
35492@@ -1648,7 +1648,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
35493 if (!vc->tx) {
35494 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
35495 card->index);
35496- atomic_inc(&vcc->stats->tx_err);
35497+ atomic_inc_unchecked(&vcc->stats->tx_err);
35498 dev_kfree_skb_any(skb);
35499 return -EINVAL;
35500 }
35501@@ -1656,14 +1656,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
35502 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
35503 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
35504 card->index);
35505- atomic_inc(&vcc->stats->tx_err);
35506+ atomic_inc_unchecked(&vcc->stats->tx_err);
35507 dev_kfree_skb_any(skb);
35508 return -EINVAL;
35509 }
35510
35511 if (skb_shinfo(skb)->nr_frags != 0) {
35512 printk("nicstar%d: No scatter-gather yet.\n", card->index);
35513- atomic_inc(&vcc->stats->tx_err);
35514+ atomic_inc_unchecked(&vcc->stats->tx_err);
35515 dev_kfree_skb_any(skb);
35516 return -EINVAL;
35517 }
35518@@ -1711,11 +1711,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
35519 }
35520
35521 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
35522- atomic_inc(&vcc->stats->tx_err);
35523+ atomic_inc_unchecked(&vcc->stats->tx_err);
35524 dev_kfree_skb_any(skb);
35525 return -EIO;
35526 }
35527- atomic_inc(&vcc->stats->tx);
35528+ atomic_inc_unchecked(&vcc->stats->tx);
35529
35530 return 0;
35531 }
35532@@ -2032,14 +2032,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35533 printk
35534 ("nicstar%d: Can't allocate buffers for aal0.\n",
35535 card->index);
35536- atomic_add(i, &vcc->stats->rx_drop);
35537+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
35538 break;
35539 }
35540 if (!atm_charge(vcc, sb->truesize)) {
35541 RXPRINTK
35542 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
35543 card->index);
35544- atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
35545+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
35546 dev_kfree_skb_any(sb);
35547 break;
35548 }
35549@@ -2054,7 +2054,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35550 ATM_SKB(sb)->vcc = vcc;
35551 __net_timestamp(sb);
35552 vcc->push(vcc, sb);
35553- atomic_inc(&vcc->stats->rx);
35554+ atomic_inc_unchecked(&vcc->stats->rx);
35555 cell += ATM_CELL_PAYLOAD;
35556 }
35557
35558@@ -2071,7 +2071,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35559 if (iovb == NULL) {
35560 printk("nicstar%d: Out of iovec buffers.\n",
35561 card->index);
35562- atomic_inc(&vcc->stats->rx_drop);
35563+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35564 recycle_rx_buf(card, skb);
35565 return;
35566 }
35567@@ -2095,7 +2095,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35568 small or large buffer itself. */
35569 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
35570 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
35571- atomic_inc(&vcc->stats->rx_err);
35572+ atomic_inc_unchecked(&vcc->stats->rx_err);
35573 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
35574 NS_MAX_IOVECS);
35575 NS_PRV_IOVCNT(iovb) = 0;
35576@@ -2115,7 +2115,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35577 ("nicstar%d: Expected a small buffer, and this is not one.\n",
35578 card->index);
35579 which_list(card, skb);
35580- atomic_inc(&vcc->stats->rx_err);
35581+ atomic_inc_unchecked(&vcc->stats->rx_err);
35582 recycle_rx_buf(card, skb);
35583 vc->rx_iov = NULL;
35584 recycle_iov_buf(card, iovb);
35585@@ -2128,7 +2128,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35586 ("nicstar%d: Expected a large buffer, and this is not one.\n",
35587 card->index);
35588 which_list(card, skb);
35589- atomic_inc(&vcc->stats->rx_err);
35590+ atomic_inc_unchecked(&vcc->stats->rx_err);
35591 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
35592 NS_PRV_IOVCNT(iovb));
35593 vc->rx_iov = NULL;
35594@@ -2151,7 +2151,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35595 printk(" - PDU size mismatch.\n");
35596 else
35597 printk(".\n");
35598- atomic_inc(&vcc->stats->rx_err);
35599+ atomic_inc_unchecked(&vcc->stats->rx_err);
35600 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
35601 NS_PRV_IOVCNT(iovb));
35602 vc->rx_iov = NULL;
35603@@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35604 /* skb points to a small buffer */
35605 if (!atm_charge(vcc, skb->truesize)) {
35606 push_rxbufs(card, skb);
35607- atomic_inc(&vcc->stats->rx_drop);
35608+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35609 } else {
35610 skb_put(skb, len);
35611 dequeue_sm_buf(card, skb);
35612@@ -2175,7 +2175,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35613 ATM_SKB(skb)->vcc = vcc;
35614 __net_timestamp(skb);
35615 vcc->push(vcc, skb);
35616- atomic_inc(&vcc->stats->rx);
35617+ atomic_inc_unchecked(&vcc->stats->rx);
35618 }
35619 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
35620 struct sk_buff *sb;
35621@@ -2186,7 +2186,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35622 if (len <= NS_SMBUFSIZE) {
35623 if (!atm_charge(vcc, sb->truesize)) {
35624 push_rxbufs(card, sb);
35625- atomic_inc(&vcc->stats->rx_drop);
35626+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35627 } else {
35628 skb_put(sb, len);
35629 dequeue_sm_buf(card, sb);
35630@@ -2196,7 +2196,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35631 ATM_SKB(sb)->vcc = vcc;
35632 __net_timestamp(sb);
35633 vcc->push(vcc, sb);
35634- atomic_inc(&vcc->stats->rx);
35635+ atomic_inc_unchecked(&vcc->stats->rx);
35636 }
35637
35638 push_rxbufs(card, skb);
35639@@ -2205,7 +2205,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35640
35641 if (!atm_charge(vcc, skb->truesize)) {
35642 push_rxbufs(card, skb);
35643- atomic_inc(&vcc->stats->rx_drop);
35644+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35645 } else {
35646 dequeue_lg_buf(card, skb);
35647 #ifdef NS_USE_DESTRUCTORS
35648@@ -2218,7 +2218,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35649 ATM_SKB(skb)->vcc = vcc;
35650 __net_timestamp(skb);
35651 vcc->push(vcc, skb);
35652- atomic_inc(&vcc->stats->rx);
35653+ atomic_inc_unchecked(&vcc->stats->rx);
35654 }
35655
35656 push_rxbufs(card, sb);
35657@@ -2239,7 +2239,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35658 printk
35659 ("nicstar%d: Out of huge buffers.\n",
35660 card->index);
35661- atomic_inc(&vcc->stats->rx_drop);
35662+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35663 recycle_iovec_rx_bufs(card,
35664 (struct iovec *)
35665 iovb->data,
35666@@ -2290,7 +2290,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35667 card->hbpool.count++;
35668 } else
35669 dev_kfree_skb_any(hb);
35670- atomic_inc(&vcc->stats->rx_drop);
35671+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35672 } else {
35673 /* Copy the small buffer to the huge buffer */
35674 sb = (struct sk_buff *)iov->iov_base;
35675@@ -2327,7 +2327,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35676 #endif /* NS_USE_DESTRUCTORS */
35677 __net_timestamp(hb);
35678 vcc->push(vcc, hb);
35679- atomic_inc(&vcc->stats->rx);
35680+ atomic_inc_unchecked(&vcc->stats->rx);
35681 }
35682 }
35683
35684diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
35685index 32784d1..4a8434a 100644
35686--- a/drivers/atm/solos-pci.c
35687+++ b/drivers/atm/solos-pci.c
35688@@ -838,7 +838,7 @@ void solos_bh(unsigned long card_arg)
35689 }
35690 atm_charge(vcc, skb->truesize);
35691 vcc->push(vcc, skb);
35692- atomic_inc(&vcc->stats->rx);
35693+ atomic_inc_unchecked(&vcc->stats->rx);
35694 break;
35695
35696 case PKT_STATUS:
35697@@ -1116,7 +1116,7 @@ static uint32_t fpga_tx(struct solos_card *card)
35698 vcc = SKB_CB(oldskb)->vcc;
35699
35700 if (vcc) {
35701- atomic_inc(&vcc->stats->tx);
35702+ atomic_inc_unchecked(&vcc->stats->tx);
35703 solos_pop(vcc, oldskb);
35704 } else {
35705 dev_kfree_skb_irq(oldskb);
35706diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
35707index 0215934..ce9f5b1 100644
35708--- a/drivers/atm/suni.c
35709+++ b/drivers/atm/suni.c
35710@@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
35711
35712
35713 #define ADD_LIMITED(s,v) \
35714- atomic_add((v),&stats->s); \
35715- if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
35716+ atomic_add_unchecked((v),&stats->s); \
35717+ if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
35718
35719
35720 static void suni_hz(unsigned long from_timer)
35721diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
35722index 5120a96..e2572bd 100644
35723--- a/drivers/atm/uPD98402.c
35724+++ b/drivers/atm/uPD98402.c
35725@@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
35726 struct sonet_stats tmp;
35727 int error = 0;
35728
35729- atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
35730+ atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
35731 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
35732 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
35733 if (zero && !error) {
35734@@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
35735
35736
35737 #define ADD_LIMITED(s,v) \
35738- { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
35739- if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
35740- atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
35741+ { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
35742+ if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
35743+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
35744
35745
35746 static void stat_event(struct atm_dev *dev)
35747@@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
35748 if (reason & uPD98402_INT_PFM) stat_event(dev);
35749 if (reason & uPD98402_INT_PCO) {
35750 (void) GET(PCOCR); /* clear interrupt cause */
35751- atomic_add(GET(HECCT),
35752+ atomic_add_unchecked(GET(HECCT),
35753 &PRIV(dev)->sonet_stats.uncorr_hcs);
35754 }
35755 if ((reason & uPD98402_INT_RFO) &&
35756@@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
35757 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
35758 uPD98402_INT_LOS),PIMR); /* enable them */
35759 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
35760- atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
35761- atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
35762- atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
35763+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
35764+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
35765+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
35766 return 0;
35767 }
35768
35769diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
35770index 969c3c2..9b72956 100644
35771--- a/drivers/atm/zatm.c
35772+++ b/drivers/atm/zatm.c
35773@@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
35774 }
35775 if (!size) {
35776 dev_kfree_skb_irq(skb);
35777- if (vcc) atomic_inc(&vcc->stats->rx_err);
35778+ if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
35779 continue;
35780 }
35781 if (!atm_charge(vcc,skb->truesize)) {
35782@@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
35783 skb->len = size;
35784 ATM_SKB(skb)->vcc = vcc;
35785 vcc->push(vcc,skb);
35786- atomic_inc(&vcc->stats->rx);
35787+ atomic_inc_unchecked(&vcc->stats->rx);
35788 }
35789 zout(pos & 0xffff,MTA(mbx));
35790 #if 0 /* probably a stupid idea */
35791@@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
35792 skb_queue_head(&zatm_vcc->backlog,skb);
35793 break;
35794 }
35795- atomic_inc(&vcc->stats->tx);
35796+ atomic_inc_unchecked(&vcc->stats->tx);
35797 wake_up(&zatm_vcc->tx_wait);
35798 }
35799
35800diff --git a/drivers/base/bus.c b/drivers/base/bus.c
35801index 4c289ab..de1c333 100644
35802--- a/drivers/base/bus.c
35803+++ b/drivers/base/bus.c
35804@@ -1193,7 +1193,7 @@ int subsys_interface_register(struct subsys_interface *sif)
35805 return -EINVAL;
35806
35807 mutex_lock(&subsys->p->mutex);
35808- list_add_tail(&sif->node, &subsys->p->interfaces);
35809+ pax_list_add_tail((struct list_head *)&sif->node, &subsys->p->interfaces);
35810 if (sif->add_dev) {
35811 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
35812 while ((dev = subsys_dev_iter_next(&iter)))
35813@@ -1218,7 +1218,7 @@ void subsys_interface_unregister(struct subsys_interface *sif)
35814 subsys = sif->subsys;
35815
35816 mutex_lock(&subsys->p->mutex);
35817- list_del_init(&sif->node);
35818+ pax_list_del_init((struct list_head *)&sif->node);
35819 if (sif->remove_dev) {
35820 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
35821 while ((dev = subsys_dev_iter_next(&iter)))
35822diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
35823index 7413d06..79155fa 100644
35824--- a/drivers/base/devtmpfs.c
35825+++ b/drivers/base/devtmpfs.c
35826@@ -354,7 +354,7 @@ int devtmpfs_mount(const char *mntdir)
35827 if (!thread)
35828 return 0;
35829
35830- err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
35831+ err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
35832 if (err)
35833 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
35834 else
35835@@ -380,11 +380,11 @@ static int devtmpfsd(void *p)
35836 *err = sys_unshare(CLONE_NEWNS);
35837 if (*err)
35838 goto out;
35839- *err = sys_mount("devtmpfs", "/", "devtmpfs", MS_SILENT, options);
35840+ *err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)"/", (char __force_user *)"devtmpfs", MS_SILENT, (char __force_user *)options);
35841 if (*err)
35842 goto out;
35843- sys_chdir("/.."); /* will traverse into overmounted root */
35844- sys_chroot(".");
35845+ sys_chdir((char __force_user *)"/.."); /* will traverse into overmounted root */
35846+ sys_chroot((char __force_user *)".");
35847 complete(&setup_done);
35848 while (1) {
35849 spin_lock(&req_lock);
35850diff --git a/drivers/base/node.c b/drivers/base/node.c
35851index bc9f43b..29703b8 100644
35852--- a/drivers/base/node.c
35853+++ b/drivers/base/node.c
35854@@ -620,7 +620,7 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
35855 struct node_attr {
35856 struct device_attribute attr;
35857 enum node_states state;
35858-};
35859+} __do_const;
35860
35861 static ssize_t show_node_state(struct device *dev,
35862 struct device_attribute *attr, char *buf)
35863diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
35864index bfb8955..42c9b9a 100644
35865--- a/drivers/base/power/domain.c
35866+++ b/drivers/base/power/domain.c
35867@@ -1850,7 +1850,7 @@ int pm_genpd_attach_cpuidle(struct generic_pm_domain *genpd, int state)
35868 {
35869 struct cpuidle_driver *cpuidle_drv;
35870 struct gpd_cpu_data *cpu_data;
35871- struct cpuidle_state *idle_state;
35872+ cpuidle_state_no_const *idle_state;
35873 int ret = 0;
35874
35875 if (IS_ERR_OR_NULL(genpd) || state < 0)
35876@@ -1918,7 +1918,7 @@ int pm_genpd_name_attach_cpuidle(const char *name, int state)
35877 int pm_genpd_detach_cpuidle(struct generic_pm_domain *genpd)
35878 {
35879 struct gpd_cpu_data *cpu_data;
35880- struct cpuidle_state *idle_state;
35881+ cpuidle_state_no_const *idle_state;
35882 int ret = 0;
35883
35884 if (IS_ERR_OR_NULL(genpd))
35885diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
35886index 03e089a..0e9560c 100644
35887--- a/drivers/base/power/sysfs.c
35888+++ b/drivers/base/power/sysfs.c
35889@@ -185,7 +185,7 @@ static ssize_t rtpm_status_show(struct device *dev,
35890 return -EIO;
35891 }
35892 }
35893- return sprintf(buf, p);
35894+ return sprintf(buf, "%s", p);
35895 }
35896
35897 static DEVICE_ATTR(runtime_status, 0444, rtpm_status_show, NULL);
35898diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
35899index 2d56f41..8830f19 100644
35900--- a/drivers/base/power/wakeup.c
35901+++ b/drivers/base/power/wakeup.c
35902@@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
35903 * They need to be modified together atomically, so it's better to use one
35904 * atomic variable to hold them both.
35905 */
35906-static atomic_t combined_event_count = ATOMIC_INIT(0);
35907+static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
35908
35909 #define IN_PROGRESS_BITS (sizeof(int) * 4)
35910 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
35911
35912 static void split_counters(unsigned int *cnt, unsigned int *inpr)
35913 {
35914- unsigned int comb = atomic_read(&combined_event_count);
35915+ unsigned int comb = atomic_read_unchecked(&combined_event_count);
35916
35917 *cnt = (comb >> IN_PROGRESS_BITS);
35918 *inpr = comb & MAX_IN_PROGRESS;
35919@@ -395,7 +395,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
35920 ws->start_prevent_time = ws->last_time;
35921
35922 /* Increment the counter of events in progress. */
35923- cec = atomic_inc_return(&combined_event_count);
35924+ cec = atomic_inc_return_unchecked(&combined_event_count);
35925
35926 trace_wakeup_source_activate(ws->name, cec);
35927 }
35928@@ -521,7 +521,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
35929 * Increment the counter of registered wakeup events and decrement the
35930 * couter of wakeup events in progress simultaneously.
35931 */
35932- cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
35933+ cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
35934 trace_wakeup_source_deactivate(ws->name, cec);
35935
35936 split_counters(&cnt, &inpr);
35937diff --git a/drivers/base/syscore.c b/drivers/base/syscore.c
35938index e8d11b6..7b1b36f 100644
35939--- a/drivers/base/syscore.c
35940+++ b/drivers/base/syscore.c
35941@@ -21,7 +21,7 @@ static DEFINE_MUTEX(syscore_ops_lock);
35942 void register_syscore_ops(struct syscore_ops *ops)
35943 {
35944 mutex_lock(&syscore_ops_lock);
35945- list_add_tail(&ops->node, &syscore_ops_list);
35946+ pax_list_add_tail((struct list_head *)&ops->node, &syscore_ops_list);
35947 mutex_unlock(&syscore_ops_lock);
35948 }
35949 EXPORT_SYMBOL_GPL(register_syscore_ops);
35950@@ -33,7 +33,7 @@ EXPORT_SYMBOL_GPL(register_syscore_ops);
35951 void unregister_syscore_ops(struct syscore_ops *ops)
35952 {
35953 mutex_lock(&syscore_ops_lock);
35954- list_del(&ops->node);
35955+ pax_list_del((struct list_head *)&ops->node);
35956 mutex_unlock(&syscore_ops_lock);
35957 }
35958 EXPORT_SYMBOL_GPL(unregister_syscore_ops);
35959diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
35960index edfa251..1734d4d 100644
35961--- a/drivers/block/cciss.c
35962+++ b/drivers/block/cciss.c
35963@@ -3011,7 +3011,7 @@ static void start_io(ctlr_info_t *h)
35964 while (!list_empty(&h->reqQ)) {
35965 c = list_entry(h->reqQ.next, CommandList_struct, list);
35966 /* can't do anything if fifo is full */
35967- if ((h->access.fifo_full(h))) {
35968+ if ((h->access->fifo_full(h))) {
35969 dev_warn(&h->pdev->dev, "fifo full\n");
35970 break;
35971 }
35972@@ -3021,7 +3021,7 @@ static void start_io(ctlr_info_t *h)
35973 h->Qdepth--;
35974
35975 /* Tell the controller execute command */
35976- h->access.submit_command(h, c);
35977+ h->access->submit_command(h, c);
35978
35979 /* Put job onto the completed Q */
35980 addQ(&h->cmpQ, c);
35981@@ -3447,17 +3447,17 @@ startio:
35982
35983 static inline unsigned long get_next_completion(ctlr_info_t *h)
35984 {
35985- return h->access.command_completed(h);
35986+ return h->access->command_completed(h);
35987 }
35988
35989 static inline int interrupt_pending(ctlr_info_t *h)
35990 {
35991- return h->access.intr_pending(h);
35992+ return h->access->intr_pending(h);
35993 }
35994
35995 static inline long interrupt_not_for_us(ctlr_info_t *h)
35996 {
35997- return ((h->access.intr_pending(h) == 0) ||
35998+ return ((h->access->intr_pending(h) == 0) ||
35999 (h->interrupts_enabled == 0));
36000 }
36001
36002@@ -3490,7 +3490,7 @@ static inline u32 next_command(ctlr_info_t *h)
36003 u32 a;
36004
36005 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
36006- return h->access.command_completed(h);
36007+ return h->access->command_completed(h);
36008
36009 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
36010 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
36011@@ -4047,7 +4047,7 @@ static void cciss_put_controller_into_performant_mode(ctlr_info_t *h)
36012 trans_support & CFGTBL_Trans_use_short_tags);
36013
36014 /* Change the access methods to the performant access methods */
36015- h->access = SA5_performant_access;
36016+ h->access = &SA5_performant_access;
36017 h->transMethod = CFGTBL_Trans_Performant;
36018
36019 return;
36020@@ -4327,7 +4327,7 @@ static int cciss_pci_init(ctlr_info_t *h)
36021 if (prod_index < 0)
36022 return -ENODEV;
36023 h->product_name = products[prod_index].product_name;
36024- h->access = *(products[prod_index].access);
36025+ h->access = products[prod_index].access;
36026
36027 if (cciss_board_disabled(h)) {
36028 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
36029@@ -5059,7 +5059,7 @@ reinit_after_soft_reset:
36030 }
36031
36032 /* make sure the board interrupts are off */
36033- h->access.set_intr_mask(h, CCISS_INTR_OFF);
36034+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
36035 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
36036 if (rc)
36037 goto clean2;
36038@@ -5109,7 +5109,7 @@ reinit_after_soft_reset:
36039 * fake ones to scoop up any residual completions.
36040 */
36041 spin_lock_irqsave(&h->lock, flags);
36042- h->access.set_intr_mask(h, CCISS_INTR_OFF);
36043+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
36044 spin_unlock_irqrestore(&h->lock, flags);
36045 free_irq(h->intr[h->intr_mode], h);
36046 rc = cciss_request_irq(h, cciss_msix_discard_completions,
36047@@ -5129,9 +5129,9 @@ reinit_after_soft_reset:
36048 dev_info(&h->pdev->dev, "Board READY.\n");
36049 dev_info(&h->pdev->dev,
36050 "Waiting for stale completions to drain.\n");
36051- h->access.set_intr_mask(h, CCISS_INTR_ON);
36052+ h->access->set_intr_mask(h, CCISS_INTR_ON);
36053 msleep(10000);
36054- h->access.set_intr_mask(h, CCISS_INTR_OFF);
36055+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
36056
36057 rc = controller_reset_failed(h->cfgtable);
36058 if (rc)
36059@@ -5154,7 +5154,7 @@ reinit_after_soft_reset:
36060 cciss_scsi_setup(h);
36061
36062 /* Turn the interrupts on so we can service requests */
36063- h->access.set_intr_mask(h, CCISS_INTR_ON);
36064+ h->access->set_intr_mask(h, CCISS_INTR_ON);
36065
36066 /* Get the firmware version */
36067 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
36068@@ -5226,7 +5226,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
36069 kfree(flush_buf);
36070 if (return_code != IO_OK)
36071 dev_warn(&h->pdev->dev, "Error flushing cache\n");
36072- h->access.set_intr_mask(h, CCISS_INTR_OFF);
36073+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
36074 free_irq(h->intr[h->intr_mode], h);
36075 }
36076
36077diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
36078index 7fda30e..eb5dfe0 100644
36079--- a/drivers/block/cciss.h
36080+++ b/drivers/block/cciss.h
36081@@ -101,7 +101,7 @@ struct ctlr_info
36082 /* information about each logical volume */
36083 drive_info_struct *drv[CISS_MAX_LUN];
36084
36085- struct access_method access;
36086+ struct access_method *access;
36087
36088 /* queue and queue Info */
36089 struct list_head reqQ;
36090diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
36091index 2b94403..fd6ad1f 100644
36092--- a/drivers/block/cpqarray.c
36093+++ b/drivers/block/cpqarray.c
36094@@ -404,7 +404,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
36095 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
36096 goto Enomem4;
36097 }
36098- hba[i]->access.set_intr_mask(hba[i], 0);
36099+ hba[i]->access->set_intr_mask(hba[i], 0);
36100 if (request_irq(hba[i]->intr, do_ida_intr,
36101 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
36102 {
36103@@ -459,7 +459,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
36104 add_timer(&hba[i]->timer);
36105
36106 /* Enable IRQ now that spinlock and rate limit timer are set up */
36107- hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
36108+ hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
36109
36110 for(j=0; j<NWD; j++) {
36111 struct gendisk *disk = ida_gendisk[i][j];
36112@@ -694,7 +694,7 @@ DBGINFO(
36113 for(i=0; i<NR_PRODUCTS; i++) {
36114 if (board_id == products[i].board_id) {
36115 c->product_name = products[i].product_name;
36116- c->access = *(products[i].access);
36117+ c->access = products[i].access;
36118 break;
36119 }
36120 }
36121@@ -792,7 +792,7 @@ static int cpqarray_eisa_detect(void)
36122 hba[ctlr]->intr = intr;
36123 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
36124 hba[ctlr]->product_name = products[j].product_name;
36125- hba[ctlr]->access = *(products[j].access);
36126+ hba[ctlr]->access = products[j].access;
36127 hba[ctlr]->ctlr = ctlr;
36128 hba[ctlr]->board_id = board_id;
36129 hba[ctlr]->pci_dev = NULL; /* not PCI */
36130@@ -978,7 +978,7 @@ static void start_io(ctlr_info_t *h)
36131
36132 while((c = h->reqQ) != NULL) {
36133 /* Can't do anything if we're busy */
36134- if (h->access.fifo_full(h) == 0)
36135+ if (h->access->fifo_full(h) == 0)
36136 return;
36137
36138 /* Get the first entry from the request Q */
36139@@ -986,7 +986,7 @@ static void start_io(ctlr_info_t *h)
36140 h->Qdepth--;
36141
36142 /* Tell the controller to do our bidding */
36143- h->access.submit_command(h, c);
36144+ h->access->submit_command(h, c);
36145
36146 /* Get onto the completion Q */
36147 addQ(&h->cmpQ, c);
36148@@ -1048,7 +1048,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
36149 unsigned long flags;
36150 __u32 a,a1;
36151
36152- istat = h->access.intr_pending(h);
36153+ istat = h->access->intr_pending(h);
36154 /* Is this interrupt for us? */
36155 if (istat == 0)
36156 return IRQ_NONE;
36157@@ -1059,7 +1059,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
36158 */
36159 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
36160 if (istat & FIFO_NOT_EMPTY) {
36161- while((a = h->access.command_completed(h))) {
36162+ while((a = h->access->command_completed(h))) {
36163 a1 = a; a &= ~3;
36164 if ((c = h->cmpQ) == NULL)
36165 {
36166@@ -1448,11 +1448,11 @@ static int sendcmd(
36167 /*
36168 * Disable interrupt
36169 */
36170- info_p->access.set_intr_mask(info_p, 0);
36171+ info_p->access->set_intr_mask(info_p, 0);
36172 /* Make sure there is room in the command FIFO */
36173 /* Actually it should be completely empty at this time. */
36174 for (i = 200000; i > 0; i--) {
36175- temp = info_p->access.fifo_full(info_p);
36176+ temp = info_p->access->fifo_full(info_p);
36177 if (temp != 0) {
36178 break;
36179 }
36180@@ -1465,7 +1465,7 @@ DBG(
36181 /*
36182 * Send the cmd
36183 */
36184- info_p->access.submit_command(info_p, c);
36185+ info_p->access->submit_command(info_p, c);
36186 complete = pollcomplete(ctlr);
36187
36188 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
36189@@ -1548,9 +1548,9 @@ static int revalidate_allvol(ctlr_info_t *host)
36190 * we check the new geometry. Then turn interrupts back on when
36191 * we're done.
36192 */
36193- host->access.set_intr_mask(host, 0);
36194+ host->access->set_intr_mask(host, 0);
36195 getgeometry(ctlr);
36196- host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
36197+ host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
36198
36199 for(i=0; i<NWD; i++) {
36200 struct gendisk *disk = ida_gendisk[ctlr][i];
36201@@ -1590,7 +1590,7 @@ static int pollcomplete(int ctlr)
36202 /* Wait (up to 2 seconds) for a command to complete */
36203
36204 for (i = 200000; i > 0; i--) {
36205- done = hba[ctlr]->access.command_completed(hba[ctlr]);
36206+ done = hba[ctlr]->access->command_completed(hba[ctlr]);
36207 if (done == 0) {
36208 udelay(10); /* a short fixed delay */
36209 } else
36210diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
36211index be73e9d..7fbf140 100644
36212--- a/drivers/block/cpqarray.h
36213+++ b/drivers/block/cpqarray.h
36214@@ -99,7 +99,7 @@ struct ctlr_info {
36215 drv_info_t drv[NWD];
36216 struct proc_dir_entry *proc;
36217
36218- struct access_method access;
36219+ struct access_method *access;
36220
36221 cmdlist_t *reqQ;
36222 cmdlist_t *cmpQ;
36223diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
36224index 2d7f608..11245fe 100644
36225--- a/drivers/block/drbd/drbd_int.h
36226+++ b/drivers/block/drbd/drbd_int.h
36227@@ -582,7 +582,7 @@ struct drbd_epoch {
36228 struct drbd_tconn *tconn;
36229 struct list_head list;
36230 unsigned int barrier_nr;
36231- atomic_t epoch_size; /* increased on every request added. */
36232+ atomic_unchecked_t epoch_size; /* increased on every request added. */
36233 atomic_t active; /* increased on every req. added, and dec on every finished. */
36234 unsigned long flags;
36235 };
36236@@ -1022,7 +1022,7 @@ struct drbd_conf {
36237 unsigned int al_tr_number;
36238 int al_tr_cycle;
36239 wait_queue_head_t seq_wait;
36240- atomic_t packet_seq;
36241+ atomic_unchecked_t packet_seq;
36242 unsigned int peer_seq;
36243 spinlock_t peer_seq_lock;
36244 unsigned int minor;
36245@@ -1572,7 +1572,7 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
36246 char __user *uoptval;
36247 int err;
36248
36249- uoptval = (char __user __force *)optval;
36250+ uoptval = (char __force_user *)optval;
36251
36252 set_fs(KERNEL_DS);
36253 if (level == SOL_SOCKET)
36254diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
36255index 55635ed..40e837c 100644
36256--- a/drivers/block/drbd/drbd_main.c
36257+++ b/drivers/block/drbd/drbd_main.c
36258@@ -1317,7 +1317,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packet cmd,
36259 p->sector = sector;
36260 p->block_id = block_id;
36261 p->blksize = blksize;
36262- p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
36263+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
36264 return drbd_send_command(mdev, sock, cmd, sizeof(*p), NULL, 0);
36265 }
36266
36267@@ -1619,7 +1619,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
36268 return -EIO;
36269 p->sector = cpu_to_be64(req->i.sector);
36270 p->block_id = (unsigned long)req;
36271- p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
36272+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
36273 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
36274 if (mdev->state.conn >= C_SYNC_SOURCE &&
36275 mdev->state.conn <= C_PAUSED_SYNC_T)
36276@@ -2574,8 +2574,8 @@ void conn_destroy(struct kref *kref)
36277 {
36278 struct drbd_tconn *tconn = container_of(kref, struct drbd_tconn, kref);
36279
36280- if (atomic_read(&tconn->current_epoch->epoch_size) != 0)
36281- conn_err(tconn, "epoch_size:%d\n", atomic_read(&tconn->current_epoch->epoch_size));
36282+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size) != 0)
36283+ conn_err(tconn, "epoch_size:%d\n", atomic_read_unchecked(&tconn->current_epoch->epoch_size));
36284 kfree(tconn->current_epoch);
36285
36286 idr_destroy(&tconn->volumes);
36287diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
36288index 8cc1e64..ba7ffa9 100644
36289--- a/drivers/block/drbd/drbd_nl.c
36290+++ b/drivers/block/drbd/drbd_nl.c
36291@@ -3440,7 +3440,7 @@ out:
36292
36293 void drbd_bcast_event(struct drbd_conf *mdev, const struct sib_info *sib)
36294 {
36295- static atomic_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
36296+ static atomic_unchecked_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
36297 struct sk_buff *msg;
36298 struct drbd_genlmsghdr *d_out;
36299 unsigned seq;
36300@@ -3453,7 +3453,7 @@ void drbd_bcast_event(struct drbd_conf *mdev, const struct sib_info *sib)
36301 return;
36302 }
36303
36304- seq = atomic_inc_return(&drbd_genl_seq);
36305+ seq = atomic_inc_return_unchecked(&drbd_genl_seq);
36306 msg = genlmsg_new(NLMSG_GOODSIZE, GFP_NOIO);
36307 if (!msg)
36308 goto failed;
36309diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
36310index cc29cd3..d4b058b 100644
36311--- a/drivers/block/drbd/drbd_receiver.c
36312+++ b/drivers/block/drbd/drbd_receiver.c
36313@@ -834,7 +834,7 @@ int drbd_connected(struct drbd_conf *mdev)
36314 {
36315 int err;
36316
36317- atomic_set(&mdev->packet_seq, 0);
36318+ atomic_set_unchecked(&mdev->packet_seq, 0);
36319 mdev->peer_seq = 0;
36320
36321 mdev->state_mutex = mdev->tconn->agreed_pro_version < 100 ?
36322@@ -1193,7 +1193,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
36323 do {
36324 next_epoch = NULL;
36325
36326- epoch_size = atomic_read(&epoch->epoch_size);
36327+ epoch_size = atomic_read_unchecked(&epoch->epoch_size);
36328
36329 switch (ev & ~EV_CLEANUP) {
36330 case EV_PUT:
36331@@ -1233,7 +1233,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
36332 rv = FE_DESTROYED;
36333 } else {
36334 epoch->flags = 0;
36335- atomic_set(&epoch->epoch_size, 0);
36336+ atomic_set_unchecked(&epoch->epoch_size, 0);
36337 /* atomic_set(&epoch->active, 0); is already zero */
36338 if (rv == FE_STILL_LIVE)
36339 rv = FE_RECYCLED;
36340@@ -1451,7 +1451,7 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
36341 conn_wait_active_ee_empty(tconn);
36342 drbd_flush(tconn);
36343
36344- if (atomic_read(&tconn->current_epoch->epoch_size)) {
36345+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
36346 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
36347 if (epoch)
36348 break;
36349@@ -1464,11 +1464,11 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
36350 }
36351
36352 epoch->flags = 0;
36353- atomic_set(&epoch->epoch_size, 0);
36354+ atomic_set_unchecked(&epoch->epoch_size, 0);
36355 atomic_set(&epoch->active, 0);
36356
36357 spin_lock(&tconn->epoch_lock);
36358- if (atomic_read(&tconn->current_epoch->epoch_size)) {
36359+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
36360 list_add(&epoch->list, &tconn->current_epoch->list);
36361 tconn->current_epoch = epoch;
36362 tconn->epochs++;
36363@@ -2172,7 +2172,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
36364
36365 err = wait_for_and_update_peer_seq(mdev, peer_seq);
36366 drbd_send_ack_dp(mdev, P_NEG_ACK, p, pi->size);
36367- atomic_inc(&tconn->current_epoch->epoch_size);
36368+ atomic_inc_unchecked(&tconn->current_epoch->epoch_size);
36369 err2 = drbd_drain_block(mdev, pi->size);
36370 if (!err)
36371 err = err2;
36372@@ -2206,7 +2206,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
36373
36374 spin_lock(&tconn->epoch_lock);
36375 peer_req->epoch = tconn->current_epoch;
36376- atomic_inc(&peer_req->epoch->epoch_size);
36377+ atomic_inc_unchecked(&peer_req->epoch->epoch_size);
36378 atomic_inc(&peer_req->epoch->active);
36379 spin_unlock(&tconn->epoch_lock);
36380
36381@@ -4347,7 +4347,7 @@ struct data_cmd {
36382 int expect_payload;
36383 size_t pkt_size;
36384 int (*fn)(struct drbd_tconn *, struct packet_info *);
36385-};
36386+} __do_const;
36387
36388 static struct data_cmd drbd_cmd_handler[] = {
36389 [P_DATA] = { 1, sizeof(struct p_data), receive_Data },
36390@@ -4467,7 +4467,7 @@ static void conn_disconnect(struct drbd_tconn *tconn)
36391 if (!list_empty(&tconn->current_epoch->list))
36392 conn_err(tconn, "ASSERTION FAILED: tconn->current_epoch->list not empty\n");
36393 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
36394- atomic_set(&tconn->current_epoch->epoch_size, 0);
36395+ atomic_set_unchecked(&tconn->current_epoch->epoch_size, 0);
36396 tconn->send.seen_any_write_yet = false;
36397
36398 conn_info(tconn, "Connection closed\n");
36399@@ -5223,7 +5223,7 @@ static int tconn_finish_peer_reqs(struct drbd_tconn *tconn)
36400 struct asender_cmd {
36401 size_t pkt_size;
36402 int (*fn)(struct drbd_tconn *tconn, struct packet_info *);
36403-};
36404+} __do_const;
36405
36406 static struct asender_cmd asender_tbl[] = {
36407 [P_PING] = { 0, got_Ping },
36408diff --git a/drivers/block/loop.c b/drivers/block/loop.c
36409index 40e7155..df5c79a 100644
36410--- a/drivers/block/loop.c
36411+++ b/drivers/block/loop.c
36412@@ -232,7 +232,7 @@ static int __do_lo_send_write(struct file *file,
36413
36414 file_start_write(file);
36415 set_fs(get_ds());
36416- bw = file->f_op->write(file, buf, len, &pos);
36417+ bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
36418 set_fs(old_fs);
36419 file_end_write(file);
36420 if (likely(bw == len))
36421diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
36422index 5618847..5a46f3b 100644
36423--- a/drivers/block/pktcdvd.c
36424+++ b/drivers/block/pktcdvd.c
36425@@ -108,7 +108,7 @@ static int pkt_seq_show(struct seq_file *m, void *p);
36426
36427 static sector_t get_zone(sector_t sector, struct pktcdvd_device *pd)
36428 {
36429- return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1);
36430+ return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1UL);
36431 }
36432
36433 /*
36434@@ -1897,7 +1897,7 @@ static noinline_for_stack int pkt_probe_settings(struct pktcdvd_device *pd)
36435 return -EROFS;
36436 }
36437 pd->settings.fp = ti.fp;
36438- pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1);
36439+ pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1UL);
36440
36441 if (ti.nwa_v) {
36442 pd->nwa = be32_to_cpu(ti.next_writable);
36443diff --git a/drivers/bluetooth/btwilink.c b/drivers/bluetooth/btwilink.c
36444index 60abf59..80789e1 100644
36445--- a/drivers/bluetooth/btwilink.c
36446+++ b/drivers/bluetooth/btwilink.c
36447@@ -293,7 +293,7 @@ static int ti_st_send_frame(struct sk_buff *skb)
36448
36449 static int bt_ti_probe(struct platform_device *pdev)
36450 {
36451- static struct ti_st *hst;
36452+ struct ti_st *hst;
36453 struct hci_dev *hdev;
36454 int err;
36455
36456diff --git a/drivers/bus/arm-cci.c b/drivers/bus/arm-cci.c
36457index 2009266..7be9ca2 100644
36458--- a/drivers/bus/arm-cci.c
36459+++ b/drivers/bus/arm-cci.c
36460@@ -405,7 +405,7 @@ static int __init cci_probe(void)
36461
36462 nb_cci_ports = cci_config->nb_ace + cci_config->nb_ace_lite;
36463
36464- ports = kcalloc(sizeof(*ports), nb_cci_ports, GFP_KERNEL);
36465+ ports = kcalloc(nb_cci_ports, sizeof(*ports), GFP_KERNEL);
36466 if (!ports)
36467 return -ENOMEM;
36468
36469diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
36470index 8a3aff7..d7538c2 100644
36471--- a/drivers/cdrom/cdrom.c
36472+++ b/drivers/cdrom/cdrom.c
36473@@ -416,7 +416,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
36474 ENSURE(reset, CDC_RESET);
36475 ENSURE(generic_packet, CDC_GENERIC_PACKET);
36476 cdi->mc_flags = 0;
36477- cdo->n_minors = 0;
36478 cdi->options = CDO_USE_FFLAGS;
36479
36480 if (autoclose==1 && CDROM_CAN(CDC_CLOSE_TRAY))
36481@@ -436,8 +435,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
36482 else
36483 cdi->cdda_method = CDDA_OLD;
36484
36485- if (!cdo->generic_packet)
36486- cdo->generic_packet = cdrom_dummy_generic_packet;
36487+ if (!cdo->generic_packet) {
36488+ pax_open_kernel();
36489+ *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
36490+ pax_close_kernel();
36491+ }
36492
36493 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
36494 mutex_lock(&cdrom_mutex);
36495@@ -458,7 +460,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
36496 if (cdi->exit)
36497 cdi->exit(cdi);
36498
36499- cdi->ops->n_minors--;
36500 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
36501 }
36502
36503@@ -2107,7 +2108,7 @@ static int cdrom_read_cdda_old(struct cdrom_device_info *cdi, __u8 __user *ubuf,
36504 */
36505 nr = nframes;
36506 do {
36507- cgc.buffer = kmalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
36508+ cgc.buffer = kzalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
36509 if (cgc.buffer)
36510 break;
36511
36512@@ -3429,7 +3430,7 @@ static int cdrom_print_info(const char *header, int val, char *info,
36513 struct cdrom_device_info *cdi;
36514 int ret;
36515
36516- ret = scnprintf(info + *pos, max_size - *pos, header);
36517+ ret = scnprintf(info + *pos, max_size - *pos, "%s", header);
36518 if (!ret)
36519 return 1;
36520
36521diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
36522index 5980cb9..6d7bd7e 100644
36523--- a/drivers/cdrom/gdrom.c
36524+++ b/drivers/cdrom/gdrom.c
36525@@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
36526 .audio_ioctl = gdrom_audio_ioctl,
36527 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
36528 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
36529- .n_minors = 1,
36530 };
36531
36532 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
36533diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
36534index 1421997..33f5d6d 100644
36535--- a/drivers/char/Kconfig
36536+++ b/drivers/char/Kconfig
36537@@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
36538
36539 config DEVKMEM
36540 bool "/dev/kmem virtual device support"
36541- default y
36542+ default n
36543+ depends on !GRKERNSEC_KMEM
36544 help
36545 Say Y here if you want to support the /dev/kmem device. The
36546 /dev/kmem device is rarely used, but can be used for certain
36547@@ -570,6 +571,7 @@ config DEVPORT
36548 bool
36549 depends on !M68K
36550 depends on ISA || PCI
36551+ depends on !GRKERNSEC_KMEM
36552 default y
36553
36554 source "drivers/s390/char/Kconfig"
36555diff --git a/drivers/char/agp/compat_ioctl.c b/drivers/char/agp/compat_ioctl.c
36556index a48e05b..6bac831 100644
36557--- a/drivers/char/agp/compat_ioctl.c
36558+++ b/drivers/char/agp/compat_ioctl.c
36559@@ -108,7 +108,7 @@ static int compat_agpioc_reserve_wrap(struct agp_file_private *priv, void __user
36560 return -ENOMEM;
36561 }
36562
36563- if (copy_from_user(usegment, (void __user *) ureserve.seg_list,
36564+ if (copy_from_user(usegment, (void __force_user *) ureserve.seg_list,
36565 sizeof(*usegment) * ureserve.seg_count)) {
36566 kfree(usegment);
36567 kfree(ksegment);
36568diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
36569index 1b19239..b87b143 100644
36570--- a/drivers/char/agp/frontend.c
36571+++ b/drivers/char/agp/frontend.c
36572@@ -819,7 +819,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
36573 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
36574 return -EFAULT;
36575
36576- if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
36577+ if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
36578 return -EFAULT;
36579
36580 client = agp_find_client_by_pid(reserve.pid);
36581@@ -849,7 +849,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
36582 if (segment == NULL)
36583 return -ENOMEM;
36584
36585- if (copy_from_user(segment, (void __user *) reserve.seg_list,
36586+ if (copy_from_user(segment, (void __force_user *) reserve.seg_list,
36587 sizeof(struct agp_segment) * reserve.seg_count)) {
36588 kfree(segment);
36589 return -EFAULT;
36590diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
36591index 4f94375..413694e 100644
36592--- a/drivers/char/genrtc.c
36593+++ b/drivers/char/genrtc.c
36594@@ -273,6 +273,7 @@ static int gen_rtc_ioctl(struct file *file,
36595 switch (cmd) {
36596
36597 case RTC_PLL_GET:
36598+ memset(&pll, 0, sizeof(pll));
36599 if (get_rtc_pll(&pll))
36600 return -EINVAL;
36601 else
36602diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
36603index 448ce5e..3a76625 100644
36604--- a/drivers/char/hpet.c
36605+++ b/drivers/char/hpet.c
36606@@ -559,7 +559,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
36607 }
36608
36609 static int
36610-hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
36611+hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
36612 struct hpet_info *info)
36613 {
36614 struct hpet_timer __iomem *timer;
36615diff --git a/drivers/char/hw_random/intel-rng.c b/drivers/char/hw_random/intel-rng.c
36616index 86fe45c..c0ea948 100644
36617--- a/drivers/char/hw_random/intel-rng.c
36618+++ b/drivers/char/hw_random/intel-rng.c
36619@@ -314,7 +314,7 @@ PFX "RNG, try using the 'no_fwh_detect' option.\n";
36620
36621 if (no_fwh_detect)
36622 return -ENODEV;
36623- printk(warning);
36624+ printk("%s", warning);
36625 return -EBUSY;
36626 }
36627
36628diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
36629index ec4e10f..f2a763b 100644
36630--- a/drivers/char/ipmi/ipmi_msghandler.c
36631+++ b/drivers/char/ipmi/ipmi_msghandler.c
36632@@ -420,7 +420,7 @@ struct ipmi_smi {
36633 struct proc_dir_entry *proc_dir;
36634 char proc_dir_name[10];
36635
36636- atomic_t stats[IPMI_NUM_STATS];
36637+ atomic_unchecked_t stats[IPMI_NUM_STATS];
36638
36639 /*
36640 * run_to_completion duplicate of smb_info, smi_info
36641@@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
36642
36643
36644 #define ipmi_inc_stat(intf, stat) \
36645- atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
36646+ atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
36647 #define ipmi_get_stat(intf, stat) \
36648- ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
36649+ ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
36650
36651 static int is_lan_addr(struct ipmi_addr *addr)
36652 {
36653@@ -2883,7 +2883,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
36654 INIT_LIST_HEAD(&intf->cmd_rcvrs);
36655 init_waitqueue_head(&intf->waitq);
36656 for (i = 0; i < IPMI_NUM_STATS; i++)
36657- atomic_set(&intf->stats[i], 0);
36658+ atomic_set_unchecked(&intf->stats[i], 0);
36659
36660 intf->proc_dir = NULL;
36661
36662diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
36663index 15e4a60..b046093 100644
36664--- a/drivers/char/ipmi/ipmi_si_intf.c
36665+++ b/drivers/char/ipmi/ipmi_si_intf.c
36666@@ -280,7 +280,7 @@ struct smi_info {
36667 unsigned char slave_addr;
36668
36669 /* Counters and things for the proc filesystem. */
36670- atomic_t stats[SI_NUM_STATS];
36671+ atomic_unchecked_t stats[SI_NUM_STATS];
36672
36673 struct task_struct *thread;
36674
36675@@ -289,9 +289,9 @@ struct smi_info {
36676 };
36677
36678 #define smi_inc_stat(smi, stat) \
36679- atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
36680+ atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
36681 #define smi_get_stat(smi, stat) \
36682- ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
36683+ ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
36684
36685 #define SI_MAX_PARMS 4
36686
36687@@ -3324,7 +3324,7 @@ static int try_smi_init(struct smi_info *new_smi)
36688 atomic_set(&new_smi->req_events, 0);
36689 new_smi->run_to_completion = 0;
36690 for (i = 0; i < SI_NUM_STATS; i++)
36691- atomic_set(&new_smi->stats[i], 0);
36692+ atomic_set_unchecked(&new_smi->stats[i], 0);
36693
36694 new_smi->interrupt_disabled = 1;
36695 atomic_set(&new_smi->stop_operation, 0);
36696diff --git a/drivers/char/mem.c b/drivers/char/mem.c
36697index f895a8c..2bc9147 100644
36698--- a/drivers/char/mem.c
36699+++ b/drivers/char/mem.c
36700@@ -18,6 +18,7 @@
36701 #include <linux/raw.h>
36702 #include <linux/tty.h>
36703 #include <linux/capability.h>
36704+#include <linux/security.h>
36705 #include <linux/ptrace.h>
36706 #include <linux/device.h>
36707 #include <linux/highmem.h>
36708@@ -37,6 +38,10 @@
36709
36710 #define DEVPORT_MINOR 4
36711
36712+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
36713+extern const struct file_operations grsec_fops;
36714+#endif
36715+
36716 static inline unsigned long size_inside_page(unsigned long start,
36717 unsigned long size)
36718 {
36719@@ -68,9 +73,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
36720
36721 while (cursor < to) {
36722 if (!devmem_is_allowed(pfn)) {
36723+#ifdef CONFIG_GRKERNSEC_KMEM
36724+ gr_handle_mem_readwrite(from, to);
36725+#else
36726 printk(KERN_INFO
36727 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
36728 current->comm, from, to);
36729+#endif
36730 return 0;
36731 }
36732 cursor += PAGE_SIZE;
36733@@ -78,6 +87,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
36734 }
36735 return 1;
36736 }
36737+#elif defined(CONFIG_GRKERNSEC_KMEM)
36738+static inline int range_is_allowed(unsigned long pfn, unsigned long size)
36739+{
36740+ return 0;
36741+}
36742 #else
36743 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
36744 {
36745@@ -120,6 +134,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
36746
36747 while (count > 0) {
36748 unsigned long remaining;
36749+ char *temp;
36750
36751 sz = size_inside_page(p, count);
36752
36753@@ -135,7 +150,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
36754 if (!ptr)
36755 return -EFAULT;
36756
36757- remaining = copy_to_user(buf, ptr, sz);
36758+#ifdef CONFIG_PAX_USERCOPY
36759+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
36760+ if (!temp) {
36761+ unxlate_dev_mem_ptr(p, ptr);
36762+ return -ENOMEM;
36763+ }
36764+ memcpy(temp, ptr, sz);
36765+#else
36766+ temp = ptr;
36767+#endif
36768+
36769+ remaining = copy_to_user(buf, temp, sz);
36770+
36771+#ifdef CONFIG_PAX_USERCOPY
36772+ kfree(temp);
36773+#endif
36774+
36775 unxlate_dev_mem_ptr(p, ptr);
36776 if (remaining)
36777 return -EFAULT;
36778@@ -364,9 +395,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
36779 size_t count, loff_t *ppos)
36780 {
36781 unsigned long p = *ppos;
36782- ssize_t low_count, read, sz;
36783+ ssize_t low_count, read, sz, err = 0;
36784 char *kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
36785- int err = 0;
36786
36787 read = 0;
36788 if (p < (unsigned long) high_memory) {
36789@@ -388,6 +418,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
36790 }
36791 #endif
36792 while (low_count > 0) {
36793+ char *temp;
36794+
36795 sz = size_inside_page(p, low_count);
36796
36797 /*
36798@@ -397,7 +429,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
36799 */
36800 kbuf = xlate_dev_kmem_ptr((char *)p);
36801
36802- if (copy_to_user(buf, kbuf, sz))
36803+#ifdef CONFIG_PAX_USERCOPY
36804+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
36805+ if (!temp)
36806+ return -ENOMEM;
36807+ memcpy(temp, kbuf, sz);
36808+#else
36809+ temp = kbuf;
36810+#endif
36811+
36812+ err = copy_to_user(buf, temp, sz);
36813+
36814+#ifdef CONFIG_PAX_USERCOPY
36815+ kfree(temp);
36816+#endif
36817+
36818+ if (err)
36819 return -EFAULT;
36820 buf += sz;
36821 p += sz;
36822@@ -822,6 +869,9 @@ static const struct memdev {
36823 #ifdef CONFIG_PRINTK
36824 [11] = { "kmsg", 0644, &kmsg_fops, NULL },
36825 #endif
36826+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
36827+ [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
36828+#endif
36829 };
36830
36831 static int memory_open(struct inode *inode, struct file *filp)
36832@@ -893,7 +943,7 @@ static int __init chr_dev_init(void)
36833 continue;
36834
36835 device_create(mem_class, NULL, MKDEV(MEM_MAJOR, minor),
36836- NULL, devlist[minor].name);
36837+ NULL, "%s", devlist[minor].name);
36838 }
36839
36840 return tty_init();
36841diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
36842index 9df78e2..01ba9ae 100644
36843--- a/drivers/char/nvram.c
36844+++ b/drivers/char/nvram.c
36845@@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
36846
36847 spin_unlock_irq(&rtc_lock);
36848
36849- if (copy_to_user(buf, contents, tmp - contents))
36850+ if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
36851 return -EFAULT;
36852
36853 *ppos = i;
36854diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
36855index d39cca6..8c1e269 100644
36856--- a/drivers/char/pcmcia/synclink_cs.c
36857+++ b/drivers/char/pcmcia/synclink_cs.c
36858@@ -2345,9 +2345,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
36859
36860 if (debug_level >= DEBUG_LEVEL_INFO)
36861 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
36862- __FILE__, __LINE__, info->device_name, port->count);
36863+ __FILE__, __LINE__, info->device_name, atomic_read(&port->count));
36864
36865- WARN_ON(!port->count);
36866+ WARN_ON(!atomic_read(&port->count));
36867
36868 if (tty_port_close_start(port, tty, filp) == 0)
36869 goto cleanup;
36870@@ -2365,7 +2365,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
36871 cleanup:
36872 if (debug_level >= DEBUG_LEVEL_INFO)
36873 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__, __LINE__,
36874- tty->driver->name, port->count);
36875+ tty->driver->name, atomic_read(&port->count));
36876 }
36877
36878 /* Wait until the transmitter is empty.
36879@@ -2507,7 +2507,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
36880
36881 if (debug_level >= DEBUG_LEVEL_INFO)
36882 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
36883- __FILE__, __LINE__, tty->driver->name, port->count);
36884+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
36885
36886 /* If port is closing, signal caller to try again */
36887 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
36888@@ -2527,11 +2527,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
36889 goto cleanup;
36890 }
36891 spin_lock(&port->lock);
36892- port->count++;
36893+ atomic_inc(&port->count);
36894 spin_unlock(&port->lock);
36895 spin_unlock_irqrestore(&info->netlock, flags);
36896
36897- if (port->count == 1) {
36898+ if (atomic_read(&port->count) == 1) {
36899 /* 1st open on this device, init hardware */
36900 retval = startup(info, tty);
36901 if (retval < 0)
36902@@ -3920,7 +3920,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
36903 unsigned short new_crctype;
36904
36905 /* return error if TTY interface open */
36906- if (info->port.count)
36907+ if (atomic_read(&info->port.count))
36908 return -EBUSY;
36909
36910 switch (encoding)
36911@@ -4024,7 +4024,7 @@ static int hdlcdev_open(struct net_device *dev)
36912
36913 /* arbitrate between network and tty opens */
36914 spin_lock_irqsave(&info->netlock, flags);
36915- if (info->port.count != 0 || info->netcount != 0) {
36916+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
36917 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
36918 spin_unlock_irqrestore(&info->netlock, flags);
36919 return -EBUSY;
36920@@ -4114,7 +4114,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
36921 printk("%s:hdlcdev_ioctl(%s)\n", __FILE__, dev->name);
36922
36923 /* return error if TTY interface open */
36924- if (info->port.count)
36925+ if (atomic_read(&info->port.count))
36926 return -EBUSY;
36927
36928 if (cmd != SIOCWANDEV)
36929diff --git a/drivers/char/random.c b/drivers/char/random.c
36930index 7a744d3..35a177ee 100644
36931--- a/drivers/char/random.c
36932+++ b/drivers/char/random.c
36933@@ -269,8 +269,13 @@
36934 /*
36935 * Configuration information
36936 */
36937+#ifdef CONFIG_GRKERNSEC_RANDNET
36938+#define INPUT_POOL_WORDS 512
36939+#define OUTPUT_POOL_WORDS 128
36940+#else
36941 #define INPUT_POOL_WORDS 128
36942 #define OUTPUT_POOL_WORDS 32
36943+#endif
36944 #define SEC_XFER_SIZE 512
36945 #define EXTRACT_SIZE 10
36946
36947@@ -310,10 +315,17 @@ static struct poolinfo {
36948 int poolwords;
36949 int tap1, tap2, tap3, tap4, tap5;
36950 } poolinfo_table[] = {
36951+#ifdef CONFIG_GRKERNSEC_RANDNET
36952+ /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
36953+ { 512, 411, 308, 208, 104, 1 },
36954+ /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
36955+ { 128, 103, 76, 51, 25, 1 },
36956+#else
36957 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
36958 { 128, 103, 76, 51, 25, 1 },
36959 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
36960 { 32, 26, 20, 14, 7, 1 },
36961+#endif
36962 #if 0
36963 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
36964 { 2048, 1638, 1231, 819, 411, 1 },
36965@@ -521,8 +533,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
36966 input_rotate += i ? 7 : 14;
36967 }
36968
36969- ACCESS_ONCE(r->input_rotate) = input_rotate;
36970- ACCESS_ONCE(r->add_ptr) = i;
36971+ ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
36972+ ACCESS_ONCE_RW(r->add_ptr) = i;
36973 smp_wmb();
36974
36975 if (out)
36976@@ -1029,7 +1041,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
36977
36978 extract_buf(r, tmp);
36979 i = min_t(int, nbytes, EXTRACT_SIZE);
36980- if (copy_to_user(buf, tmp, i)) {
36981+ if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
36982 ret = -EFAULT;
36983 break;
36984 }
36985@@ -1365,7 +1377,7 @@ EXPORT_SYMBOL(generate_random_uuid);
36986 #include <linux/sysctl.h>
36987
36988 static int min_read_thresh = 8, min_write_thresh;
36989-static int max_read_thresh = INPUT_POOL_WORDS * 32;
36990+static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
36991 static int max_write_thresh = INPUT_POOL_WORDS * 32;
36992 static char sysctl_bootid[16];
36993
36994@@ -1381,7 +1393,7 @@ static char sysctl_bootid[16];
36995 static int proc_do_uuid(struct ctl_table *table, int write,
36996 void __user *buffer, size_t *lenp, loff_t *ppos)
36997 {
36998- struct ctl_table fake_table;
36999+ ctl_table_no_const fake_table;
37000 unsigned char buf[64], tmp_uuid[16], *uuid;
37001
37002 uuid = table->data;
37003diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
37004index 7cc1fe22..b602d6b 100644
37005--- a/drivers/char/sonypi.c
37006+++ b/drivers/char/sonypi.c
37007@@ -54,6 +54,7 @@
37008
37009 #include <asm/uaccess.h>
37010 #include <asm/io.h>
37011+#include <asm/local.h>
37012
37013 #include <linux/sonypi.h>
37014
37015@@ -490,7 +491,7 @@ static struct sonypi_device {
37016 spinlock_t fifo_lock;
37017 wait_queue_head_t fifo_proc_list;
37018 struct fasync_struct *fifo_async;
37019- int open_count;
37020+ local_t open_count;
37021 int model;
37022 struct input_dev *input_jog_dev;
37023 struct input_dev *input_key_dev;
37024@@ -892,7 +893,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
37025 static int sonypi_misc_release(struct inode *inode, struct file *file)
37026 {
37027 mutex_lock(&sonypi_device.lock);
37028- sonypi_device.open_count--;
37029+ local_dec(&sonypi_device.open_count);
37030 mutex_unlock(&sonypi_device.lock);
37031 return 0;
37032 }
37033@@ -901,9 +902,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
37034 {
37035 mutex_lock(&sonypi_device.lock);
37036 /* Flush input queue on first open */
37037- if (!sonypi_device.open_count)
37038+ if (!local_read(&sonypi_device.open_count))
37039 kfifo_reset(&sonypi_device.fifo);
37040- sonypi_device.open_count++;
37041+ local_inc(&sonypi_device.open_count);
37042 mutex_unlock(&sonypi_device.lock);
37043
37044 return 0;
37045diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
37046index 64420b3..5c40b56 100644
37047--- a/drivers/char/tpm/tpm_acpi.c
37048+++ b/drivers/char/tpm/tpm_acpi.c
37049@@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
37050 virt = acpi_os_map_memory(start, len);
37051 if (!virt) {
37052 kfree(log->bios_event_log);
37053+ log->bios_event_log = NULL;
37054 printk("%s: ERROR - Unable to map memory\n", __func__);
37055 return -EIO;
37056 }
37057
37058- memcpy_fromio(log->bios_event_log, virt, len);
37059+ memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
37060
37061 acpi_os_unmap_memory(virt, len);
37062 return 0;
37063diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
37064index 84ddc55..1d32f1e 100644
37065--- a/drivers/char/tpm/tpm_eventlog.c
37066+++ b/drivers/char/tpm/tpm_eventlog.c
37067@@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
37068 event = addr;
37069
37070 if ((event->event_type == 0 && event->event_size == 0) ||
37071- ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
37072+ (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
37073 return NULL;
37074
37075 return addr;
37076@@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
37077 return NULL;
37078
37079 if ((event->event_type == 0 && event->event_size == 0) ||
37080- ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
37081+ (event->event_size >= limit - v - sizeof(struct tcpa_event)))
37082 return NULL;
37083
37084 (*pos)++;
37085@@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
37086 int i;
37087
37088 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
37089- seq_putc(m, data[i]);
37090+ if (!seq_putc(m, data[i]))
37091+ return -EFAULT;
37092
37093 return 0;
37094 }
37095diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
37096index b79cf3e..de172d64f 100644
37097--- a/drivers/char/virtio_console.c
37098+++ b/drivers/char/virtio_console.c
37099@@ -682,7 +682,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
37100 if (to_user) {
37101 ssize_t ret;
37102
37103- ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
37104+ ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
37105 if (ret)
37106 return -EFAULT;
37107 } else {
37108@@ -785,7 +785,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
37109 if (!port_has_data(port) && !port->host_connected)
37110 return 0;
37111
37112- return fill_readbuf(port, ubuf, count, true);
37113+ return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
37114 }
37115
37116 static int wait_port_writable(struct port *port, bool nonblock)
37117diff --git a/drivers/clk/clk-composite.c b/drivers/clk/clk-composite.c
37118index a33f46f..a720eed 100644
37119--- a/drivers/clk/clk-composite.c
37120+++ b/drivers/clk/clk-composite.c
37121@@ -122,7 +122,7 @@ struct clk *clk_register_composite(struct device *dev, const char *name,
37122 struct clk *clk;
37123 struct clk_init_data init;
37124 struct clk_composite *composite;
37125- struct clk_ops *clk_composite_ops;
37126+ clk_ops_no_const *clk_composite_ops;
37127
37128 composite = kzalloc(sizeof(*composite), GFP_KERNEL);
37129 if (!composite) {
37130diff --git a/drivers/clk/socfpga/clk.c b/drivers/clk/socfpga/clk.c
37131index 81dd31a..ef5c542 100644
37132--- a/drivers/clk/socfpga/clk.c
37133+++ b/drivers/clk/socfpga/clk.c
37134@@ -22,6 +22,7 @@
37135 #include <linux/clk-provider.h>
37136 #include <linux/io.h>
37137 #include <linux/of.h>
37138+#include <asm/pgtable.h>
37139
37140 /* Clock Manager offsets */
37141 #define CLKMGR_CTRL 0x0
37142@@ -152,8 +153,10 @@ static __init struct clk *socfpga_clk_init(struct device_node *node,
37143 streq(clk_name, "periph_pll") ||
37144 streq(clk_name, "sdram_pll")) {
37145 socfpga_clk->hw.bit_idx = SOCFPGA_PLL_EXT_ENA;
37146- clk_pll_ops.enable = clk_gate_ops.enable;
37147- clk_pll_ops.disable = clk_gate_ops.disable;
37148+ pax_open_kernel();
37149+ *(void **)&clk_pll_ops.enable = clk_gate_ops.enable;
37150+ *(void **)&clk_pll_ops.disable = clk_gate_ops.disable;
37151+ pax_close_kernel();
37152 }
37153
37154 clk = clk_register(NULL, &socfpga_clk->hw.hw);
37155@@ -244,7 +247,7 @@ static unsigned long socfpga_clk_recalc_rate(struct clk_hw *hwclk,
37156 return parent_rate / div;
37157 }
37158
37159-static struct clk_ops gateclk_ops = {
37160+static clk_ops_no_const gateclk_ops __read_only = {
37161 .recalc_rate = socfpga_clk_recalc_rate,
37162 .get_parent = socfpga_clk_get_parent,
37163 .set_parent = socfpga_clk_set_parent,
37164diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
37165index 506fd23..01a593f 100644
37166--- a/drivers/cpufreq/acpi-cpufreq.c
37167+++ b/drivers/cpufreq/acpi-cpufreq.c
37168@@ -172,7 +172,7 @@ static ssize_t show_global_boost(struct kobject *kobj,
37169 return sprintf(buf, "%u\n", boost_enabled);
37170 }
37171
37172-static struct global_attr global_boost = __ATTR(boost, 0644,
37173+static global_attr_no_const global_boost = __ATTR(boost, 0644,
37174 show_global_boost,
37175 store_global_boost);
37176
37177@@ -721,8 +721,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
37178 data->acpi_data = per_cpu_ptr(acpi_perf_data, cpu);
37179 per_cpu(acfreq_data, cpu) = data;
37180
37181- if (cpu_has(c, X86_FEATURE_CONSTANT_TSC))
37182- acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
37183+ if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) {
37184+ pax_open_kernel();
37185+ *(u8 *)&acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
37186+ pax_close_kernel();
37187+ }
37188
37189 result = acpi_processor_register_performance(data->acpi_data, cpu);
37190 if (result)
37191@@ -850,7 +853,9 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
37192 policy->cur = acpi_cpufreq_guess_freq(data, policy->cpu);
37193 break;
37194 case ACPI_ADR_SPACE_FIXED_HARDWARE:
37195- acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
37196+ pax_open_kernel();
37197+ *(void **)&acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
37198+ pax_close_kernel();
37199 policy->cur = get_cur_freq_on_cpu(cpu);
37200 break;
37201 default:
37202diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
37203index 04548f7..457a342 100644
37204--- a/drivers/cpufreq/cpufreq.c
37205+++ b/drivers/cpufreq/cpufreq.c
37206@@ -2069,7 +2069,7 @@ static int cpufreq_cpu_callback(struct notifier_block *nfb,
37207 return NOTIFY_OK;
37208 }
37209
37210-static struct notifier_block __refdata cpufreq_cpu_notifier = {
37211+static struct notifier_block cpufreq_cpu_notifier = {
37212 .notifier_call = cpufreq_cpu_callback,
37213 };
37214
37215@@ -2101,8 +2101,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
37216
37217 pr_debug("trying to register driver %s\n", driver_data->name);
37218
37219- if (driver_data->setpolicy)
37220- driver_data->flags |= CPUFREQ_CONST_LOOPS;
37221+ if (driver_data->setpolicy) {
37222+ pax_open_kernel();
37223+ *(u8 *)&driver_data->flags |= CPUFREQ_CONST_LOOPS;
37224+ pax_close_kernel();
37225+ }
37226
37227 write_lock_irqsave(&cpufreq_driver_lock, flags);
37228 if (cpufreq_driver) {
37229diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
37230index 0806c31..6a73276 100644
37231--- a/drivers/cpufreq/cpufreq_governor.c
37232+++ b/drivers/cpufreq/cpufreq_governor.c
37233@@ -187,7 +187,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
37234 struct dbs_data *dbs_data;
37235 struct od_cpu_dbs_info_s *od_dbs_info = NULL;
37236 struct cs_cpu_dbs_info_s *cs_dbs_info = NULL;
37237- struct od_ops *od_ops = NULL;
37238+ const struct od_ops *od_ops = NULL;
37239 struct od_dbs_tuners *od_tuners = NULL;
37240 struct cs_dbs_tuners *cs_tuners = NULL;
37241 struct cpu_dbs_common_info *cpu_cdbs;
37242@@ -253,7 +253,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
37243
37244 if ((cdata->governor == GOV_CONSERVATIVE) &&
37245 (!policy->governor->initialized)) {
37246- struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
37247+ const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
37248
37249 cpufreq_register_notifier(cs_ops->notifier_block,
37250 CPUFREQ_TRANSITION_NOTIFIER);
37251@@ -273,7 +273,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
37252
37253 if ((dbs_data->cdata->governor == GOV_CONSERVATIVE) &&
37254 (policy->governor->initialized == 1)) {
37255- struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
37256+ const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
37257
37258 cpufreq_unregister_notifier(cs_ops->notifier_block,
37259 CPUFREQ_TRANSITION_NOTIFIER);
37260diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
37261index 88cd39f..87f0393 100644
37262--- a/drivers/cpufreq/cpufreq_governor.h
37263+++ b/drivers/cpufreq/cpufreq_governor.h
37264@@ -202,7 +202,7 @@ struct common_dbs_data {
37265 void (*exit)(struct dbs_data *dbs_data);
37266
37267 /* Governor specific ops, see below */
37268- void *gov_ops;
37269+ const void *gov_ops;
37270 };
37271
37272 /* Governor Per policy data */
37273@@ -222,7 +222,7 @@ struct od_ops {
37274 unsigned int (*powersave_bias_target)(struct cpufreq_policy *policy,
37275 unsigned int freq_next, unsigned int relation);
37276 void (*freq_increase)(struct cpufreq_policy *policy, unsigned int freq);
37277-};
37278+} __no_const;
37279
37280 struct cs_ops {
37281 struct notifier_block *notifier_block;
37282diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c
37283index 32f26f6..feb657b 100644
37284--- a/drivers/cpufreq/cpufreq_ondemand.c
37285+++ b/drivers/cpufreq/cpufreq_ondemand.c
37286@@ -522,7 +522,7 @@ static void od_exit(struct dbs_data *dbs_data)
37287
37288 define_get_cpu_dbs_routines(od_cpu_dbs_info);
37289
37290-static struct od_ops od_ops = {
37291+static struct od_ops od_ops __read_only = {
37292 .powersave_bias_init_cpu = ondemand_powersave_bias_init_cpu,
37293 .powersave_bias_target = generic_powersave_bias_target,
37294 .freq_increase = dbs_freq_increase,
37295@@ -577,14 +577,18 @@ void od_register_powersave_bias_handler(unsigned int (*f)
37296 (struct cpufreq_policy *, unsigned int, unsigned int),
37297 unsigned int powersave_bias)
37298 {
37299- od_ops.powersave_bias_target = f;
37300+ pax_open_kernel();
37301+ *(void **)&od_ops.powersave_bias_target = f;
37302+ pax_close_kernel();
37303 od_set_powersave_bias(powersave_bias);
37304 }
37305 EXPORT_SYMBOL_GPL(od_register_powersave_bias_handler);
37306
37307 void od_unregister_powersave_bias_handler(void)
37308 {
37309- od_ops.powersave_bias_target = generic_powersave_bias_target;
37310+ pax_open_kernel();
37311+ *(void **)&od_ops.powersave_bias_target = generic_powersave_bias_target;
37312+ pax_close_kernel();
37313 od_set_powersave_bias(0);
37314 }
37315 EXPORT_SYMBOL_GPL(od_unregister_powersave_bias_handler);
37316diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c
37317index 4cf0d28..5830372 100644
37318--- a/drivers/cpufreq/cpufreq_stats.c
37319+++ b/drivers/cpufreq/cpufreq_stats.c
37320@@ -352,7 +352,7 @@ static int cpufreq_stat_cpu_callback(struct notifier_block *nfb,
37321 }
37322
37323 /* priority=1 so this will get called before cpufreq_remove_dev */
37324-static struct notifier_block cpufreq_stat_cpu_notifier __refdata = {
37325+static struct notifier_block cpufreq_stat_cpu_notifier = {
37326 .notifier_call = cpufreq_stat_cpu_callback,
37327 .priority = 1,
37328 };
37329diff --git a/drivers/cpufreq/p4-clockmod.c b/drivers/cpufreq/p4-clockmod.c
37330index 2f0a2a6..93d728e 100644
37331--- a/drivers/cpufreq/p4-clockmod.c
37332+++ b/drivers/cpufreq/p4-clockmod.c
37333@@ -160,10 +160,14 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
37334 case 0x0F: /* Core Duo */
37335 case 0x16: /* Celeron Core */
37336 case 0x1C: /* Atom */
37337- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
37338+ pax_open_kernel();
37339+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
37340+ pax_close_kernel();
37341 return speedstep_get_frequency(SPEEDSTEP_CPU_PCORE);
37342 case 0x0D: /* Pentium M (Dothan) */
37343- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
37344+ pax_open_kernel();
37345+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
37346+ pax_close_kernel();
37347 /* fall through */
37348 case 0x09: /* Pentium M (Banias) */
37349 return speedstep_get_frequency(SPEEDSTEP_CPU_PM);
37350@@ -175,7 +179,9 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
37351
37352 /* on P-4s, the TSC runs with constant frequency independent whether
37353 * throttling is active or not. */
37354- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
37355+ pax_open_kernel();
37356+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
37357+ pax_close_kernel();
37358
37359 if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4M) {
37360 printk(KERN_WARNING PFX "Warning: Pentium 4-M detected. "
37361diff --git a/drivers/cpufreq/sparc-us3-cpufreq.c b/drivers/cpufreq/sparc-us3-cpufreq.c
37362index ac76b48..2445bc6 100644
37363--- a/drivers/cpufreq/sparc-us3-cpufreq.c
37364+++ b/drivers/cpufreq/sparc-us3-cpufreq.c
37365@@ -18,14 +18,12 @@
37366 #include <asm/head.h>
37367 #include <asm/timer.h>
37368
37369-static struct cpufreq_driver *cpufreq_us3_driver;
37370-
37371 struct us3_freq_percpu_info {
37372 struct cpufreq_frequency_table table[4];
37373 };
37374
37375 /* Indexed by cpu number. */
37376-static struct us3_freq_percpu_info *us3_freq_table;
37377+static struct us3_freq_percpu_info us3_freq_table[NR_CPUS];
37378
37379 /* UltraSPARC-III has three dividers: 1, 2, and 32. These are controlled
37380 * in the Safari config register.
37381@@ -186,12 +184,25 @@ static int __init us3_freq_cpu_init(struct cpufreq_policy *policy)
37382
37383 static int us3_freq_cpu_exit(struct cpufreq_policy *policy)
37384 {
37385- if (cpufreq_us3_driver)
37386- us3_set_cpu_divider_index(policy, 0);
37387+ us3_set_cpu_divider_index(policy->cpu, 0);
37388
37389 return 0;
37390 }
37391
37392+static int __init us3_freq_init(void);
37393+static void __exit us3_freq_exit(void);
37394+
37395+static struct cpufreq_driver cpufreq_us3_driver = {
37396+ .init = us3_freq_cpu_init,
37397+ .verify = us3_freq_verify,
37398+ .target = us3_freq_target,
37399+ .get = us3_freq_get,
37400+ .exit = us3_freq_cpu_exit,
37401+ .owner = THIS_MODULE,
37402+ .name = "UltraSPARC-III",
37403+
37404+};
37405+
37406 static int __init us3_freq_init(void)
37407 {
37408 unsigned long manuf, impl, ver;
37409@@ -208,55 +219,15 @@ static int __init us3_freq_init(void)
37410 (impl == CHEETAH_IMPL ||
37411 impl == CHEETAH_PLUS_IMPL ||
37412 impl == JAGUAR_IMPL ||
37413- impl == PANTHER_IMPL)) {
37414- struct cpufreq_driver *driver;
37415-
37416- ret = -ENOMEM;
37417- driver = kzalloc(sizeof(*driver), GFP_KERNEL);
37418- if (!driver)
37419- goto err_out;
37420-
37421- us3_freq_table = kzalloc((NR_CPUS * sizeof(*us3_freq_table)),
37422- GFP_KERNEL);
37423- if (!us3_freq_table)
37424- goto err_out;
37425-
37426- driver->init = us3_freq_cpu_init;
37427- driver->verify = us3_freq_verify;
37428- driver->target = us3_freq_target;
37429- driver->get = us3_freq_get;
37430- driver->exit = us3_freq_cpu_exit;
37431- strcpy(driver->name, "UltraSPARC-III");
37432-
37433- cpufreq_us3_driver = driver;
37434- ret = cpufreq_register_driver(driver);
37435- if (ret)
37436- goto err_out;
37437-
37438- return 0;
37439-
37440-err_out:
37441- if (driver) {
37442- kfree(driver);
37443- cpufreq_us3_driver = NULL;
37444- }
37445- kfree(us3_freq_table);
37446- us3_freq_table = NULL;
37447- return ret;
37448- }
37449+ impl == PANTHER_IMPL))
37450+ return cpufreq_register_driver(&cpufreq_us3_driver);
37451
37452 return -ENODEV;
37453 }
37454
37455 static void __exit us3_freq_exit(void)
37456 {
37457- if (cpufreq_us3_driver) {
37458- cpufreq_unregister_driver(cpufreq_us3_driver);
37459- kfree(cpufreq_us3_driver);
37460- cpufreq_us3_driver = NULL;
37461- kfree(us3_freq_table);
37462- us3_freq_table = NULL;
37463- }
37464+ cpufreq_unregister_driver(&cpufreq_us3_driver);
37465 }
37466
37467 MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
37468diff --git a/drivers/cpufreq/speedstep-centrino.c b/drivers/cpufreq/speedstep-centrino.c
37469index f897d51..15da295 100644
37470--- a/drivers/cpufreq/speedstep-centrino.c
37471+++ b/drivers/cpufreq/speedstep-centrino.c
37472@@ -353,8 +353,11 @@ static int centrino_cpu_init(struct cpufreq_policy *policy)
37473 !cpu_has(cpu, X86_FEATURE_EST))
37474 return -ENODEV;
37475
37476- if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC))
37477- centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
37478+ if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC)) {
37479+ pax_open_kernel();
37480+ *(u8 *)&centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
37481+ pax_close_kernel();
37482+ }
37483
37484 if (policy->cpu != 0)
37485 return -ENODEV;
37486diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c
37487index d75040d..4738ca5 100644
37488--- a/drivers/cpuidle/cpuidle.c
37489+++ b/drivers/cpuidle/cpuidle.c
37490@@ -252,7 +252,7 @@ static int poll_idle(struct cpuidle_device *dev,
37491
37492 static void poll_idle_init(struct cpuidle_driver *drv)
37493 {
37494- struct cpuidle_state *state = &drv->states[0];
37495+ cpuidle_state_no_const *state = &drv->states[0];
37496
37497 snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
37498 snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
37499diff --git a/drivers/cpuidle/governor.c b/drivers/cpuidle/governor.c
37500index ea2f8e7..70ac501 100644
37501--- a/drivers/cpuidle/governor.c
37502+++ b/drivers/cpuidle/governor.c
37503@@ -87,7 +87,7 @@ int cpuidle_register_governor(struct cpuidle_governor *gov)
37504 mutex_lock(&cpuidle_lock);
37505 if (__cpuidle_find_governor(gov->name) == NULL) {
37506 ret = 0;
37507- list_add_tail(&gov->governor_list, &cpuidle_governors);
37508+ pax_list_add_tail((struct list_head *)&gov->governor_list, &cpuidle_governors);
37509 if (!cpuidle_curr_governor ||
37510 cpuidle_curr_governor->rating < gov->rating)
37511 cpuidle_switch_governor(gov);
37512@@ -135,7 +135,7 @@ void cpuidle_unregister_governor(struct cpuidle_governor *gov)
37513 new_gov = cpuidle_replace_governor(gov->rating);
37514 cpuidle_switch_governor(new_gov);
37515 }
37516- list_del(&gov->governor_list);
37517+ pax_list_del((struct list_head *)&gov->governor_list);
37518 mutex_unlock(&cpuidle_lock);
37519 }
37520
37521diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
37522index 8739cc0..dc859d0 100644
37523--- a/drivers/cpuidle/sysfs.c
37524+++ b/drivers/cpuidle/sysfs.c
37525@@ -134,7 +134,7 @@ static struct attribute *cpuidle_switch_attrs[] = {
37526 NULL
37527 };
37528
37529-static struct attribute_group cpuidle_attr_group = {
37530+static attribute_group_no_const cpuidle_attr_group = {
37531 .attrs = cpuidle_default_attrs,
37532 .name = "cpuidle",
37533 };
37534diff --git a/drivers/crypto/hifn_795x.c b/drivers/crypto/hifn_795x.c
37535index 12fea3e..1e28f47 100644
37536--- a/drivers/crypto/hifn_795x.c
37537+++ b/drivers/crypto/hifn_795x.c
37538@@ -51,7 +51,7 @@ module_param_string(hifn_pll_ref, hifn_pll_ref, sizeof(hifn_pll_ref), 0444);
37539 MODULE_PARM_DESC(hifn_pll_ref,
37540 "PLL reference clock (pci[freq] or ext[freq], default ext)");
37541
37542-static atomic_t hifn_dev_number;
37543+static atomic_unchecked_t hifn_dev_number;
37544
37545 #define ACRYPTO_OP_DECRYPT 0
37546 #define ACRYPTO_OP_ENCRYPT 1
37547@@ -2577,7 +2577,7 @@ static int hifn_probe(struct pci_dev *pdev, const struct pci_device_id *id)
37548 goto err_out_disable_pci_device;
37549
37550 snprintf(name, sizeof(name), "hifn%d",
37551- atomic_inc_return(&hifn_dev_number)-1);
37552+ atomic_inc_return_unchecked(&hifn_dev_number)-1);
37553
37554 err = pci_request_regions(pdev, name);
37555 if (err)
37556diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
37557index c99c00d..990a4b2 100644
37558--- a/drivers/devfreq/devfreq.c
37559+++ b/drivers/devfreq/devfreq.c
37560@@ -607,7 +607,7 @@ int devfreq_add_governor(struct devfreq_governor *governor)
37561 goto err_out;
37562 }
37563
37564- list_add(&governor->node, &devfreq_governor_list);
37565+ pax_list_add((struct list_head *)&governor->node, &devfreq_governor_list);
37566
37567 list_for_each_entry(devfreq, &devfreq_list, node) {
37568 int ret = 0;
37569@@ -695,7 +695,7 @@ int devfreq_remove_governor(struct devfreq_governor *governor)
37570 }
37571 }
37572
37573- list_del(&governor->node);
37574+ pax_list_del((struct list_head *)&governor->node);
37575 err_out:
37576 mutex_unlock(&devfreq_list_lock);
37577
37578diff --git a/drivers/dma/sh/shdmac.c b/drivers/dma/sh/shdmac.c
37579index 1069e88..dfcd642 100644
37580--- a/drivers/dma/sh/shdmac.c
37581+++ b/drivers/dma/sh/shdmac.c
37582@@ -511,7 +511,7 @@ static int sh_dmae_nmi_handler(struct notifier_block *self,
37583 return ret;
37584 }
37585
37586-static struct notifier_block sh_dmae_nmi_notifier __read_mostly = {
37587+static struct notifier_block sh_dmae_nmi_notifier = {
37588 .notifier_call = sh_dmae_nmi_handler,
37589
37590 /* Run before NMI debug handler and KGDB */
37591diff --git a/drivers/edac/edac_device.c b/drivers/edac/edac_device.c
37592index 211021d..201d47f 100644
37593--- a/drivers/edac/edac_device.c
37594+++ b/drivers/edac/edac_device.c
37595@@ -474,9 +474,9 @@ void edac_device_reset_delay_period(struct edac_device_ctl_info *edac_dev,
37596 */
37597 int edac_device_alloc_index(void)
37598 {
37599- static atomic_t device_indexes = ATOMIC_INIT(0);
37600+ static atomic_unchecked_t device_indexes = ATOMIC_INIT(0);
37601
37602- return atomic_inc_return(&device_indexes) - 1;
37603+ return atomic_inc_return_unchecked(&device_indexes) - 1;
37604 }
37605 EXPORT_SYMBOL_GPL(edac_device_alloc_index);
37606
37607diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
37608index 9f7e0e60..348c875 100644
37609--- a/drivers/edac/edac_mc_sysfs.c
37610+++ b/drivers/edac/edac_mc_sysfs.c
37611@@ -150,7 +150,7 @@ static const char * const edac_caps[] = {
37612 struct dev_ch_attribute {
37613 struct device_attribute attr;
37614 int channel;
37615-};
37616+} __do_const;
37617
37618 #define DEVICE_CHANNEL(_name, _mode, _show, _store, _var) \
37619 struct dev_ch_attribute dev_attr_legacy_##_name = \
37620@@ -1007,14 +1007,16 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
37621 }
37622
37623 if (mci->set_sdram_scrub_rate || mci->get_sdram_scrub_rate) {
37624+ pax_open_kernel();
37625 if (mci->get_sdram_scrub_rate) {
37626- dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
37627- dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
37628+ *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
37629+ *(void **)&dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
37630 }
37631 if (mci->set_sdram_scrub_rate) {
37632- dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
37633- dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
37634+ *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
37635+ *(void **)&dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
37636 }
37637+ pax_close_kernel();
37638 err = device_create_file(&mci->dev,
37639 &dev_attr_sdram_scrub_rate);
37640 if (err) {
37641diff --git a/drivers/edac/edac_pci.c b/drivers/edac/edac_pci.c
37642index dd370f9..0281629 100644
37643--- a/drivers/edac/edac_pci.c
37644+++ b/drivers/edac/edac_pci.c
37645@@ -29,7 +29,7 @@
37646
37647 static DEFINE_MUTEX(edac_pci_ctls_mutex);
37648 static LIST_HEAD(edac_pci_list);
37649-static atomic_t pci_indexes = ATOMIC_INIT(0);
37650+static atomic_unchecked_t pci_indexes = ATOMIC_INIT(0);
37651
37652 /*
37653 * edac_pci_alloc_ctl_info
37654@@ -315,7 +315,7 @@ EXPORT_SYMBOL_GPL(edac_pci_reset_delay_period);
37655 */
37656 int edac_pci_alloc_index(void)
37657 {
37658- return atomic_inc_return(&pci_indexes) - 1;
37659+ return atomic_inc_return_unchecked(&pci_indexes) - 1;
37660 }
37661 EXPORT_SYMBOL_GPL(edac_pci_alloc_index);
37662
37663diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
37664index e8658e4..22746d6 100644
37665--- a/drivers/edac/edac_pci_sysfs.c
37666+++ b/drivers/edac/edac_pci_sysfs.c
37667@@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
37668 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
37669 static int edac_pci_poll_msec = 1000; /* one second workq period */
37670
37671-static atomic_t pci_parity_count = ATOMIC_INIT(0);
37672-static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
37673+static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
37674+static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
37675
37676 static struct kobject *edac_pci_top_main_kobj;
37677 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
37678@@ -235,7 +235,7 @@ struct edac_pci_dev_attribute {
37679 void *value;
37680 ssize_t(*show) (void *, char *);
37681 ssize_t(*store) (void *, const char *, size_t);
37682-};
37683+} __do_const;
37684
37685 /* Set of show/store abstract level functions for PCI Parity object */
37686 static ssize_t edac_pci_dev_show(struct kobject *kobj, struct attribute *attr,
37687@@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
37688 edac_printk(KERN_CRIT, EDAC_PCI,
37689 "Signaled System Error on %s\n",
37690 pci_name(dev));
37691- atomic_inc(&pci_nonparity_count);
37692+ atomic_inc_unchecked(&pci_nonparity_count);
37693 }
37694
37695 if (status & (PCI_STATUS_PARITY)) {
37696@@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
37697 "Master Data Parity Error on %s\n",
37698 pci_name(dev));
37699
37700- atomic_inc(&pci_parity_count);
37701+ atomic_inc_unchecked(&pci_parity_count);
37702 }
37703
37704 if (status & (PCI_STATUS_DETECTED_PARITY)) {
37705@@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
37706 "Detected Parity Error on %s\n",
37707 pci_name(dev));
37708
37709- atomic_inc(&pci_parity_count);
37710+ atomic_inc_unchecked(&pci_parity_count);
37711 }
37712 }
37713
37714@@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
37715 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
37716 "Signaled System Error on %s\n",
37717 pci_name(dev));
37718- atomic_inc(&pci_nonparity_count);
37719+ atomic_inc_unchecked(&pci_nonparity_count);
37720 }
37721
37722 if (status & (PCI_STATUS_PARITY)) {
37723@@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
37724 "Master Data Parity Error on "
37725 "%s\n", pci_name(dev));
37726
37727- atomic_inc(&pci_parity_count);
37728+ atomic_inc_unchecked(&pci_parity_count);
37729 }
37730
37731 if (status & (PCI_STATUS_DETECTED_PARITY)) {
37732@@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
37733 "Detected Parity Error on %s\n",
37734 pci_name(dev));
37735
37736- atomic_inc(&pci_parity_count);
37737+ atomic_inc_unchecked(&pci_parity_count);
37738 }
37739 }
37740 }
37741@@ -672,7 +672,7 @@ void edac_pci_do_parity_check(void)
37742 if (!check_pci_errors)
37743 return;
37744
37745- before_count = atomic_read(&pci_parity_count);
37746+ before_count = atomic_read_unchecked(&pci_parity_count);
37747
37748 /* scan all PCI devices looking for a Parity Error on devices and
37749 * bridges.
37750@@ -684,7 +684,7 @@ void edac_pci_do_parity_check(void)
37751 /* Only if operator has selected panic on PCI Error */
37752 if (edac_pci_get_panic_on_pe()) {
37753 /* If the count is different 'after' from 'before' */
37754- if (before_count != atomic_read(&pci_parity_count))
37755+ if (before_count != atomic_read_unchecked(&pci_parity_count))
37756 panic("EDAC: PCI Parity Error");
37757 }
37758 }
37759diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
37760index 51b7e3a..aa8a3e8 100644
37761--- a/drivers/edac/mce_amd.h
37762+++ b/drivers/edac/mce_amd.h
37763@@ -77,7 +77,7 @@ struct amd_decoder_ops {
37764 bool (*mc0_mce)(u16, u8);
37765 bool (*mc1_mce)(u16, u8);
37766 bool (*mc2_mce)(u16, u8);
37767-};
37768+} __no_const;
37769
37770 void amd_report_gart_errors(bool);
37771 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
37772diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
37773index 57ea7f4..af06b76 100644
37774--- a/drivers/firewire/core-card.c
37775+++ b/drivers/firewire/core-card.c
37776@@ -528,9 +528,9 @@ void fw_card_initialize(struct fw_card *card,
37777 const struct fw_card_driver *driver,
37778 struct device *device)
37779 {
37780- static atomic_t index = ATOMIC_INIT(-1);
37781+ static atomic_unchecked_t index = ATOMIC_INIT(-1);
37782
37783- card->index = atomic_inc_return(&index);
37784+ card->index = atomic_inc_return_unchecked(&index);
37785 card->driver = driver;
37786 card->device = device;
37787 card->current_tlabel = 0;
37788@@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
37789
37790 void fw_core_remove_card(struct fw_card *card)
37791 {
37792- struct fw_card_driver dummy_driver = dummy_driver_template;
37793+ fw_card_driver_no_const dummy_driver = dummy_driver_template;
37794
37795 card->driver->update_phy_reg(card, 4,
37796 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
37797diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
37798index de4aa40..49ab1f2 100644
37799--- a/drivers/firewire/core-device.c
37800+++ b/drivers/firewire/core-device.c
37801@@ -253,7 +253,7 @@ EXPORT_SYMBOL(fw_device_enable_phys_dma);
37802 struct config_rom_attribute {
37803 struct device_attribute attr;
37804 u32 key;
37805-};
37806+} __do_const;
37807
37808 static ssize_t show_immediate(struct device *dev,
37809 struct device_attribute *dattr, char *buf)
37810diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
37811index e5af0e3..d318058 100644
37812--- a/drivers/firewire/core-transaction.c
37813+++ b/drivers/firewire/core-transaction.c
37814@@ -38,6 +38,7 @@
37815 #include <linux/timer.h>
37816 #include <linux/types.h>
37817 #include <linux/workqueue.h>
37818+#include <linux/sched.h>
37819
37820 #include <asm/byteorder.h>
37821
37822diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
37823index 515a42c..5ecf3ba 100644
37824--- a/drivers/firewire/core.h
37825+++ b/drivers/firewire/core.h
37826@@ -111,6 +111,7 @@ struct fw_card_driver {
37827
37828 int (*stop_iso)(struct fw_iso_context *ctx);
37829 };
37830+typedef struct fw_card_driver __no_const fw_card_driver_no_const;
37831
37832 void fw_card_initialize(struct fw_card *card,
37833 const struct fw_card_driver *driver, struct device *device);
37834diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
37835index 94a58a0..f5eba42 100644
37836--- a/drivers/firmware/dmi-id.c
37837+++ b/drivers/firmware/dmi-id.c
37838@@ -16,7 +16,7 @@
37839 struct dmi_device_attribute{
37840 struct device_attribute dev_attr;
37841 int field;
37842-};
37843+} __do_const;
37844 #define to_dmi_dev_attr(_dev_attr) \
37845 container_of(_dev_attr, struct dmi_device_attribute, dev_attr)
37846
37847diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
37848index fa0affb..aa448eb 100644
37849--- a/drivers/firmware/dmi_scan.c
37850+++ b/drivers/firmware/dmi_scan.c
37851@@ -791,7 +791,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
37852 if (buf == NULL)
37853 return -1;
37854
37855- dmi_table(buf, dmi_len, dmi_num, decode, private_data);
37856+ dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
37857
37858 iounmap(buf);
37859 return 0;
37860diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
37861index 5145fa3..0d3babd 100644
37862--- a/drivers/firmware/efi/efi.c
37863+++ b/drivers/firmware/efi/efi.c
37864@@ -65,14 +65,16 @@ static struct attribute_group efi_subsys_attr_group = {
37865 };
37866
37867 static struct efivars generic_efivars;
37868-static struct efivar_operations generic_ops;
37869+static efivar_operations_no_const generic_ops __read_only;
37870
37871 static int generic_ops_register(void)
37872 {
37873- generic_ops.get_variable = efi.get_variable;
37874- generic_ops.set_variable = efi.set_variable;
37875- generic_ops.get_next_variable = efi.get_next_variable;
37876- generic_ops.query_variable_store = efi_query_variable_store;
37877+ pax_open_kernel();
37878+ *(void **)&generic_ops.get_variable = efi.get_variable;
37879+ *(void **)&generic_ops.set_variable = efi.set_variable;
37880+ *(void **)&generic_ops.get_next_variable = efi.get_next_variable;
37881+ *(void **)&generic_ops.query_variable_store = efi_query_variable_store;
37882+ pax_close_kernel();
37883
37884 return efivars_register(&generic_efivars, &generic_ops, efi_kobj);
37885 }
37886diff --git a/drivers/firmware/efi/efivars.c b/drivers/firmware/efi/efivars.c
37887index 8a7432a..28fb839 100644
37888--- a/drivers/firmware/efi/efivars.c
37889+++ b/drivers/firmware/efi/efivars.c
37890@@ -452,7 +452,7 @@ efivar_create_sysfs_entry(struct efivar_entry *new_var)
37891 static int
37892 create_efivars_bin_attributes(void)
37893 {
37894- struct bin_attribute *attr;
37895+ bin_attribute_no_const *attr;
37896 int error;
37897
37898 /* new_var */
37899diff --git a/drivers/firmware/google/memconsole.c b/drivers/firmware/google/memconsole.c
37900index 2a90ba6..07f3733 100644
37901--- a/drivers/firmware/google/memconsole.c
37902+++ b/drivers/firmware/google/memconsole.c
37903@@ -147,7 +147,9 @@ static int __init memconsole_init(void)
37904 if (!found_memconsole())
37905 return -ENODEV;
37906
37907- memconsole_bin_attr.size = memconsole_length;
37908+ pax_open_kernel();
37909+ *(size_t *)&memconsole_bin_attr.size = memconsole_length;
37910+ pax_close_kernel();
37911
37912 ret = sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr);
37913
37914diff --git a/drivers/gpio/gpio-ich.c b/drivers/gpio/gpio-ich.c
37915index 814addb..0937d7f 100644
37916--- a/drivers/gpio/gpio-ich.c
37917+++ b/drivers/gpio/gpio-ich.c
37918@@ -71,7 +71,7 @@ struct ichx_desc {
37919 /* Some chipsets have quirks, let these use their own request/get */
37920 int (*request)(struct gpio_chip *chip, unsigned offset);
37921 int (*get)(struct gpio_chip *chip, unsigned offset);
37922-};
37923+} __do_const;
37924
37925 static struct {
37926 spinlock_t lock;
37927diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
37928index 9902732..64b62dd 100644
37929--- a/drivers/gpio/gpio-vr41xx.c
37930+++ b/drivers/gpio/gpio-vr41xx.c
37931@@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
37932 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
37933 maskl, pendl, maskh, pendh);
37934
37935- atomic_inc(&irq_err_count);
37936+ atomic_inc_unchecked(&irq_err_count);
37937
37938 return -EINVAL;
37939 }
37940diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
37941index c722c3b..2ec6040 100644
37942--- a/drivers/gpu/drm/drm_crtc_helper.c
37943+++ b/drivers/gpu/drm/drm_crtc_helper.c
37944@@ -328,7 +328,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
37945 struct drm_crtc *tmp;
37946 int crtc_mask = 1;
37947
37948- WARN(!crtc, "checking null crtc?\n");
37949+ BUG_ON(!crtc);
37950
37951 dev = crtc->dev;
37952
37953diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
37954index fe58d08..07bc38e 100644
37955--- a/drivers/gpu/drm/drm_drv.c
37956+++ b/drivers/gpu/drm/drm_drv.c
37957@@ -186,7 +186,7 @@ static void drm_legacy_dev_reinit(struct drm_device *dev)
37958 atomic_set(&dev->vma_count, 0);
37959
37960 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
37961- atomic_set(&dev->counts[i], 0);
37962+ atomic_set_unchecked(&dev->counts[i], 0);
37963
37964 dev->sigdata.lock = NULL;
37965
37966@@ -302,7 +302,7 @@ module_exit(drm_core_exit);
37967 /**
37968 * Copy and IOCTL return string to user space
37969 */
37970-static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
37971+static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
37972 {
37973 int len;
37974
37975@@ -372,7 +372,7 @@ long drm_ioctl(struct file *filp,
37976 struct drm_file *file_priv = filp->private_data;
37977 struct drm_device *dev;
37978 const struct drm_ioctl_desc *ioctl = NULL;
37979- drm_ioctl_t *func;
37980+ drm_ioctl_no_const_t func;
37981 unsigned int nr = DRM_IOCTL_NR(cmd);
37982 int retcode = -EINVAL;
37983 char stack_kdata[128];
37984@@ -385,7 +385,7 @@ long drm_ioctl(struct file *filp,
37985 return -ENODEV;
37986
37987 atomic_inc(&dev->ioctl_count);
37988- atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
37989+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
37990 ++file_priv->ioctl_count;
37991
37992 if ((nr >= DRM_CORE_IOCTL_COUNT) &&
37993diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
37994index 3f84277..c627c54 100644
37995--- a/drivers/gpu/drm/drm_fops.c
37996+++ b/drivers/gpu/drm/drm_fops.c
37997@@ -97,7 +97,7 @@ int drm_open(struct inode *inode, struct file *filp)
37998 if (drm_device_is_unplugged(dev))
37999 return -ENODEV;
38000
38001- if (!dev->open_count++)
38002+ if (local_inc_return(&dev->open_count) == 1)
38003 need_setup = 1;
38004 mutex_lock(&dev->struct_mutex);
38005 old_imapping = inode->i_mapping;
38006@@ -113,7 +113,7 @@ int drm_open(struct inode *inode, struct file *filp)
38007 retcode = drm_open_helper(inode, filp, dev);
38008 if (retcode)
38009 goto err_undo;
38010- atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
38011+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
38012 if (need_setup) {
38013 retcode = drm_setup(dev);
38014 if (retcode)
38015@@ -128,7 +128,7 @@ err_undo:
38016 iput(container_of(dev->dev_mapping, struct inode, i_data));
38017 dev->dev_mapping = old_mapping;
38018 mutex_unlock(&dev->struct_mutex);
38019- dev->open_count--;
38020+ local_dec(&dev->open_count);
38021 return retcode;
38022 }
38023 EXPORT_SYMBOL(drm_open);
38024@@ -405,7 +405,7 @@ int drm_release(struct inode *inode, struct file *filp)
38025
38026 mutex_lock(&drm_global_mutex);
38027
38028- DRM_DEBUG("open_count = %d\n", dev->open_count);
38029+ DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
38030
38031 if (dev->driver->preclose)
38032 dev->driver->preclose(dev, file_priv);
38033@@ -414,10 +414,10 @@ int drm_release(struct inode *inode, struct file *filp)
38034 * Begin inline drm_release
38035 */
38036
38037- DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
38038+ DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
38039 task_pid_nr(current),
38040 (long)old_encode_dev(file_priv->minor->device),
38041- dev->open_count);
38042+ local_read(&dev->open_count));
38043
38044 /* Release any auth tokens that might point to this file_priv,
38045 (do that under the drm_global_mutex) */
38046@@ -516,8 +516,8 @@ int drm_release(struct inode *inode, struct file *filp)
38047 * End inline drm_release
38048 */
38049
38050- atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
38051- if (!--dev->open_count) {
38052+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
38053+ if (local_dec_and_test(&dev->open_count)) {
38054 if (atomic_read(&dev->ioctl_count)) {
38055 DRM_ERROR("Device busy: %d\n",
38056 atomic_read(&dev->ioctl_count));
38057diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
38058index f731116..629842c 100644
38059--- a/drivers/gpu/drm/drm_global.c
38060+++ b/drivers/gpu/drm/drm_global.c
38061@@ -36,7 +36,7 @@
38062 struct drm_global_item {
38063 struct mutex mutex;
38064 void *object;
38065- int refcount;
38066+ atomic_t refcount;
38067 };
38068
38069 static struct drm_global_item glob[DRM_GLOBAL_NUM];
38070@@ -49,7 +49,7 @@ void drm_global_init(void)
38071 struct drm_global_item *item = &glob[i];
38072 mutex_init(&item->mutex);
38073 item->object = NULL;
38074- item->refcount = 0;
38075+ atomic_set(&item->refcount, 0);
38076 }
38077 }
38078
38079@@ -59,7 +59,7 @@ void drm_global_release(void)
38080 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
38081 struct drm_global_item *item = &glob[i];
38082 BUG_ON(item->object != NULL);
38083- BUG_ON(item->refcount != 0);
38084+ BUG_ON(atomic_read(&item->refcount) != 0);
38085 }
38086 }
38087
38088@@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
38089 void *object;
38090
38091 mutex_lock(&item->mutex);
38092- if (item->refcount == 0) {
38093+ if (atomic_read(&item->refcount) == 0) {
38094 item->object = kzalloc(ref->size, GFP_KERNEL);
38095 if (unlikely(item->object == NULL)) {
38096 ret = -ENOMEM;
38097@@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
38098 goto out_err;
38099
38100 }
38101- ++item->refcount;
38102+ atomic_inc(&item->refcount);
38103 ref->object = item->object;
38104 object = item->object;
38105 mutex_unlock(&item->mutex);
38106@@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
38107 struct drm_global_item *item = &glob[ref->global_type];
38108
38109 mutex_lock(&item->mutex);
38110- BUG_ON(item->refcount == 0);
38111+ BUG_ON(atomic_read(&item->refcount) == 0);
38112 BUG_ON(ref->object != item->object);
38113- if (--item->refcount == 0) {
38114+ if (atomic_dec_and_test(&item->refcount)) {
38115 ref->release(ref);
38116 item->object = NULL;
38117 }
38118diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
38119index 5329832..b503f49 100644
38120--- a/drivers/gpu/drm/drm_info.c
38121+++ b/drivers/gpu/drm/drm_info.c
38122@@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
38123 struct drm_local_map *map;
38124 struct drm_map_list *r_list;
38125
38126- /* Hardcoded from _DRM_FRAME_BUFFER,
38127- _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
38128- _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
38129- const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
38130+ static const char * const types[] = {
38131+ [_DRM_FRAME_BUFFER] = "FB",
38132+ [_DRM_REGISTERS] = "REG",
38133+ [_DRM_SHM] = "SHM",
38134+ [_DRM_AGP] = "AGP",
38135+ [_DRM_SCATTER_GATHER] = "SG",
38136+ [_DRM_CONSISTENT] = "PCI",
38137+ [_DRM_GEM] = "GEM" };
38138 const char *type;
38139 int i;
38140
38141@@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
38142 map = r_list->map;
38143 if (!map)
38144 continue;
38145- if (map->type < 0 || map->type > 5)
38146+ if (map->type >= ARRAY_SIZE(types))
38147 type = "??";
38148 else
38149 type = types[map->type];
38150@@ -257,7 +261,11 @@ int drm_vma_info(struct seq_file *m, void *data)
38151 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
38152 vma->vm_flags & VM_LOCKED ? 'l' : '-',
38153 vma->vm_flags & VM_IO ? 'i' : '-',
38154+#ifdef CONFIG_GRKERNSEC_HIDESYM
38155+ 0);
38156+#else
38157 vma->vm_pgoff);
38158+#endif
38159
38160 #if defined(__i386__)
38161 pgprot = pgprot_val(vma->vm_page_prot);
38162diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
38163index 2f4c434..dd12cd2 100644
38164--- a/drivers/gpu/drm/drm_ioc32.c
38165+++ b/drivers/gpu/drm/drm_ioc32.c
38166@@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
38167 request = compat_alloc_user_space(nbytes);
38168 if (!access_ok(VERIFY_WRITE, request, nbytes))
38169 return -EFAULT;
38170- list = (struct drm_buf_desc *) (request + 1);
38171+ list = (struct drm_buf_desc __user *) (request + 1);
38172
38173 if (__put_user(count, &request->count)
38174 || __put_user(list, &request->list))
38175@@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
38176 request = compat_alloc_user_space(nbytes);
38177 if (!access_ok(VERIFY_WRITE, request, nbytes))
38178 return -EFAULT;
38179- list = (struct drm_buf_pub *) (request + 1);
38180+ list = (struct drm_buf_pub __user *) (request + 1);
38181
38182 if (__put_user(count, &request->count)
38183 || __put_user(list, &request->list))
38184@@ -1016,7 +1016,7 @@ static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
38185 return 0;
38186 }
38187
38188-drm_ioctl_compat_t *drm_compat_ioctls[] = {
38189+drm_ioctl_compat_t drm_compat_ioctls[] = {
38190 [DRM_IOCTL_NR(DRM_IOCTL_VERSION32)] = compat_drm_version,
38191 [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE32)] = compat_drm_getunique,
38192 [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP32)] = compat_drm_getmap,
38193@@ -1062,7 +1062,6 @@ drm_ioctl_compat_t *drm_compat_ioctls[] = {
38194 long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
38195 {
38196 unsigned int nr = DRM_IOCTL_NR(cmd);
38197- drm_ioctl_compat_t *fn;
38198 int ret;
38199
38200 /* Assume that ioctls without an explicit compat routine will just
38201@@ -1072,10 +1071,8 @@ long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
38202 if (nr >= ARRAY_SIZE(drm_compat_ioctls))
38203 return drm_ioctl(filp, cmd, arg);
38204
38205- fn = drm_compat_ioctls[nr];
38206-
38207- if (fn != NULL)
38208- ret = (*fn) (filp, cmd, arg);
38209+ if (drm_compat_ioctls[nr] != NULL)
38210+ ret = (*drm_compat_ioctls[nr]) (filp, cmd, arg);
38211 else
38212 ret = drm_ioctl(filp, cmd, arg);
38213
38214diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
38215index d752c96..fe08455 100644
38216--- a/drivers/gpu/drm/drm_lock.c
38217+++ b/drivers/gpu/drm/drm_lock.c
38218@@ -86,7 +86,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
38219 if (drm_lock_take(&master->lock, lock->context)) {
38220 master->lock.file_priv = file_priv;
38221 master->lock.lock_time = jiffies;
38222- atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
38223+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
38224 break; /* Got lock */
38225 }
38226
38227@@ -157,7 +157,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
38228 return -EINVAL;
38229 }
38230
38231- atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
38232+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
38233
38234 if (drm_lock_free(&master->lock, lock->context)) {
38235 /* FIXME: Should really bail out here. */
38236diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
38237index 39d8645..59e06fa 100644
38238--- a/drivers/gpu/drm/drm_stub.c
38239+++ b/drivers/gpu/drm/drm_stub.c
38240@@ -484,7 +484,7 @@ void drm_unplug_dev(struct drm_device *dev)
38241
38242 drm_device_set_unplugged(dev);
38243
38244- if (dev->open_count == 0) {
38245+ if (local_read(&dev->open_count) == 0) {
38246 drm_put_dev(dev);
38247 }
38248 mutex_unlock(&drm_global_mutex);
38249diff --git a/drivers/gpu/drm/drm_sysfs.c b/drivers/gpu/drm/drm_sysfs.c
38250index 2290b3b..22056a1 100644
38251--- a/drivers/gpu/drm/drm_sysfs.c
38252+++ b/drivers/gpu/drm/drm_sysfs.c
38253@@ -524,7 +524,7 @@ EXPORT_SYMBOL(drm_sysfs_hotplug_event);
38254 int drm_sysfs_device_add(struct drm_minor *minor)
38255 {
38256 int err;
38257- char *minor_str;
38258+ const char *minor_str;
38259
38260 minor->kdev.parent = minor->dev->dev;
38261
38262diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
38263index ab1892eb..d7009ca 100644
38264--- a/drivers/gpu/drm/i810/i810_dma.c
38265+++ b/drivers/gpu/drm/i810/i810_dma.c
38266@@ -944,8 +944,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
38267 dma->buflist[vertex->idx],
38268 vertex->discard, vertex->used);
38269
38270- atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
38271- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
38272+ atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
38273+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
38274 sarea_priv->last_enqueue = dev_priv->counter - 1;
38275 sarea_priv->last_dispatch = (int)hw_status[5];
38276
38277@@ -1105,8 +1105,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
38278 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
38279 mc->last_render);
38280
38281- atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
38282- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
38283+ atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
38284+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
38285 sarea_priv->last_enqueue = dev_priv->counter - 1;
38286 sarea_priv->last_dispatch = (int)hw_status[5];
38287
38288diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
38289index d4d16ed..8fb0b51 100644
38290--- a/drivers/gpu/drm/i810/i810_drv.h
38291+++ b/drivers/gpu/drm/i810/i810_drv.h
38292@@ -108,8 +108,8 @@ typedef struct drm_i810_private {
38293 int page_flipping;
38294
38295 wait_queue_head_t irq_queue;
38296- atomic_t irq_received;
38297- atomic_t irq_emitted;
38298+ atomic_unchecked_t irq_received;
38299+ atomic_unchecked_t irq_emitted;
38300
38301 int front_offset;
38302 } drm_i810_private_t;
38303diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
38304index a6f4cb5..6b2beb2 100644
38305--- a/drivers/gpu/drm/i915/i915_debugfs.c
38306+++ b/drivers/gpu/drm/i915/i915_debugfs.c
38307@@ -624,7 +624,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
38308 I915_READ(GTIMR));
38309 }
38310 seq_printf(m, "Interrupts received: %d\n",
38311- atomic_read(&dev_priv->irq_received));
38312+ atomic_read_unchecked(&dev_priv->irq_received));
38313 for_each_ring(ring, dev_priv, i) {
38314 if (IS_GEN6(dev) || IS_GEN7(dev)) {
38315 seq_printf(m,
38316diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
38317index d5c784d..06e5c36 100644
38318--- a/drivers/gpu/drm/i915/i915_dma.c
38319+++ b/drivers/gpu/drm/i915/i915_dma.c
38320@@ -1263,7 +1263,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
38321 bool can_switch;
38322
38323 spin_lock(&dev->count_lock);
38324- can_switch = (dev->open_count == 0);
38325+ can_switch = (local_read(&dev->open_count) == 0);
38326 spin_unlock(&dev->count_lock);
38327 return can_switch;
38328 }
38329diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
38330index ab0f2c0..53c1bda 100644
38331--- a/drivers/gpu/drm/i915/i915_drv.h
38332+++ b/drivers/gpu/drm/i915/i915_drv.h
38333@@ -1181,7 +1181,7 @@ typedef struct drm_i915_private {
38334 drm_dma_handle_t *status_page_dmah;
38335 struct resource mch_res;
38336
38337- atomic_t irq_received;
38338+ atomic_unchecked_t irq_received;
38339
38340 /* protects the irq masks */
38341 spinlock_t irq_lock;
38342diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
38343index bf34577..3fd2ffa 100644
38344--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
38345+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
38346@@ -768,9 +768,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
38347
38348 static int
38349 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
38350- int count)
38351+ unsigned int count)
38352 {
38353- int i;
38354+ unsigned int i;
38355 int relocs_total = 0;
38356 int relocs_max = INT_MAX / sizeof(struct drm_i915_gem_relocation_entry);
38357
38358diff --git a/drivers/gpu/drm/i915/i915_ioc32.c b/drivers/gpu/drm/i915/i915_ioc32.c
38359index 3c59584..500f2e9 100644
38360--- a/drivers/gpu/drm/i915/i915_ioc32.c
38361+++ b/drivers/gpu/drm/i915/i915_ioc32.c
38362@@ -181,7 +181,7 @@ static int compat_i915_alloc(struct file *file, unsigned int cmd,
38363 (unsigned long)request);
38364 }
38365
38366-static drm_ioctl_compat_t *i915_compat_ioctls[] = {
38367+static drm_ioctl_compat_t i915_compat_ioctls[] = {
38368 [DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
38369 [DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
38370 [DRM_I915_GETPARAM] = compat_i915_getparam,
38371@@ -202,18 +202,15 @@ static drm_ioctl_compat_t *i915_compat_ioctls[] = {
38372 long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
38373 {
38374 unsigned int nr = DRM_IOCTL_NR(cmd);
38375- drm_ioctl_compat_t *fn = NULL;
38376 int ret;
38377
38378 if (nr < DRM_COMMAND_BASE)
38379 return drm_compat_ioctl(filp, cmd, arg);
38380
38381- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls))
38382- fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
38383-
38384- if (fn != NULL)
38385+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls)) {
38386+ drm_ioctl_compat_t fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
38387 ret = (*fn) (filp, cmd, arg);
38388- else
38389+ } else
38390 ret = drm_ioctl(filp, cmd, arg);
38391
38392 return ret;
38393diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
38394index 4b91228..590c643 100644
38395--- a/drivers/gpu/drm/i915/i915_irq.c
38396+++ b/drivers/gpu/drm/i915/i915_irq.c
38397@@ -1085,7 +1085,7 @@ static irqreturn_t valleyview_irq_handler(int irq, void *arg)
38398 int pipe;
38399 u32 pipe_stats[I915_MAX_PIPES];
38400
38401- atomic_inc(&dev_priv->irq_received);
38402+ atomic_inc_unchecked(&dev_priv->irq_received);
38403
38404 while (true) {
38405 iir = I915_READ(VLV_IIR);
38406@@ -1390,7 +1390,7 @@ static irqreturn_t ironlake_irq_handler(int irq, void *arg)
38407 irqreturn_t ret = IRQ_NONE;
38408 bool err_int_reenable = false;
38409
38410- atomic_inc(&dev_priv->irq_received);
38411+ atomic_inc_unchecked(&dev_priv->irq_received);
38412
38413 /* We get interrupts on unclaimed registers, so check for this before we
38414 * do any I915_{READ,WRITE}. */
38415@@ -2146,7 +2146,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
38416 {
38417 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
38418
38419- atomic_set(&dev_priv->irq_received, 0);
38420+ atomic_set_unchecked(&dev_priv->irq_received, 0);
38421
38422 I915_WRITE(HWSTAM, 0xeffe);
38423
38424@@ -2164,7 +2164,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
38425 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
38426 int pipe;
38427
38428- atomic_set(&dev_priv->irq_received, 0);
38429+ atomic_set_unchecked(&dev_priv->irq_received, 0);
38430
38431 /* VLV magic */
38432 I915_WRITE(VLV_IMR, 0);
38433@@ -2452,7 +2452,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
38434 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
38435 int pipe;
38436
38437- atomic_set(&dev_priv->irq_received, 0);
38438+ atomic_set_unchecked(&dev_priv->irq_received, 0);
38439
38440 for_each_pipe(pipe)
38441 I915_WRITE(PIPESTAT(pipe), 0);
38442@@ -2530,7 +2530,7 @@ static irqreturn_t i8xx_irq_handler(int irq, void *arg)
38443 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
38444 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
38445
38446- atomic_inc(&dev_priv->irq_received);
38447+ atomic_inc_unchecked(&dev_priv->irq_received);
38448
38449 iir = I915_READ16(IIR);
38450 if (iir == 0)
38451@@ -2604,7 +2604,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
38452 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
38453 int pipe;
38454
38455- atomic_set(&dev_priv->irq_received, 0);
38456+ atomic_set_unchecked(&dev_priv->irq_received, 0);
38457
38458 if (I915_HAS_HOTPLUG(dev)) {
38459 I915_WRITE(PORT_HOTPLUG_EN, 0);
38460@@ -2703,7 +2703,7 @@ static irqreturn_t i915_irq_handler(int irq, void *arg)
38461 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
38462 int pipe, ret = IRQ_NONE;
38463
38464- atomic_inc(&dev_priv->irq_received);
38465+ atomic_inc_unchecked(&dev_priv->irq_received);
38466
38467 iir = I915_READ(IIR);
38468 do {
38469@@ -2827,7 +2827,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
38470 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
38471 int pipe;
38472
38473- atomic_set(&dev_priv->irq_received, 0);
38474+ atomic_set_unchecked(&dev_priv->irq_received, 0);
38475
38476 I915_WRITE(PORT_HOTPLUG_EN, 0);
38477 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
38478@@ -2941,7 +2941,7 @@ static irqreturn_t i965_irq_handler(int irq, void *arg)
38479 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
38480 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
38481
38482- atomic_inc(&dev_priv->irq_received);
38483+ atomic_inc_unchecked(&dev_priv->irq_received);
38484
38485 iir = I915_READ(IIR);
38486
38487diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
38488index d78d33f..01d7c58 100644
38489--- a/drivers/gpu/drm/i915/intel_display.c
38490+++ b/drivers/gpu/drm/i915/intel_display.c
38491@@ -9972,13 +9972,13 @@ struct intel_quirk {
38492 int subsystem_vendor;
38493 int subsystem_device;
38494 void (*hook)(struct drm_device *dev);
38495-};
38496+} __do_const;
38497
38498 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
38499 struct intel_dmi_quirk {
38500 void (*hook)(struct drm_device *dev);
38501 const struct dmi_system_id (*dmi_id_list)[];
38502-};
38503+} __do_const;
38504
38505 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
38506 {
38507@@ -9986,18 +9986,20 @@ static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
38508 return 1;
38509 }
38510
38511-static const struct intel_dmi_quirk intel_dmi_quirks[] = {
38512+static const struct dmi_system_id intel_dmi_quirks_table[] = {
38513 {
38514- .dmi_id_list = &(const struct dmi_system_id[]) {
38515- {
38516- .callback = intel_dmi_reverse_brightness,
38517- .ident = "NCR Corporation",
38518- .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
38519- DMI_MATCH(DMI_PRODUCT_NAME, ""),
38520- },
38521- },
38522- { } /* terminating entry */
38523+ .callback = intel_dmi_reverse_brightness,
38524+ .ident = "NCR Corporation",
38525+ .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
38526+ DMI_MATCH(DMI_PRODUCT_NAME, ""),
38527 },
38528+ },
38529+ { } /* terminating entry */
38530+};
38531+
38532+static const struct intel_dmi_quirk intel_dmi_quirks[] = {
38533+ {
38534+ .dmi_id_list = &intel_dmi_quirks_table,
38535 .hook = quirk_invert_brightness,
38536 },
38537 };
38538diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
38539index ca4bc54..ee598a2 100644
38540--- a/drivers/gpu/drm/mga/mga_drv.h
38541+++ b/drivers/gpu/drm/mga/mga_drv.h
38542@@ -120,9 +120,9 @@ typedef struct drm_mga_private {
38543 u32 clear_cmd;
38544 u32 maccess;
38545
38546- atomic_t vbl_received; /**< Number of vblanks received. */
38547+ atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
38548 wait_queue_head_t fence_queue;
38549- atomic_t last_fence_retired;
38550+ atomic_unchecked_t last_fence_retired;
38551 u32 next_fence_to_post;
38552
38553 unsigned int fb_cpp;
38554diff --git a/drivers/gpu/drm/mga/mga_ioc32.c b/drivers/gpu/drm/mga/mga_ioc32.c
38555index 709e90d..89a1c0d 100644
38556--- a/drivers/gpu/drm/mga/mga_ioc32.c
38557+++ b/drivers/gpu/drm/mga/mga_ioc32.c
38558@@ -189,7 +189,7 @@ static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
38559 return 0;
38560 }
38561
38562-drm_ioctl_compat_t *mga_compat_ioctls[] = {
38563+drm_ioctl_compat_t mga_compat_ioctls[] = {
38564 [DRM_MGA_INIT] = compat_mga_init,
38565 [DRM_MGA_GETPARAM] = compat_mga_getparam,
38566 [DRM_MGA_DMA_BOOTSTRAP] = compat_mga_dma_bootstrap,
38567@@ -207,18 +207,15 @@ drm_ioctl_compat_t *mga_compat_ioctls[] = {
38568 long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
38569 {
38570 unsigned int nr = DRM_IOCTL_NR(cmd);
38571- drm_ioctl_compat_t *fn = NULL;
38572 int ret;
38573
38574 if (nr < DRM_COMMAND_BASE)
38575 return drm_compat_ioctl(filp, cmd, arg);
38576
38577- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls))
38578- fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
38579-
38580- if (fn != NULL)
38581+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls)) {
38582+ drm_ioctl_compat_t fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
38583 ret = (*fn) (filp, cmd, arg);
38584- else
38585+ } else
38586 ret = drm_ioctl(filp, cmd, arg);
38587
38588 return ret;
38589diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
38590index 598c281..60d590e 100644
38591--- a/drivers/gpu/drm/mga/mga_irq.c
38592+++ b/drivers/gpu/drm/mga/mga_irq.c
38593@@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
38594 if (crtc != 0)
38595 return 0;
38596
38597- return atomic_read(&dev_priv->vbl_received);
38598+ return atomic_read_unchecked(&dev_priv->vbl_received);
38599 }
38600
38601
38602@@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
38603 /* VBLANK interrupt */
38604 if (status & MGA_VLINEPEN) {
38605 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
38606- atomic_inc(&dev_priv->vbl_received);
38607+ atomic_inc_unchecked(&dev_priv->vbl_received);
38608 drm_handle_vblank(dev, 0);
38609 handled = 1;
38610 }
38611@@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
38612 if ((prim_start & ~0x03) != (prim_end & ~0x03))
38613 MGA_WRITE(MGA_PRIMEND, prim_end);
38614
38615- atomic_inc(&dev_priv->last_fence_retired);
38616+ atomic_inc_unchecked(&dev_priv->last_fence_retired);
38617 DRM_WAKEUP(&dev_priv->fence_queue);
38618 handled = 1;
38619 }
38620@@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
38621 * using fences.
38622 */
38623 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
38624- (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
38625+ (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
38626 - *sequence) <= (1 << 23)));
38627
38628 *sequence = cur_fence;
38629diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
38630index 3e72876..d1c15ad 100644
38631--- a/drivers/gpu/drm/nouveau/nouveau_bios.c
38632+++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
38633@@ -965,7 +965,7 @@ static int parse_bit_tmds_tbl_entry(struct drm_device *dev, struct nvbios *bios,
38634 struct bit_table {
38635 const char id;
38636 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
38637-};
38638+} __no_const;
38639
38640 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
38641
38642diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
38643index 994fd6e..6e12565 100644
38644--- a/drivers/gpu/drm/nouveau/nouveau_drm.h
38645+++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
38646@@ -94,7 +94,6 @@ struct nouveau_drm {
38647 struct drm_global_reference mem_global_ref;
38648 struct ttm_bo_global_ref bo_global_ref;
38649 struct ttm_bo_device bdev;
38650- atomic_t validate_sequence;
38651 int (*move)(struct nouveau_channel *,
38652 struct ttm_buffer_object *,
38653 struct ttm_mem_reg *, struct ttm_mem_reg *);
38654diff --git a/drivers/gpu/drm/nouveau/nouveau_ioc32.c b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
38655index c1a7e5a..38b8539 100644
38656--- a/drivers/gpu/drm/nouveau/nouveau_ioc32.c
38657+++ b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
38658@@ -50,7 +50,7 @@ long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
38659 unsigned long arg)
38660 {
38661 unsigned int nr = DRM_IOCTL_NR(cmd);
38662- drm_ioctl_compat_t *fn = NULL;
38663+ drm_ioctl_compat_t fn = NULL;
38664 int ret;
38665
38666 if (nr < DRM_COMMAND_BASE)
38667diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
38668index 81638d7..2e45854 100644
38669--- a/drivers/gpu/drm/nouveau/nouveau_vga.c
38670+++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
38671@@ -65,7 +65,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
38672 bool can_switch;
38673
38674 spin_lock(&dev->count_lock);
38675- can_switch = (dev->open_count == 0);
38676+ can_switch = (local_read(&dev->open_count) == 0);
38677 spin_unlock(&dev->count_lock);
38678 return can_switch;
38679 }
38680diff --git a/drivers/gpu/drm/qxl/qxl_cmd.c b/drivers/gpu/drm/qxl/qxl_cmd.c
38681index eb89653..613cf71 100644
38682--- a/drivers/gpu/drm/qxl/qxl_cmd.c
38683+++ b/drivers/gpu/drm/qxl/qxl_cmd.c
38684@@ -285,27 +285,27 @@ static int wait_for_io_cmd_user(struct qxl_device *qdev, uint8_t val, long port,
38685 int ret;
38686
38687 mutex_lock(&qdev->async_io_mutex);
38688- irq_num = atomic_read(&qdev->irq_received_io_cmd);
38689+ irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
38690 if (qdev->last_sent_io_cmd > irq_num) {
38691 if (intr)
38692 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
38693- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
38694+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
38695 else
38696 ret = wait_event_timeout(qdev->io_cmd_event,
38697- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
38698+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
38699 /* 0 is timeout, just bail the "hw" has gone away */
38700 if (ret <= 0)
38701 goto out;
38702- irq_num = atomic_read(&qdev->irq_received_io_cmd);
38703+ irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
38704 }
38705 outb(val, addr);
38706 qdev->last_sent_io_cmd = irq_num + 1;
38707 if (intr)
38708 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
38709- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
38710+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
38711 else
38712 ret = wait_event_timeout(qdev->io_cmd_event,
38713- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
38714+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
38715 out:
38716 if (ret > 0)
38717 ret = 0;
38718diff --git a/drivers/gpu/drm/qxl/qxl_debugfs.c b/drivers/gpu/drm/qxl/qxl_debugfs.c
38719index c3c2bbd..bc3c0fb 100644
38720--- a/drivers/gpu/drm/qxl/qxl_debugfs.c
38721+++ b/drivers/gpu/drm/qxl/qxl_debugfs.c
38722@@ -42,10 +42,10 @@ qxl_debugfs_irq_received(struct seq_file *m, void *data)
38723 struct drm_info_node *node = (struct drm_info_node *) m->private;
38724 struct qxl_device *qdev = node->minor->dev->dev_private;
38725
38726- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received));
38727- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_display));
38728- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_cursor));
38729- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_io_cmd));
38730+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received));
38731+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_display));
38732+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_cursor));
38733+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_io_cmd));
38734 seq_printf(m, "%d\n", qdev->irq_received_error);
38735 return 0;
38736 }
38737diff --git a/drivers/gpu/drm/qxl/qxl_drv.h b/drivers/gpu/drm/qxl/qxl_drv.h
38738index f7c9add..fb971d2 100644
38739--- a/drivers/gpu/drm/qxl/qxl_drv.h
38740+++ b/drivers/gpu/drm/qxl/qxl_drv.h
38741@@ -290,10 +290,10 @@ struct qxl_device {
38742 unsigned int last_sent_io_cmd;
38743
38744 /* interrupt handling */
38745- atomic_t irq_received;
38746- atomic_t irq_received_display;
38747- atomic_t irq_received_cursor;
38748- atomic_t irq_received_io_cmd;
38749+ atomic_unchecked_t irq_received;
38750+ atomic_unchecked_t irq_received_display;
38751+ atomic_unchecked_t irq_received_cursor;
38752+ atomic_unchecked_t irq_received_io_cmd;
38753 unsigned irq_received_error;
38754 wait_queue_head_t display_event;
38755 wait_queue_head_t cursor_event;
38756diff --git a/drivers/gpu/drm/qxl/qxl_irq.c b/drivers/gpu/drm/qxl/qxl_irq.c
38757index 21393dc..329f3a9 100644
38758--- a/drivers/gpu/drm/qxl/qxl_irq.c
38759+++ b/drivers/gpu/drm/qxl/qxl_irq.c
38760@@ -33,19 +33,19 @@ irqreturn_t qxl_irq_handler(DRM_IRQ_ARGS)
38761
38762 pending = xchg(&qdev->ram_header->int_pending, 0);
38763
38764- atomic_inc(&qdev->irq_received);
38765+ atomic_inc_unchecked(&qdev->irq_received);
38766
38767 if (pending & QXL_INTERRUPT_DISPLAY) {
38768- atomic_inc(&qdev->irq_received_display);
38769+ atomic_inc_unchecked(&qdev->irq_received_display);
38770 wake_up_all(&qdev->display_event);
38771 qxl_queue_garbage_collect(qdev, false);
38772 }
38773 if (pending & QXL_INTERRUPT_CURSOR) {
38774- atomic_inc(&qdev->irq_received_cursor);
38775+ atomic_inc_unchecked(&qdev->irq_received_cursor);
38776 wake_up_all(&qdev->cursor_event);
38777 }
38778 if (pending & QXL_INTERRUPT_IO_CMD) {
38779- atomic_inc(&qdev->irq_received_io_cmd);
38780+ atomic_inc_unchecked(&qdev->irq_received_io_cmd);
38781 wake_up_all(&qdev->io_cmd_event);
38782 }
38783 if (pending & QXL_INTERRUPT_ERROR) {
38784@@ -82,10 +82,10 @@ int qxl_irq_init(struct qxl_device *qdev)
38785 init_waitqueue_head(&qdev->io_cmd_event);
38786 INIT_WORK(&qdev->client_monitors_config_work,
38787 qxl_client_monitors_config_work_func);
38788- atomic_set(&qdev->irq_received, 0);
38789- atomic_set(&qdev->irq_received_display, 0);
38790- atomic_set(&qdev->irq_received_cursor, 0);
38791- atomic_set(&qdev->irq_received_io_cmd, 0);
38792+ atomic_set_unchecked(&qdev->irq_received, 0);
38793+ atomic_set_unchecked(&qdev->irq_received_display, 0);
38794+ atomic_set_unchecked(&qdev->irq_received_cursor, 0);
38795+ atomic_set_unchecked(&qdev->irq_received_io_cmd, 0);
38796 qdev->irq_received_error = 0;
38797 ret = drm_irq_install(qdev->ddev);
38798 qdev->ram_header->int_mask = QXL_INTERRUPT_MASK;
38799diff --git a/drivers/gpu/drm/qxl/qxl_ttm.c b/drivers/gpu/drm/qxl/qxl_ttm.c
38800index 037786d..2a95e33 100644
38801--- a/drivers/gpu/drm/qxl/qxl_ttm.c
38802+++ b/drivers/gpu/drm/qxl/qxl_ttm.c
38803@@ -103,7 +103,7 @@ static void qxl_ttm_global_fini(struct qxl_device *qdev)
38804 }
38805 }
38806
38807-static struct vm_operations_struct qxl_ttm_vm_ops;
38808+static vm_operations_struct_no_const qxl_ttm_vm_ops __read_only;
38809 static const struct vm_operations_struct *ttm_vm_ops;
38810
38811 static int qxl_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
38812@@ -147,8 +147,10 @@ int qxl_mmap(struct file *filp, struct vm_area_struct *vma)
38813 return r;
38814 if (unlikely(ttm_vm_ops == NULL)) {
38815 ttm_vm_ops = vma->vm_ops;
38816+ pax_open_kernel();
38817 qxl_ttm_vm_ops = *ttm_vm_ops;
38818 qxl_ttm_vm_ops.fault = &qxl_ttm_fault;
38819+ pax_close_kernel();
38820 }
38821 vma->vm_ops = &qxl_ttm_vm_ops;
38822 return 0;
38823@@ -558,25 +560,23 @@ static int qxl_mm_dump_table(struct seq_file *m, void *data)
38824 static int qxl_ttm_debugfs_init(struct qxl_device *qdev)
38825 {
38826 #if defined(CONFIG_DEBUG_FS)
38827- static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES];
38828- static char qxl_mem_types_names[QXL_DEBUGFS_MEM_TYPES][32];
38829- unsigned i;
38830+ static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES] = {
38831+ {
38832+ .name = "qxl_mem_mm",
38833+ .show = &qxl_mm_dump_table,
38834+ },
38835+ {
38836+ .name = "qxl_surf_mm",
38837+ .show = &qxl_mm_dump_table,
38838+ }
38839+ };
38840
38841- for (i = 0; i < QXL_DEBUGFS_MEM_TYPES; i++) {
38842- if (i == 0)
38843- sprintf(qxl_mem_types_names[i], "qxl_mem_mm");
38844- else
38845- sprintf(qxl_mem_types_names[i], "qxl_surf_mm");
38846- qxl_mem_types_list[i].name = qxl_mem_types_names[i];
38847- qxl_mem_types_list[i].show = &qxl_mm_dump_table;
38848- qxl_mem_types_list[i].driver_features = 0;
38849- if (i == 0)
38850- qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
38851- else
38852- qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
38853+ pax_open_kernel();
38854+ *(void **)&qxl_mem_types_list[0].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
38855+ *(void **)&qxl_mem_types_list[1].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
38856+ pax_close_kernel();
38857
38858- }
38859- return qxl_debugfs_add_files(qdev, qxl_mem_types_list, i);
38860+ return qxl_debugfs_add_files(qdev, qxl_mem_types_list, QXL_DEBUGFS_MEM_TYPES);
38861 #else
38862 return 0;
38863 #endif
38864diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
38865index c451257..0ad2134 100644
38866--- a/drivers/gpu/drm/r128/r128_cce.c
38867+++ b/drivers/gpu/drm/r128/r128_cce.c
38868@@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
38869
38870 /* GH: Simple idle check.
38871 */
38872- atomic_set(&dev_priv->idle_count, 0);
38873+ atomic_set_unchecked(&dev_priv->idle_count, 0);
38874
38875 /* We don't support anything other than bus-mastering ring mode,
38876 * but the ring can be in either AGP or PCI space for the ring
38877diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
38878index 56eb5e3..c4ec43d 100644
38879--- a/drivers/gpu/drm/r128/r128_drv.h
38880+++ b/drivers/gpu/drm/r128/r128_drv.h
38881@@ -90,14 +90,14 @@ typedef struct drm_r128_private {
38882 int is_pci;
38883 unsigned long cce_buffers_offset;
38884
38885- atomic_t idle_count;
38886+ atomic_unchecked_t idle_count;
38887
38888 int page_flipping;
38889 int current_page;
38890 u32 crtc_offset;
38891 u32 crtc_offset_cntl;
38892
38893- atomic_t vbl_received;
38894+ atomic_unchecked_t vbl_received;
38895
38896 u32 color_fmt;
38897 unsigned int front_offset;
38898diff --git a/drivers/gpu/drm/r128/r128_ioc32.c b/drivers/gpu/drm/r128/r128_ioc32.c
38899index a954c54..9cc595c 100644
38900--- a/drivers/gpu/drm/r128/r128_ioc32.c
38901+++ b/drivers/gpu/drm/r128/r128_ioc32.c
38902@@ -177,7 +177,7 @@ static int compat_r128_getparam(struct file *file, unsigned int cmd,
38903 return drm_ioctl(file, DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
38904 }
38905
38906-drm_ioctl_compat_t *r128_compat_ioctls[] = {
38907+drm_ioctl_compat_t r128_compat_ioctls[] = {
38908 [DRM_R128_INIT] = compat_r128_init,
38909 [DRM_R128_DEPTH] = compat_r128_depth,
38910 [DRM_R128_STIPPLE] = compat_r128_stipple,
38911@@ -196,18 +196,15 @@ drm_ioctl_compat_t *r128_compat_ioctls[] = {
38912 long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
38913 {
38914 unsigned int nr = DRM_IOCTL_NR(cmd);
38915- drm_ioctl_compat_t *fn = NULL;
38916 int ret;
38917
38918 if (nr < DRM_COMMAND_BASE)
38919 return drm_compat_ioctl(filp, cmd, arg);
38920
38921- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls))
38922- fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
38923-
38924- if (fn != NULL)
38925+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls)) {
38926+ drm_ioctl_compat_t fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
38927 ret = (*fn) (filp, cmd, arg);
38928- else
38929+ } else
38930 ret = drm_ioctl(filp, cmd, arg);
38931
38932 return ret;
38933diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
38934index 2ea4f09..d391371 100644
38935--- a/drivers/gpu/drm/r128/r128_irq.c
38936+++ b/drivers/gpu/drm/r128/r128_irq.c
38937@@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
38938 if (crtc != 0)
38939 return 0;
38940
38941- return atomic_read(&dev_priv->vbl_received);
38942+ return atomic_read_unchecked(&dev_priv->vbl_received);
38943 }
38944
38945 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
38946@@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
38947 /* VBLANK interrupt */
38948 if (status & R128_CRTC_VBLANK_INT) {
38949 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
38950- atomic_inc(&dev_priv->vbl_received);
38951+ atomic_inc_unchecked(&dev_priv->vbl_received);
38952 drm_handle_vblank(dev, 0);
38953 return IRQ_HANDLED;
38954 }
38955diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
38956index 01dd9ae..6352f04 100644
38957--- a/drivers/gpu/drm/r128/r128_state.c
38958+++ b/drivers/gpu/drm/r128/r128_state.c
38959@@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
38960
38961 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
38962 {
38963- if (atomic_read(&dev_priv->idle_count) == 0)
38964+ if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
38965 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
38966 else
38967- atomic_set(&dev_priv->idle_count, 0);
38968+ atomic_set_unchecked(&dev_priv->idle_count, 0);
38969 }
38970
38971 #endif
38972diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
38973index af85299..ed9ac8d 100644
38974--- a/drivers/gpu/drm/radeon/mkregtable.c
38975+++ b/drivers/gpu/drm/radeon/mkregtable.c
38976@@ -624,14 +624,14 @@ static int parser_auth(struct table *t, const char *filename)
38977 regex_t mask_rex;
38978 regmatch_t match[4];
38979 char buf[1024];
38980- size_t end;
38981+ long end;
38982 int len;
38983 int done = 0;
38984 int r;
38985 unsigned o;
38986 struct offset *offset;
38987 char last_reg_s[10];
38988- int last_reg;
38989+ unsigned long last_reg;
38990
38991 if (regcomp
38992 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
38993diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
38994index 841d0e0..9eaa268 100644
38995--- a/drivers/gpu/drm/radeon/radeon_device.c
38996+++ b/drivers/gpu/drm/radeon/radeon_device.c
38997@@ -1117,7 +1117,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
38998 bool can_switch;
38999
39000 spin_lock(&dev->count_lock);
39001- can_switch = (dev->open_count == 0);
39002+ can_switch = (local_read(&dev->open_count) == 0);
39003 spin_unlock(&dev->count_lock);
39004 return can_switch;
39005 }
39006diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
39007index b369d42..8dd04eb 100644
39008--- a/drivers/gpu/drm/radeon/radeon_drv.h
39009+++ b/drivers/gpu/drm/radeon/radeon_drv.h
39010@@ -258,7 +258,7 @@ typedef struct drm_radeon_private {
39011
39012 /* SW interrupt */
39013 wait_queue_head_t swi_queue;
39014- atomic_t swi_emitted;
39015+ atomic_unchecked_t swi_emitted;
39016 int vblank_crtc;
39017 uint32_t irq_enable_reg;
39018 uint32_t r500_disp_irq_reg;
39019diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
39020index c180df8..5fd8186 100644
39021--- a/drivers/gpu/drm/radeon/radeon_ioc32.c
39022+++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
39023@@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
39024 request = compat_alloc_user_space(sizeof(*request));
39025 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
39026 || __put_user(req32.param, &request->param)
39027- || __put_user((void __user *)(unsigned long)req32.value,
39028+ || __put_user((unsigned long)req32.value,
39029 &request->value))
39030 return -EFAULT;
39031
39032@@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
39033 #define compat_radeon_cp_setparam NULL
39034 #endif /* X86_64 || IA64 */
39035
39036-static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
39037+static drm_ioctl_compat_t radeon_compat_ioctls[] = {
39038 [DRM_RADEON_CP_INIT] = compat_radeon_cp_init,
39039 [DRM_RADEON_CLEAR] = compat_radeon_cp_clear,
39040 [DRM_RADEON_STIPPLE] = compat_radeon_cp_stipple,
39041@@ -393,18 +393,15 @@ static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
39042 long radeon_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
39043 {
39044 unsigned int nr = DRM_IOCTL_NR(cmd);
39045- drm_ioctl_compat_t *fn = NULL;
39046 int ret;
39047
39048 if (nr < DRM_COMMAND_BASE)
39049 return drm_compat_ioctl(filp, cmd, arg);
39050
39051- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls))
39052- fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
39053-
39054- if (fn != NULL)
39055+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls)) {
39056+ drm_ioctl_compat_t fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
39057 ret = (*fn) (filp, cmd, arg);
39058- else
39059+ } else
39060 ret = drm_ioctl(filp, cmd, arg);
39061
39062 return ret;
39063diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
39064index 8d68e97..9dcfed8 100644
39065--- a/drivers/gpu/drm/radeon/radeon_irq.c
39066+++ b/drivers/gpu/drm/radeon/radeon_irq.c
39067@@ -226,8 +226,8 @@ static int radeon_emit_irq(struct drm_device * dev)
39068 unsigned int ret;
39069 RING_LOCALS;
39070
39071- atomic_inc(&dev_priv->swi_emitted);
39072- ret = atomic_read(&dev_priv->swi_emitted);
39073+ atomic_inc_unchecked(&dev_priv->swi_emitted);
39074+ ret = atomic_read_unchecked(&dev_priv->swi_emitted);
39075
39076 BEGIN_RING(4);
39077 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
39078@@ -353,7 +353,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
39079 drm_radeon_private_t *dev_priv =
39080 (drm_radeon_private_t *) dev->dev_private;
39081
39082- atomic_set(&dev_priv->swi_emitted, 0);
39083+ atomic_set_unchecked(&dev_priv->swi_emitted, 0);
39084 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
39085
39086 dev->max_vblank_count = 0x001fffff;
39087diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
39088index 4d20910..6726b6d 100644
39089--- a/drivers/gpu/drm/radeon/radeon_state.c
39090+++ b/drivers/gpu/drm/radeon/radeon_state.c
39091@@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
39092 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
39093 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
39094
39095- if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
39096+ if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
39097 sarea_priv->nbox * sizeof(depth_boxes[0])))
39098 return -EFAULT;
39099
39100@@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
39101 {
39102 drm_radeon_private_t *dev_priv = dev->dev_private;
39103 drm_radeon_getparam_t *param = data;
39104- int value;
39105+ int value = 0;
39106
39107 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
39108
39109diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
39110index 71245d6..94c556d 100644
39111--- a/drivers/gpu/drm/radeon/radeon_ttm.c
39112+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
39113@@ -784,7 +784,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
39114 man->size = size >> PAGE_SHIFT;
39115 }
39116
39117-static struct vm_operations_struct radeon_ttm_vm_ops;
39118+static vm_operations_struct_no_const radeon_ttm_vm_ops __read_only;
39119 static const struct vm_operations_struct *ttm_vm_ops = NULL;
39120
39121 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
39122@@ -825,8 +825,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
39123 }
39124 if (unlikely(ttm_vm_ops == NULL)) {
39125 ttm_vm_ops = vma->vm_ops;
39126+ pax_open_kernel();
39127 radeon_ttm_vm_ops = *ttm_vm_ops;
39128 radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
39129+ pax_close_kernel();
39130 }
39131 vma->vm_ops = &radeon_ttm_vm_ops;
39132 return 0;
39133@@ -855,38 +857,33 @@ static int radeon_mm_dump_table(struct seq_file *m, void *data)
39134 static int radeon_ttm_debugfs_init(struct radeon_device *rdev)
39135 {
39136 #if defined(CONFIG_DEBUG_FS)
39137- static struct drm_info_list radeon_mem_types_list[RADEON_DEBUGFS_MEM_TYPES+2];
39138- static char radeon_mem_types_names[RADEON_DEBUGFS_MEM_TYPES+2][32];
39139- unsigned i;
39140+ static struct drm_info_list radeon_mem_types_list[RADEON_DEBUGFS_MEM_TYPES+2] = {
39141+ {
39142+ .name = "radeon_vram_mm",
39143+ .show = &radeon_mm_dump_table,
39144+ },
39145+ {
39146+ .name = "radeon_gtt_mm",
39147+ .show = &radeon_mm_dump_table,
39148+ },
39149+ {
39150+ .name = "ttm_page_pool",
39151+ .show = &ttm_page_alloc_debugfs,
39152+ },
39153+ {
39154+ .name = "ttm_dma_page_pool",
39155+ .show = &ttm_dma_page_alloc_debugfs,
39156+ },
39157+ };
39158+ unsigned i = RADEON_DEBUGFS_MEM_TYPES + 1;
39159
39160- for (i = 0; i < RADEON_DEBUGFS_MEM_TYPES; i++) {
39161- if (i == 0)
39162- sprintf(radeon_mem_types_names[i], "radeon_vram_mm");
39163- else
39164- sprintf(radeon_mem_types_names[i], "radeon_gtt_mm");
39165- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
39166- radeon_mem_types_list[i].show = &radeon_mm_dump_table;
39167- radeon_mem_types_list[i].driver_features = 0;
39168- if (i == 0)
39169- radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_VRAM].priv;
39170- else
39171- radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_TT].priv;
39172-
39173- }
39174- /* Add ttm page pool to debugfs */
39175- sprintf(radeon_mem_types_names[i], "ttm_page_pool");
39176- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
39177- radeon_mem_types_list[i].show = &ttm_page_alloc_debugfs;
39178- radeon_mem_types_list[i].driver_features = 0;
39179- radeon_mem_types_list[i++].data = NULL;
39180+ pax_open_kernel();
39181+ *(void **)&radeon_mem_types_list[0].data = rdev->mman.bdev.man[TTM_PL_VRAM].priv;
39182+ *(void **)&radeon_mem_types_list[1].data = rdev->mman.bdev.man[TTM_PL_TT].priv;
39183+ pax_close_kernel();
39184 #ifdef CONFIG_SWIOTLB
39185- if (swiotlb_nr_tbl()) {
39186- sprintf(radeon_mem_types_names[i], "ttm_dma_page_pool");
39187- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
39188- radeon_mem_types_list[i].show = &ttm_dma_page_alloc_debugfs;
39189- radeon_mem_types_list[i].driver_features = 0;
39190- radeon_mem_types_list[i++].data = NULL;
39191- }
39192+ if (swiotlb_nr_tbl())
39193+ i++;
39194 #endif
39195 return radeon_debugfs_add_files(rdev, radeon_mem_types_list, i);
39196
39197diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
39198index 1447d79..40b2a5b 100644
39199--- a/drivers/gpu/drm/radeon/rs690.c
39200+++ b/drivers/gpu/drm/radeon/rs690.c
39201@@ -345,9 +345,11 @@ static void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
39202 if (max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
39203 rdev->pm.sideport_bandwidth.full)
39204 max_bandwidth = rdev->pm.sideport_bandwidth;
39205- read_delay_latency.full = dfixed_const(370 * 800 * 1000);
39206+ read_delay_latency.full = dfixed_const(800 * 1000);
39207 read_delay_latency.full = dfixed_div(read_delay_latency,
39208 rdev->pm.igp_sideport_mclk);
39209+ a.full = dfixed_const(370);
39210+ read_delay_latency.full = dfixed_mul(read_delay_latency, a);
39211 } else {
39212 if (max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
39213 rdev->pm.k8_bandwidth.full)
39214diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c
39215index dbc2def..0a9f710 100644
39216--- a/drivers/gpu/drm/ttm/ttm_memory.c
39217+++ b/drivers/gpu/drm/ttm/ttm_memory.c
39218@@ -264,7 +264,7 @@ static int ttm_mem_init_kernel_zone(struct ttm_mem_global *glob,
39219 zone->glob = glob;
39220 glob->zone_kernel = zone;
39221 ret = kobject_init_and_add(
39222- &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
39223+ &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
39224 if (unlikely(ret != 0)) {
39225 kobject_put(&zone->kobj);
39226 return ret;
39227@@ -347,7 +347,7 @@ static int ttm_mem_init_dma32_zone(struct ttm_mem_global *glob,
39228 zone->glob = glob;
39229 glob->zone_dma32 = zone;
39230 ret = kobject_init_and_add(
39231- &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
39232+ &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
39233 if (unlikely(ret != 0)) {
39234 kobject_put(&zone->kobj);
39235 return ret;
39236diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
39237index 863bef9..cba15cf 100644
39238--- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
39239+++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
39240@@ -391,9 +391,9 @@ out:
39241 static unsigned long
39242 ttm_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
39243 {
39244- static atomic_t start_pool = ATOMIC_INIT(0);
39245+ static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
39246 unsigned i;
39247- unsigned pool_offset = atomic_add_return(1, &start_pool);
39248+ unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
39249 struct ttm_page_pool *pool;
39250 int shrink_pages = sc->nr_to_scan;
39251 unsigned long freed = 0;
39252diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_fb.c
39253index 97e9d61..bf23c461 100644
39254--- a/drivers/gpu/drm/udl/udl_fb.c
39255+++ b/drivers/gpu/drm/udl/udl_fb.c
39256@@ -367,7 +367,6 @@ static int udl_fb_release(struct fb_info *info, int user)
39257 fb_deferred_io_cleanup(info);
39258 kfree(info->fbdefio);
39259 info->fbdefio = NULL;
39260- info->fbops->fb_mmap = udl_fb_mmap;
39261 }
39262
39263 pr_warn("released /dev/fb%d user=%d count=%d\n",
39264diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
39265index a811ef2..ff99b05 100644
39266--- a/drivers/gpu/drm/via/via_drv.h
39267+++ b/drivers/gpu/drm/via/via_drv.h
39268@@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
39269 typedef uint32_t maskarray_t[5];
39270
39271 typedef struct drm_via_irq {
39272- atomic_t irq_received;
39273+ atomic_unchecked_t irq_received;
39274 uint32_t pending_mask;
39275 uint32_t enable_mask;
39276 wait_queue_head_t irq_queue;
39277@@ -75,7 +75,7 @@ typedef struct drm_via_private {
39278 struct timeval last_vblank;
39279 int last_vblank_valid;
39280 unsigned usec_per_vblank;
39281- atomic_t vbl_received;
39282+ atomic_unchecked_t vbl_received;
39283 drm_via_state_t hc_state;
39284 char pci_buf[VIA_PCI_BUF_SIZE];
39285 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
39286diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
39287index ac98964..5dbf512 100644
39288--- a/drivers/gpu/drm/via/via_irq.c
39289+++ b/drivers/gpu/drm/via/via_irq.c
39290@@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
39291 if (crtc != 0)
39292 return 0;
39293
39294- return atomic_read(&dev_priv->vbl_received);
39295+ return atomic_read_unchecked(&dev_priv->vbl_received);
39296 }
39297
39298 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
39299@@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
39300
39301 status = VIA_READ(VIA_REG_INTERRUPT);
39302 if (status & VIA_IRQ_VBLANK_PENDING) {
39303- atomic_inc(&dev_priv->vbl_received);
39304- if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
39305+ atomic_inc_unchecked(&dev_priv->vbl_received);
39306+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
39307 do_gettimeofday(&cur_vblank);
39308 if (dev_priv->last_vblank_valid) {
39309 dev_priv->usec_per_vblank =
39310@@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
39311 dev_priv->last_vblank = cur_vblank;
39312 dev_priv->last_vblank_valid = 1;
39313 }
39314- if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
39315+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
39316 DRM_DEBUG("US per vblank is: %u\n",
39317 dev_priv->usec_per_vblank);
39318 }
39319@@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
39320
39321 for (i = 0; i < dev_priv->num_irqs; ++i) {
39322 if (status & cur_irq->pending_mask) {
39323- atomic_inc(&cur_irq->irq_received);
39324+ atomic_inc_unchecked(&cur_irq->irq_received);
39325 DRM_WAKEUP(&cur_irq->irq_queue);
39326 handled = 1;
39327 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
39328@@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
39329 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
39330 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
39331 masks[irq][4]));
39332- cur_irq_sequence = atomic_read(&cur_irq->irq_received);
39333+ cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
39334 } else {
39335 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
39336 (((cur_irq_sequence =
39337- atomic_read(&cur_irq->irq_received)) -
39338+ atomic_read_unchecked(&cur_irq->irq_received)) -
39339 *sequence) <= (1 << 23)));
39340 }
39341 *sequence = cur_irq_sequence;
39342@@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
39343 }
39344
39345 for (i = 0; i < dev_priv->num_irqs; ++i) {
39346- atomic_set(&cur_irq->irq_received, 0);
39347+ atomic_set_unchecked(&cur_irq->irq_received, 0);
39348 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
39349 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
39350 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
39351@@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
39352 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
39353 case VIA_IRQ_RELATIVE:
39354 irqwait->request.sequence +=
39355- atomic_read(&cur_irq->irq_received);
39356+ atomic_read_unchecked(&cur_irq->irq_received);
39357 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
39358 case VIA_IRQ_ABSOLUTE:
39359 break;
39360diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
39361index 150ec64..f5165f2 100644
39362--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
39363+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
39364@@ -290,7 +290,7 @@ struct vmw_private {
39365 * Fencing and IRQs.
39366 */
39367
39368- atomic_t marker_seq;
39369+ atomic_unchecked_t marker_seq;
39370 wait_queue_head_t fence_queue;
39371 wait_queue_head_t fifo_queue;
39372 int fence_queue_waiters; /* Protected by hw_mutex */
39373diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
39374index 3eb1486..0a47ee9 100644
39375--- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
39376+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
39377@@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
39378 (unsigned int) min,
39379 (unsigned int) fifo->capabilities);
39380
39381- atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
39382+ atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
39383 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
39384 vmw_marker_queue_init(&fifo->marker_queue);
39385 return vmw_fifo_send_fence(dev_priv, &dummy);
39386@@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
39387 if (reserveable)
39388 iowrite32(bytes, fifo_mem +
39389 SVGA_FIFO_RESERVED);
39390- return fifo_mem + (next_cmd >> 2);
39391+ return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
39392 } else {
39393 need_bounce = true;
39394 }
39395@@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
39396
39397 fm = vmw_fifo_reserve(dev_priv, bytes);
39398 if (unlikely(fm == NULL)) {
39399- *seqno = atomic_read(&dev_priv->marker_seq);
39400+ *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
39401 ret = -ENOMEM;
39402 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
39403 false, 3*HZ);
39404@@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
39405 }
39406
39407 do {
39408- *seqno = atomic_add_return(1, &dev_priv->marker_seq);
39409+ *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
39410 } while (*seqno == 0);
39411
39412 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
39413diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
39414index c509d40..3b640c3 100644
39415--- a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
39416+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
39417@@ -138,7 +138,7 @@ int vmw_present_ioctl(struct drm_device *dev, void *data,
39418 int ret;
39419
39420 num_clips = arg->num_clips;
39421- clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
39422+ clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
39423
39424 if (unlikely(num_clips == 0))
39425 return 0;
39426@@ -222,7 +222,7 @@ int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
39427 int ret;
39428
39429 num_clips = arg->num_clips;
39430- clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
39431+ clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
39432
39433 if (unlikely(num_clips == 0))
39434 return 0;
39435diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
39436index 4640adb..e1384ed 100644
39437--- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
39438+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
39439@@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
39440 * emitted. Then the fence is stale and signaled.
39441 */
39442
39443- ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
39444+ ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
39445 > VMW_FENCE_WRAP);
39446
39447 return ret;
39448@@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
39449
39450 if (fifo_idle)
39451 down_read(&fifo_state->rwsem);
39452- signal_seq = atomic_read(&dev_priv->marker_seq);
39453+ signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
39454 ret = 0;
39455
39456 for (;;) {
39457diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
39458index 8a8725c2..afed796 100644
39459--- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
39460+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
39461@@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
39462 while (!vmw_lag_lt(queue, us)) {
39463 spin_lock(&queue->lock);
39464 if (list_empty(&queue->head))
39465- seqno = atomic_read(&dev_priv->marker_seq);
39466+ seqno = atomic_read_unchecked(&dev_priv->marker_seq);
39467 else {
39468 marker = list_first_entry(&queue->head,
39469 struct vmw_marker, head);
39470diff --git a/drivers/gpu/host1x/drm/dc.c b/drivers/gpu/host1x/drm/dc.c
39471index b1a05ad..1c9d899 100644
39472--- a/drivers/gpu/host1x/drm/dc.c
39473+++ b/drivers/gpu/host1x/drm/dc.c
39474@@ -1004,7 +1004,7 @@ static int tegra_dc_debugfs_init(struct tegra_dc *dc, struct drm_minor *minor)
39475 }
39476
39477 for (i = 0; i < ARRAY_SIZE(debugfs_files); i++)
39478- dc->debugfs_files[i].data = dc;
39479+ *(void **)&dc->debugfs_files[i].data = dc;
39480
39481 err = drm_debugfs_create_files(dc->debugfs_files,
39482 ARRAY_SIZE(debugfs_files),
39483diff --git a/drivers/gpu/vga/vga_switcheroo.c b/drivers/gpu/vga/vga_switcheroo.c
39484index ec0ae2d..dc0780b 100644
39485--- a/drivers/gpu/vga/vga_switcheroo.c
39486+++ b/drivers/gpu/vga/vga_switcheroo.c
39487@@ -643,7 +643,7 @@ static int vga_switcheroo_runtime_resume(struct device *dev)
39488
39489 /* this version is for the case where the power switch is separate
39490 to the device being powered down. */
39491-int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain)
39492+int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain)
39493 {
39494 /* copy over all the bus versions */
39495 if (dev->bus && dev->bus->pm) {
39496@@ -688,7 +688,7 @@ static int vga_switcheroo_runtime_resume_hdmi_audio(struct device *dev)
39497 return ret;
39498 }
39499
39500-int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain)
39501+int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain)
39502 {
39503 /* copy over all the bus versions */
39504 if (dev->bus && dev->bus->pm) {
39505diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
39506index e80da62..bbcba01 100644
39507--- a/drivers/hid/hid-core.c
39508+++ b/drivers/hid/hid-core.c
39509@@ -2417,7 +2417,7 @@ EXPORT_SYMBOL_GPL(hid_ignore);
39510
39511 int hid_add_device(struct hid_device *hdev)
39512 {
39513- static atomic_t id = ATOMIC_INIT(0);
39514+ static atomic_unchecked_t id = ATOMIC_INIT(0);
39515 int ret;
39516
39517 if (WARN_ON(hdev->status & HID_STAT_ADDED))
39518@@ -2451,7 +2451,7 @@ int hid_add_device(struct hid_device *hdev)
39519 /* XXX hack, any other cleaner solution after the driver core
39520 * is converted to allow more than 20 bytes as the device name? */
39521 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
39522- hdev->vendor, hdev->product, atomic_inc_return(&id));
39523+ hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
39524
39525 hid_debug_register(hdev, dev_name(&hdev->dev));
39526 ret = device_add(&hdev->dev);
39527diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
39528index c13fb5b..55a3802 100644
39529--- a/drivers/hid/hid-wiimote-debug.c
39530+++ b/drivers/hid/hid-wiimote-debug.c
39531@@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
39532 else if (size == 0)
39533 return -EIO;
39534
39535- if (copy_to_user(u, buf, size))
39536+ if (size > sizeof(buf) || copy_to_user(u, buf, size))
39537 return -EFAULT;
39538
39539 *off += size;
39540diff --git a/drivers/hid/uhid.c b/drivers/hid/uhid.c
39541index 93b00d7..0a71596 100644
39542--- a/drivers/hid/uhid.c
39543+++ b/drivers/hid/uhid.c
39544@@ -47,7 +47,7 @@ struct uhid_device {
39545 struct mutex report_lock;
39546 wait_queue_head_t report_wait;
39547 atomic_t report_done;
39548- atomic_t report_id;
39549+ atomic_unchecked_t report_id;
39550 struct uhid_event report_buf;
39551 };
39552
39553@@ -163,7 +163,7 @@ static int uhid_hid_get_raw(struct hid_device *hid, unsigned char rnum,
39554
39555 spin_lock_irqsave(&uhid->qlock, flags);
39556 ev->type = UHID_FEATURE;
39557- ev->u.feature.id = atomic_inc_return(&uhid->report_id);
39558+ ev->u.feature.id = atomic_inc_return_unchecked(&uhid->report_id);
39559 ev->u.feature.rnum = rnum;
39560 ev->u.feature.rtype = report_type;
39561
39562@@ -446,7 +446,7 @@ static int uhid_dev_feature_answer(struct uhid_device *uhid,
39563 spin_lock_irqsave(&uhid->qlock, flags);
39564
39565 /* id for old report; drop it silently */
39566- if (atomic_read(&uhid->report_id) != ev->u.feature_answer.id)
39567+ if (atomic_read_unchecked(&uhid->report_id) != ev->u.feature_answer.id)
39568 goto unlock;
39569 if (atomic_read(&uhid->report_done))
39570 goto unlock;
39571diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
39572index 6de6c98..18319e9 100644
39573--- a/drivers/hv/channel.c
39574+++ b/drivers/hv/channel.c
39575@@ -406,8 +406,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
39576 int ret = 0;
39577 int t;
39578
39579- next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
39580- atomic_inc(&vmbus_connection.next_gpadl_handle);
39581+ next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
39582+ atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
39583
39584 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
39585 if (ret)
39586diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
39587index 88f4096..e50452e 100644
39588--- a/drivers/hv/hv.c
39589+++ b/drivers/hv/hv.c
39590@@ -112,7 +112,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
39591 u64 output_address = (output) ? virt_to_phys(output) : 0;
39592 u32 output_address_hi = output_address >> 32;
39593 u32 output_address_lo = output_address & 0xFFFFFFFF;
39594- void *hypercall_page = hv_context.hypercall_page;
39595+ void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
39596
39597 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
39598 "=a"(hv_status_lo) : "d" (control_hi),
39599diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c
39600index 7e17a54..a50a33d 100644
39601--- a/drivers/hv/hv_balloon.c
39602+++ b/drivers/hv/hv_balloon.c
39603@@ -464,7 +464,7 @@ MODULE_PARM_DESC(hot_add, "If set attempt memory hot_add");
39604
39605 module_param(pressure_report_delay, uint, (S_IRUGO | S_IWUSR));
39606 MODULE_PARM_DESC(pressure_report_delay, "Delay in secs in reporting pressure");
39607-static atomic_t trans_id = ATOMIC_INIT(0);
39608+static atomic_unchecked_t trans_id = ATOMIC_INIT(0);
39609
39610 static int dm_ring_size = (5 * PAGE_SIZE);
39611
39612@@ -886,7 +886,7 @@ static void hot_add_req(struct work_struct *dummy)
39613 pr_info("Memory hot add failed\n");
39614
39615 dm->state = DM_INITIALIZED;
39616- resp.hdr.trans_id = atomic_inc_return(&trans_id);
39617+ resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
39618 vmbus_sendpacket(dm->dev->channel, &resp,
39619 sizeof(struct dm_hot_add_response),
39620 (unsigned long)NULL,
39621@@ -960,7 +960,7 @@ static void post_status(struct hv_dynmem_device *dm)
39622 memset(&status, 0, sizeof(struct dm_status));
39623 status.hdr.type = DM_STATUS_REPORT;
39624 status.hdr.size = sizeof(struct dm_status);
39625- status.hdr.trans_id = atomic_inc_return(&trans_id);
39626+ status.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
39627
39628 /*
39629 * The host expects the guest to report free memory.
39630@@ -980,7 +980,7 @@ static void post_status(struct hv_dynmem_device *dm)
39631 * send the status. This can happen if we were interrupted
39632 * after we picked our transaction ID.
39633 */
39634- if (status.hdr.trans_id != atomic_read(&trans_id))
39635+ if (status.hdr.trans_id != atomic_read_unchecked(&trans_id))
39636 return;
39637
39638 vmbus_sendpacket(dm->dev->channel, &status,
39639@@ -1108,7 +1108,7 @@ static void balloon_up(struct work_struct *dummy)
39640 */
39641
39642 do {
39643- bl_resp->hdr.trans_id = atomic_inc_return(&trans_id);
39644+ bl_resp->hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
39645 ret = vmbus_sendpacket(dm_device.dev->channel,
39646 bl_resp,
39647 bl_resp->hdr.size,
39648@@ -1152,7 +1152,7 @@ static void balloon_down(struct hv_dynmem_device *dm,
39649
39650 memset(&resp, 0, sizeof(struct dm_unballoon_response));
39651 resp.hdr.type = DM_UNBALLOON_RESPONSE;
39652- resp.hdr.trans_id = atomic_inc_return(&trans_id);
39653+ resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
39654 resp.hdr.size = sizeof(struct dm_unballoon_response);
39655
39656 vmbus_sendpacket(dm_device.dev->channel, &resp,
39657@@ -1215,7 +1215,7 @@ static void version_resp(struct hv_dynmem_device *dm,
39658 memset(&version_req, 0, sizeof(struct dm_version_request));
39659 version_req.hdr.type = DM_VERSION_REQUEST;
39660 version_req.hdr.size = sizeof(struct dm_version_request);
39661- version_req.hdr.trans_id = atomic_inc_return(&trans_id);
39662+ version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
39663 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN7;
39664 version_req.is_last_attempt = 1;
39665
39666@@ -1385,7 +1385,7 @@ static int balloon_probe(struct hv_device *dev,
39667 memset(&version_req, 0, sizeof(struct dm_version_request));
39668 version_req.hdr.type = DM_VERSION_REQUEST;
39669 version_req.hdr.size = sizeof(struct dm_version_request);
39670- version_req.hdr.trans_id = atomic_inc_return(&trans_id);
39671+ version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
39672 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN8;
39673 version_req.is_last_attempt = 0;
39674
39675@@ -1416,7 +1416,7 @@ static int balloon_probe(struct hv_device *dev,
39676 memset(&cap_msg, 0, sizeof(struct dm_capabilities));
39677 cap_msg.hdr.type = DM_CAPABILITIES_REPORT;
39678 cap_msg.hdr.size = sizeof(struct dm_capabilities);
39679- cap_msg.hdr.trans_id = atomic_inc_return(&trans_id);
39680+ cap_msg.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
39681
39682 cap_msg.caps.cap_bits.balloon = 1;
39683 cap_msg.caps.cap_bits.hot_add = 1;
39684diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
39685index d84918f..7f38f9f 100644
39686--- a/drivers/hv/hyperv_vmbus.h
39687+++ b/drivers/hv/hyperv_vmbus.h
39688@@ -595,7 +595,7 @@ enum vmbus_connect_state {
39689 struct vmbus_connection {
39690 enum vmbus_connect_state conn_state;
39691
39692- atomic_t next_gpadl_handle;
39693+ atomic_unchecked_t next_gpadl_handle;
39694
39695 /*
39696 * Represents channel interrupts. Each bit position represents a
39697diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
39698index f9fe46f..356b119 100644
39699--- a/drivers/hv/vmbus_drv.c
39700+++ b/drivers/hv/vmbus_drv.c
39701@@ -672,10 +672,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
39702 {
39703 int ret = 0;
39704
39705- static atomic_t device_num = ATOMIC_INIT(0);
39706+ static atomic_unchecked_t device_num = ATOMIC_INIT(0);
39707
39708 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
39709- atomic_inc_return(&device_num));
39710+ atomic_inc_return_unchecked(&device_num));
39711
39712 child_device_obj->device.bus = &hv_bus;
39713 child_device_obj->device.parent = &hv_acpi_dev->dev;
39714diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
39715index a9e3d01..9dd246e 100644
39716--- a/drivers/hwmon/acpi_power_meter.c
39717+++ b/drivers/hwmon/acpi_power_meter.c
39718@@ -117,7 +117,7 @@ struct sensor_template {
39719 struct device_attribute *devattr,
39720 const char *buf, size_t count);
39721 int index;
39722-};
39723+} __do_const;
39724
39725 /* Averaging interval */
39726 static int update_avg_interval(struct acpi_power_meter_resource *resource)
39727@@ -629,7 +629,7 @@ static int register_attrs(struct acpi_power_meter_resource *resource,
39728 struct sensor_template *attrs)
39729 {
39730 struct device *dev = &resource->acpi_dev->dev;
39731- struct sensor_device_attribute *sensors =
39732+ sensor_device_attribute_no_const *sensors =
39733 &resource->sensors[resource->num_sensors];
39734 int res = 0;
39735
39736diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
39737index 3288f13..71cfb4e 100644
39738--- a/drivers/hwmon/applesmc.c
39739+++ b/drivers/hwmon/applesmc.c
39740@@ -1106,7 +1106,7 @@ static int applesmc_create_nodes(struct applesmc_node_group *groups, int num)
39741 {
39742 struct applesmc_node_group *grp;
39743 struct applesmc_dev_attr *node;
39744- struct attribute *attr;
39745+ attribute_no_const *attr;
39746 int ret, i;
39747
39748 for (grp = groups; grp->format; grp++) {
39749diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c
39750index b25c643..a13460d 100644
39751--- a/drivers/hwmon/asus_atk0110.c
39752+++ b/drivers/hwmon/asus_atk0110.c
39753@@ -152,10 +152,10 @@ MODULE_DEVICE_TABLE(acpi, atk_ids);
39754 struct atk_sensor_data {
39755 struct list_head list;
39756 struct atk_data *data;
39757- struct device_attribute label_attr;
39758- struct device_attribute input_attr;
39759- struct device_attribute limit1_attr;
39760- struct device_attribute limit2_attr;
39761+ device_attribute_no_const label_attr;
39762+ device_attribute_no_const input_attr;
39763+ device_attribute_no_const limit1_attr;
39764+ device_attribute_no_const limit2_attr;
39765 char label_attr_name[ATTR_NAME_SIZE];
39766 char input_attr_name[ATTR_NAME_SIZE];
39767 char limit1_attr_name[ATTR_NAME_SIZE];
39768@@ -275,7 +275,7 @@ static ssize_t atk_name_show(struct device *dev,
39769 static struct device_attribute atk_name_attr =
39770 __ATTR(name, 0444, atk_name_show, NULL);
39771
39772-static void atk_init_attribute(struct device_attribute *attr, char *name,
39773+static void atk_init_attribute(device_attribute_no_const *attr, char *name,
39774 sysfs_show_func show)
39775 {
39776 sysfs_attr_init(&attr->attr);
39777diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
39778index 78be661..4dd032f 100644
39779--- a/drivers/hwmon/coretemp.c
39780+++ b/drivers/hwmon/coretemp.c
39781@@ -797,7 +797,7 @@ static int coretemp_cpu_callback(struct notifier_block *nfb,
39782 return NOTIFY_OK;
39783 }
39784
39785-static struct notifier_block coretemp_cpu_notifier __refdata = {
39786+static struct notifier_block coretemp_cpu_notifier = {
39787 .notifier_call = coretemp_cpu_callback,
39788 };
39789
39790diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
39791index 632f1dc..57e6a58 100644
39792--- a/drivers/hwmon/ibmaem.c
39793+++ b/drivers/hwmon/ibmaem.c
39794@@ -926,7 +926,7 @@ static int aem_register_sensors(struct aem_data *data,
39795 struct aem_rw_sensor_template *rw)
39796 {
39797 struct device *dev = &data->pdev->dev;
39798- struct sensor_device_attribute *sensors = data->sensors;
39799+ sensor_device_attribute_no_const *sensors = data->sensors;
39800 int err;
39801
39802 /* Set up read-only sensors */
39803diff --git a/drivers/hwmon/iio_hwmon.c b/drivers/hwmon/iio_hwmon.c
39804index 708081b..fe2d4ab 100644
39805--- a/drivers/hwmon/iio_hwmon.c
39806+++ b/drivers/hwmon/iio_hwmon.c
39807@@ -73,7 +73,7 @@ static int iio_hwmon_probe(struct platform_device *pdev)
39808 {
39809 struct device *dev = &pdev->dev;
39810 struct iio_hwmon_state *st;
39811- struct sensor_device_attribute *a;
39812+ sensor_device_attribute_no_const *a;
39813 int ret, i;
39814 int in_i = 1, temp_i = 1, curr_i = 1;
39815 enum iio_chan_type type;
39816diff --git a/drivers/hwmon/nct6775.c b/drivers/hwmon/nct6775.c
39817index 6eb03ce..bea7e3e 100644
39818--- a/drivers/hwmon/nct6775.c
39819+++ b/drivers/hwmon/nct6775.c
39820@@ -936,10 +936,10 @@ static struct attribute_group *
39821 nct6775_create_attr_group(struct device *dev, struct sensor_template_group *tg,
39822 int repeat)
39823 {
39824- struct attribute_group *group;
39825+ attribute_group_no_const *group;
39826 struct sensor_device_attr_u *su;
39827- struct sensor_device_attribute *a;
39828- struct sensor_device_attribute_2 *a2;
39829+ sensor_device_attribute_no_const *a;
39830+ sensor_device_attribute_2_no_const *a2;
39831 struct attribute **attrs;
39832 struct sensor_device_template **t;
39833 int err, i, j, count;
39834diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
39835index 9319fcf..189ff45 100644
39836--- a/drivers/hwmon/pmbus/pmbus_core.c
39837+++ b/drivers/hwmon/pmbus/pmbus_core.c
39838@@ -781,7 +781,7 @@ static int pmbus_add_attribute(struct pmbus_data *data, struct attribute *attr)
39839 return 0;
39840 }
39841
39842-static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
39843+static void pmbus_dev_attr_init(device_attribute_no_const *dev_attr,
39844 const char *name,
39845 umode_t mode,
39846 ssize_t (*show)(struct device *dev,
39847@@ -798,7 +798,7 @@ static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
39848 dev_attr->store = store;
39849 }
39850
39851-static void pmbus_attr_init(struct sensor_device_attribute *a,
39852+static void pmbus_attr_init(sensor_device_attribute_no_const *a,
39853 const char *name,
39854 umode_t mode,
39855 ssize_t (*show)(struct device *dev,
39856@@ -820,7 +820,7 @@ static int pmbus_add_boolean(struct pmbus_data *data,
39857 u16 reg, u8 mask)
39858 {
39859 struct pmbus_boolean *boolean;
39860- struct sensor_device_attribute *a;
39861+ sensor_device_attribute_no_const *a;
39862
39863 boolean = devm_kzalloc(data->dev, sizeof(*boolean), GFP_KERNEL);
39864 if (!boolean)
39865@@ -845,7 +845,7 @@ static struct pmbus_sensor *pmbus_add_sensor(struct pmbus_data *data,
39866 bool update, bool readonly)
39867 {
39868 struct pmbus_sensor *sensor;
39869- struct device_attribute *a;
39870+ device_attribute_no_const *a;
39871
39872 sensor = devm_kzalloc(data->dev, sizeof(*sensor), GFP_KERNEL);
39873 if (!sensor)
39874@@ -876,7 +876,7 @@ static int pmbus_add_label(struct pmbus_data *data,
39875 const char *lstring, int index)
39876 {
39877 struct pmbus_label *label;
39878- struct device_attribute *a;
39879+ device_attribute_no_const *a;
39880
39881 label = devm_kzalloc(data->dev, sizeof(*label), GFP_KERNEL);
39882 if (!label)
39883diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
39884index 97cd45a..ac54d8b 100644
39885--- a/drivers/hwmon/sht15.c
39886+++ b/drivers/hwmon/sht15.c
39887@@ -169,7 +169,7 @@ struct sht15_data {
39888 int supply_uv;
39889 bool supply_uv_valid;
39890 struct work_struct update_supply_work;
39891- atomic_t interrupt_handled;
39892+ atomic_unchecked_t interrupt_handled;
39893 };
39894
39895 /**
39896@@ -542,13 +542,13 @@ static int sht15_measurement(struct sht15_data *data,
39897 ret = gpio_direction_input(data->pdata->gpio_data);
39898 if (ret)
39899 return ret;
39900- atomic_set(&data->interrupt_handled, 0);
39901+ atomic_set_unchecked(&data->interrupt_handled, 0);
39902
39903 enable_irq(gpio_to_irq(data->pdata->gpio_data));
39904 if (gpio_get_value(data->pdata->gpio_data) == 0) {
39905 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
39906 /* Only relevant if the interrupt hasn't occurred. */
39907- if (!atomic_read(&data->interrupt_handled))
39908+ if (!atomic_read_unchecked(&data->interrupt_handled))
39909 schedule_work(&data->read_work);
39910 }
39911 ret = wait_event_timeout(data->wait_queue,
39912@@ -820,7 +820,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
39913
39914 /* First disable the interrupt */
39915 disable_irq_nosync(irq);
39916- atomic_inc(&data->interrupt_handled);
39917+ atomic_inc_unchecked(&data->interrupt_handled);
39918 /* Then schedule a reading work struct */
39919 if (data->state != SHT15_READING_NOTHING)
39920 schedule_work(&data->read_work);
39921@@ -842,11 +842,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
39922 * If not, then start the interrupt again - care here as could
39923 * have gone low in meantime so verify it hasn't!
39924 */
39925- atomic_set(&data->interrupt_handled, 0);
39926+ atomic_set_unchecked(&data->interrupt_handled, 0);
39927 enable_irq(gpio_to_irq(data->pdata->gpio_data));
39928 /* If still not occurred or another handler was scheduled */
39929 if (gpio_get_value(data->pdata->gpio_data)
39930- || atomic_read(&data->interrupt_handled))
39931+ || atomic_read_unchecked(&data->interrupt_handled))
39932 return;
39933 }
39934
39935diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
39936index 38944e9..ae9e5ed 100644
39937--- a/drivers/hwmon/via-cputemp.c
39938+++ b/drivers/hwmon/via-cputemp.c
39939@@ -296,7 +296,7 @@ static int via_cputemp_cpu_callback(struct notifier_block *nfb,
39940 return NOTIFY_OK;
39941 }
39942
39943-static struct notifier_block via_cputemp_cpu_notifier __refdata = {
39944+static struct notifier_block via_cputemp_cpu_notifier = {
39945 .notifier_call = via_cputemp_cpu_callback,
39946 };
39947
39948diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
39949index 07f01ac..d79ad3d 100644
39950--- a/drivers/i2c/busses/i2c-amd756-s4882.c
39951+++ b/drivers/i2c/busses/i2c-amd756-s4882.c
39952@@ -43,7 +43,7 @@
39953 extern struct i2c_adapter amd756_smbus;
39954
39955 static struct i2c_adapter *s4882_adapter;
39956-static struct i2c_algorithm *s4882_algo;
39957+static i2c_algorithm_no_const *s4882_algo;
39958
39959 /* Wrapper access functions for multiplexed SMBus */
39960 static DEFINE_MUTEX(amd756_lock);
39961diff --git a/drivers/i2c/busses/i2c-diolan-u2c.c b/drivers/i2c/busses/i2c-diolan-u2c.c
39962index dae3ddf..26e21d1 100644
39963--- a/drivers/i2c/busses/i2c-diolan-u2c.c
39964+++ b/drivers/i2c/busses/i2c-diolan-u2c.c
39965@@ -99,7 +99,7 @@ MODULE_PARM_DESC(frequency, "I2C clock frequency in hertz");
39966 /* usb layer */
39967
39968 /* Send command to device, and get response. */
39969-static int diolan_usb_transfer(struct i2c_diolan_u2c *dev)
39970+static int __intentional_overflow(-1) diolan_usb_transfer(struct i2c_diolan_u2c *dev)
39971 {
39972 int ret = 0;
39973 int actual;
39974diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
39975index 2ca268d..c6acbdf 100644
39976--- a/drivers/i2c/busses/i2c-nforce2-s4985.c
39977+++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
39978@@ -41,7 +41,7 @@
39979 extern struct i2c_adapter *nforce2_smbus;
39980
39981 static struct i2c_adapter *s4985_adapter;
39982-static struct i2c_algorithm *s4985_algo;
39983+static i2c_algorithm_no_const *s4985_algo;
39984
39985 /* Wrapper access functions for multiplexed SMBus */
39986 static DEFINE_MUTEX(nforce2_lock);
39987diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
39988index c3ccdea..5b3dc1a 100644
39989--- a/drivers/i2c/i2c-dev.c
39990+++ b/drivers/i2c/i2c-dev.c
39991@@ -271,7 +271,7 @@ static noinline int i2cdev_ioctl_rdrw(struct i2c_client *client,
39992 break;
39993 }
39994
39995- data_ptrs[i] = (u8 __user *)rdwr_pa[i].buf;
39996+ data_ptrs[i] = (u8 __force_user *)rdwr_pa[i].buf;
39997 rdwr_pa[i].buf = memdup_user(data_ptrs[i], rdwr_pa[i].len);
39998 if (IS_ERR(rdwr_pa[i].buf)) {
39999 res = PTR_ERR(rdwr_pa[i].buf);
40000diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
40001index 0b510ba..4fbb5085 100644
40002--- a/drivers/ide/ide-cd.c
40003+++ b/drivers/ide/ide-cd.c
40004@@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
40005 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
40006 if ((unsigned long)buf & alignment
40007 || blk_rq_bytes(rq) & q->dma_pad_mask
40008- || object_is_on_stack(buf))
40009+ || object_starts_on_stack(buf))
40010 drive->dma = 0;
40011 }
40012 }
40013diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
40014index f95c697..0a1b05c 100644
40015--- a/drivers/iio/industrialio-core.c
40016+++ b/drivers/iio/industrialio-core.c
40017@@ -506,7 +506,7 @@ static ssize_t iio_write_channel_info(struct device *dev,
40018 }
40019
40020 static
40021-int __iio_device_attr_init(struct device_attribute *dev_attr,
40022+int __iio_device_attr_init(device_attribute_no_const *dev_attr,
40023 const char *postfix,
40024 struct iio_chan_spec const *chan,
40025 ssize_t (*readfunc)(struct device *dev,
40026diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
40027index 784b97c..c9ceadf 100644
40028--- a/drivers/infiniband/core/cm.c
40029+++ b/drivers/infiniband/core/cm.c
40030@@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
40031
40032 struct cm_counter_group {
40033 struct kobject obj;
40034- atomic_long_t counter[CM_ATTR_COUNT];
40035+ atomic_long_unchecked_t counter[CM_ATTR_COUNT];
40036 };
40037
40038 struct cm_counter_attribute {
40039@@ -1395,7 +1395,7 @@ static void cm_dup_req_handler(struct cm_work *work,
40040 struct ib_mad_send_buf *msg = NULL;
40041 int ret;
40042
40043- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40044+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40045 counter[CM_REQ_COUNTER]);
40046
40047 /* Quick state check to discard duplicate REQs. */
40048@@ -1779,7 +1779,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
40049 if (!cm_id_priv)
40050 return;
40051
40052- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40053+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40054 counter[CM_REP_COUNTER]);
40055 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
40056 if (ret)
40057@@ -1946,7 +1946,7 @@ static int cm_rtu_handler(struct cm_work *work)
40058 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
40059 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
40060 spin_unlock_irq(&cm_id_priv->lock);
40061- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40062+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40063 counter[CM_RTU_COUNTER]);
40064 goto out;
40065 }
40066@@ -2129,7 +2129,7 @@ static int cm_dreq_handler(struct cm_work *work)
40067 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
40068 dreq_msg->local_comm_id);
40069 if (!cm_id_priv) {
40070- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40071+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40072 counter[CM_DREQ_COUNTER]);
40073 cm_issue_drep(work->port, work->mad_recv_wc);
40074 return -EINVAL;
40075@@ -2154,7 +2154,7 @@ static int cm_dreq_handler(struct cm_work *work)
40076 case IB_CM_MRA_REP_RCVD:
40077 break;
40078 case IB_CM_TIMEWAIT:
40079- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40080+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40081 counter[CM_DREQ_COUNTER]);
40082 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
40083 goto unlock;
40084@@ -2168,7 +2168,7 @@ static int cm_dreq_handler(struct cm_work *work)
40085 cm_free_msg(msg);
40086 goto deref;
40087 case IB_CM_DREQ_RCVD:
40088- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40089+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40090 counter[CM_DREQ_COUNTER]);
40091 goto unlock;
40092 default:
40093@@ -2535,7 +2535,7 @@ static int cm_mra_handler(struct cm_work *work)
40094 ib_modify_mad(cm_id_priv->av.port->mad_agent,
40095 cm_id_priv->msg, timeout)) {
40096 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
40097- atomic_long_inc(&work->port->
40098+ atomic_long_inc_unchecked(&work->port->
40099 counter_group[CM_RECV_DUPLICATES].
40100 counter[CM_MRA_COUNTER]);
40101 goto out;
40102@@ -2544,7 +2544,7 @@ static int cm_mra_handler(struct cm_work *work)
40103 break;
40104 case IB_CM_MRA_REQ_RCVD:
40105 case IB_CM_MRA_REP_RCVD:
40106- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40107+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40108 counter[CM_MRA_COUNTER]);
40109 /* fall through */
40110 default:
40111@@ -2706,7 +2706,7 @@ static int cm_lap_handler(struct cm_work *work)
40112 case IB_CM_LAP_IDLE:
40113 break;
40114 case IB_CM_MRA_LAP_SENT:
40115- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40116+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40117 counter[CM_LAP_COUNTER]);
40118 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
40119 goto unlock;
40120@@ -2722,7 +2722,7 @@ static int cm_lap_handler(struct cm_work *work)
40121 cm_free_msg(msg);
40122 goto deref;
40123 case IB_CM_LAP_RCVD:
40124- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40125+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40126 counter[CM_LAP_COUNTER]);
40127 goto unlock;
40128 default:
40129@@ -3006,7 +3006,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
40130 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
40131 if (cur_cm_id_priv) {
40132 spin_unlock_irq(&cm.lock);
40133- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40134+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40135 counter[CM_SIDR_REQ_COUNTER]);
40136 goto out; /* Duplicate message. */
40137 }
40138@@ -3218,10 +3218,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
40139 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
40140 msg->retries = 1;
40141
40142- atomic_long_add(1 + msg->retries,
40143+ atomic_long_add_unchecked(1 + msg->retries,
40144 &port->counter_group[CM_XMIT].counter[attr_index]);
40145 if (msg->retries)
40146- atomic_long_add(msg->retries,
40147+ atomic_long_add_unchecked(msg->retries,
40148 &port->counter_group[CM_XMIT_RETRIES].
40149 counter[attr_index]);
40150
40151@@ -3431,7 +3431,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
40152 }
40153
40154 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
40155- atomic_long_inc(&port->counter_group[CM_RECV].
40156+ atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
40157 counter[attr_id - CM_ATTR_ID_OFFSET]);
40158
40159 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
40160@@ -3636,7 +3636,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
40161 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
40162
40163 return sprintf(buf, "%ld\n",
40164- atomic_long_read(&group->counter[cm_attr->index]));
40165+ atomic_long_read_unchecked(&group->counter[cm_attr->index]));
40166 }
40167
40168 static const struct sysfs_ops cm_counter_ops = {
40169diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
40170index 9f5ad7c..588cd84 100644
40171--- a/drivers/infiniband/core/fmr_pool.c
40172+++ b/drivers/infiniband/core/fmr_pool.c
40173@@ -98,8 +98,8 @@ struct ib_fmr_pool {
40174
40175 struct task_struct *thread;
40176
40177- atomic_t req_ser;
40178- atomic_t flush_ser;
40179+ atomic_unchecked_t req_ser;
40180+ atomic_unchecked_t flush_ser;
40181
40182 wait_queue_head_t force_wait;
40183 };
40184@@ -179,10 +179,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
40185 struct ib_fmr_pool *pool = pool_ptr;
40186
40187 do {
40188- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
40189+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
40190 ib_fmr_batch_release(pool);
40191
40192- atomic_inc(&pool->flush_ser);
40193+ atomic_inc_unchecked(&pool->flush_ser);
40194 wake_up_interruptible(&pool->force_wait);
40195
40196 if (pool->flush_function)
40197@@ -190,7 +190,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
40198 }
40199
40200 set_current_state(TASK_INTERRUPTIBLE);
40201- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
40202+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
40203 !kthread_should_stop())
40204 schedule();
40205 __set_current_state(TASK_RUNNING);
40206@@ -282,8 +282,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
40207 pool->dirty_watermark = params->dirty_watermark;
40208 pool->dirty_len = 0;
40209 spin_lock_init(&pool->pool_lock);
40210- atomic_set(&pool->req_ser, 0);
40211- atomic_set(&pool->flush_ser, 0);
40212+ atomic_set_unchecked(&pool->req_ser, 0);
40213+ atomic_set_unchecked(&pool->flush_ser, 0);
40214 init_waitqueue_head(&pool->force_wait);
40215
40216 pool->thread = kthread_run(ib_fmr_cleanup_thread,
40217@@ -411,11 +411,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
40218 }
40219 spin_unlock_irq(&pool->pool_lock);
40220
40221- serial = atomic_inc_return(&pool->req_ser);
40222+ serial = atomic_inc_return_unchecked(&pool->req_ser);
40223 wake_up_process(pool->thread);
40224
40225 if (wait_event_interruptible(pool->force_wait,
40226- atomic_read(&pool->flush_ser) - serial >= 0))
40227+ atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
40228 return -EINTR;
40229
40230 return 0;
40231@@ -525,7 +525,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
40232 } else {
40233 list_add_tail(&fmr->list, &pool->dirty_list);
40234 if (++pool->dirty_len >= pool->dirty_watermark) {
40235- atomic_inc(&pool->req_ser);
40236+ atomic_inc_unchecked(&pool->req_ser);
40237 wake_up_process(pool->thread);
40238 }
40239 }
40240diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
40241index 4cb8eb2..146bf60 100644
40242--- a/drivers/infiniband/hw/cxgb4/mem.c
40243+++ b/drivers/infiniband/hw/cxgb4/mem.c
40244@@ -249,7 +249,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
40245 int err;
40246 struct fw_ri_tpte tpt;
40247 u32 stag_idx;
40248- static atomic_t key;
40249+ static atomic_unchecked_t key;
40250
40251 if (c4iw_fatal_error(rdev))
40252 return -EIO;
40253@@ -266,7 +266,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
40254 if (rdev->stats.stag.cur > rdev->stats.stag.max)
40255 rdev->stats.stag.max = rdev->stats.stag.cur;
40256 mutex_unlock(&rdev->stats.lock);
40257- *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
40258+ *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
40259 }
40260 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
40261 __func__, stag_state, type, pdid, stag_idx);
40262diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
40263index 79b3dbc..96e5fcc 100644
40264--- a/drivers/infiniband/hw/ipath/ipath_rc.c
40265+++ b/drivers/infiniband/hw/ipath/ipath_rc.c
40266@@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
40267 struct ib_atomic_eth *ateth;
40268 struct ipath_ack_entry *e;
40269 u64 vaddr;
40270- atomic64_t *maddr;
40271+ atomic64_unchecked_t *maddr;
40272 u64 sdata;
40273 u32 rkey;
40274 u8 next;
40275@@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
40276 IB_ACCESS_REMOTE_ATOMIC)))
40277 goto nack_acc_unlck;
40278 /* Perform atomic OP and save result. */
40279- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
40280+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
40281 sdata = be64_to_cpu(ateth->swap_data);
40282 e = &qp->s_ack_queue[qp->r_head_ack_queue];
40283 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
40284- (u64) atomic64_add_return(sdata, maddr) - sdata :
40285+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
40286 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
40287 be64_to_cpu(ateth->compare_data),
40288 sdata);
40289diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
40290index 1f95bba..9530f87 100644
40291--- a/drivers/infiniband/hw/ipath/ipath_ruc.c
40292+++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
40293@@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
40294 unsigned long flags;
40295 struct ib_wc wc;
40296 u64 sdata;
40297- atomic64_t *maddr;
40298+ atomic64_unchecked_t *maddr;
40299 enum ib_wc_status send_status;
40300
40301 /*
40302@@ -382,11 +382,11 @@ again:
40303 IB_ACCESS_REMOTE_ATOMIC)))
40304 goto acc_err;
40305 /* Perform atomic OP and save result. */
40306- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
40307+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
40308 sdata = wqe->wr.wr.atomic.compare_add;
40309 *(u64 *) sqp->s_sge.sge.vaddr =
40310 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
40311- (u64) atomic64_add_return(sdata, maddr) - sdata :
40312+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
40313 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
40314 sdata, wqe->wr.wr.atomic.swap);
40315 goto send_comp;
40316diff --git a/drivers/infiniband/hw/mlx4/mad.c b/drivers/infiniband/hw/mlx4/mad.c
40317index f2a3f48..673ec79 100644
40318--- a/drivers/infiniband/hw/mlx4/mad.c
40319+++ b/drivers/infiniband/hw/mlx4/mad.c
40320@@ -98,7 +98,7 @@ __be64 mlx4_ib_gen_node_guid(void)
40321
40322 __be64 mlx4_ib_get_new_demux_tid(struct mlx4_ib_demux_ctx *ctx)
40323 {
40324- return cpu_to_be64(atomic_inc_return(&ctx->tid)) |
40325+ return cpu_to_be64(atomic_inc_return_unchecked(&ctx->tid)) |
40326 cpu_to_be64(0xff00000000000000LL);
40327 }
40328
40329diff --git a/drivers/infiniband/hw/mlx4/mcg.c b/drivers/infiniband/hw/mlx4/mcg.c
40330index 25b2cdf..099ff97 100644
40331--- a/drivers/infiniband/hw/mlx4/mcg.c
40332+++ b/drivers/infiniband/hw/mlx4/mcg.c
40333@@ -1040,7 +1040,7 @@ int mlx4_ib_mcg_port_init(struct mlx4_ib_demux_ctx *ctx)
40334 {
40335 char name[20];
40336
40337- atomic_set(&ctx->tid, 0);
40338+ atomic_set_unchecked(&ctx->tid, 0);
40339 sprintf(name, "mlx4_ib_mcg%d", ctx->port);
40340 ctx->mcg_wq = create_singlethread_workqueue(name);
40341 if (!ctx->mcg_wq)
40342diff --git a/drivers/infiniband/hw/mlx4/mlx4_ib.h b/drivers/infiniband/hw/mlx4/mlx4_ib.h
40343index 036b663..c9a8c73 100644
40344--- a/drivers/infiniband/hw/mlx4/mlx4_ib.h
40345+++ b/drivers/infiniband/hw/mlx4/mlx4_ib.h
40346@@ -404,7 +404,7 @@ struct mlx4_ib_demux_ctx {
40347 struct list_head mcg_mgid0_list;
40348 struct workqueue_struct *mcg_wq;
40349 struct mlx4_ib_demux_pv_ctx **tun;
40350- atomic_t tid;
40351+ atomic_unchecked_t tid;
40352 int flushing; /* flushing the work queue */
40353 };
40354
40355diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c
40356index 9d3e5c1..6f166df 100644
40357--- a/drivers/infiniband/hw/mthca/mthca_cmd.c
40358+++ b/drivers/infiniband/hw/mthca/mthca_cmd.c
40359@@ -772,7 +772,7 @@ static void mthca_setup_cmd_doorbells(struct mthca_dev *dev, u64 base)
40360 mthca_dbg(dev, "Mapped doorbell page for posting FW commands\n");
40361 }
40362
40363-int mthca_QUERY_FW(struct mthca_dev *dev)
40364+int __intentional_overflow(-1) mthca_QUERY_FW(struct mthca_dev *dev)
40365 {
40366 struct mthca_mailbox *mailbox;
40367 u32 *outbox;
40368@@ -1612,7 +1612,7 @@ int mthca_HW2SW_MPT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
40369 CMD_TIME_CLASS_B);
40370 }
40371
40372-int mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
40373+int __intentional_overflow(-1) mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
40374 int num_mtt)
40375 {
40376 return mthca_cmd(dev, mailbox->dma, num_mtt, 0, CMD_WRITE_MTT,
40377@@ -1634,7 +1634,7 @@ int mthca_MAP_EQ(struct mthca_dev *dev, u64 event_mask, int unmap,
40378 0, CMD_MAP_EQ, CMD_TIME_CLASS_B);
40379 }
40380
40381-int mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
40382+int __intentional_overflow(-1) mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
40383 int eq_num)
40384 {
40385 return mthca_cmd(dev, mailbox->dma, eq_num, 0, CMD_SW2HW_EQ,
40386@@ -1857,7 +1857,7 @@ int mthca_CONF_SPECIAL_QP(struct mthca_dev *dev, int type, u32 qpn)
40387 CMD_TIME_CLASS_B);
40388 }
40389
40390-int mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
40391+int __intentional_overflow(-1) mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
40392 int port, struct ib_wc *in_wc, struct ib_grh *in_grh,
40393 void *in_mad, void *response_mad)
40394 {
40395diff --git a/drivers/infiniband/hw/mthca/mthca_main.c b/drivers/infiniband/hw/mthca/mthca_main.c
40396index 87897b9..7e79542 100644
40397--- a/drivers/infiniband/hw/mthca/mthca_main.c
40398+++ b/drivers/infiniband/hw/mthca/mthca_main.c
40399@@ -692,7 +692,7 @@ err_close:
40400 return err;
40401 }
40402
40403-static int mthca_setup_hca(struct mthca_dev *dev)
40404+static int __intentional_overflow(-1) mthca_setup_hca(struct mthca_dev *dev)
40405 {
40406 int err;
40407
40408diff --git a/drivers/infiniband/hw/mthca/mthca_mr.c b/drivers/infiniband/hw/mthca/mthca_mr.c
40409index ed9a989..6aa5dc2 100644
40410--- a/drivers/infiniband/hw/mthca/mthca_mr.c
40411+++ b/drivers/infiniband/hw/mthca/mthca_mr.c
40412@@ -81,7 +81,7 @@ struct mthca_mpt_entry {
40413 * through the bitmaps)
40414 */
40415
40416-static u32 mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
40417+static u32 __intentional_overflow(-1) mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
40418 {
40419 int o;
40420 int m;
40421@@ -426,7 +426,7 @@ static inline u32 adjust_key(struct mthca_dev *dev, u32 key)
40422 return key;
40423 }
40424
40425-int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
40426+int __intentional_overflow(-1) mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
40427 u64 iova, u64 total_size, u32 access, struct mthca_mr *mr)
40428 {
40429 struct mthca_mailbox *mailbox;
40430@@ -516,7 +516,7 @@ int mthca_mr_alloc_notrans(struct mthca_dev *dev, u32 pd,
40431 return mthca_mr_alloc(dev, pd, 12, 0, ~0ULL, access, mr);
40432 }
40433
40434-int mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
40435+int __intentional_overflow(-1) mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
40436 u64 *buffer_list, int buffer_size_shift,
40437 int list_len, u64 iova, u64 total_size,
40438 u32 access, struct mthca_mr *mr)
40439diff --git a/drivers/infiniband/hw/mthca/mthca_provider.c b/drivers/infiniband/hw/mthca/mthca_provider.c
40440index 5b71d43..35a9e14 100644
40441--- a/drivers/infiniband/hw/mthca/mthca_provider.c
40442+++ b/drivers/infiniband/hw/mthca/mthca_provider.c
40443@@ -763,7 +763,7 @@ unlock:
40444 return 0;
40445 }
40446
40447-static int mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
40448+static int __intentional_overflow(-1) mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
40449 {
40450 struct mthca_dev *dev = to_mdev(ibcq->device);
40451 struct mthca_cq *cq = to_mcq(ibcq);
40452diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
40453index 4291410..d2ab1fb 100644
40454--- a/drivers/infiniband/hw/nes/nes.c
40455+++ b/drivers/infiniband/hw/nes/nes.c
40456@@ -98,7 +98,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
40457 LIST_HEAD(nes_adapter_list);
40458 static LIST_HEAD(nes_dev_list);
40459
40460-atomic_t qps_destroyed;
40461+atomic_unchecked_t qps_destroyed;
40462
40463 static unsigned int ee_flsh_adapter;
40464 static unsigned int sysfs_nonidx_addr;
40465@@ -269,7 +269,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
40466 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
40467 struct nes_adapter *nesadapter = nesdev->nesadapter;
40468
40469- atomic_inc(&qps_destroyed);
40470+ atomic_inc_unchecked(&qps_destroyed);
40471
40472 /* Free the control structures */
40473
40474diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
40475index 33cc589..3bd6538 100644
40476--- a/drivers/infiniband/hw/nes/nes.h
40477+++ b/drivers/infiniband/hw/nes/nes.h
40478@@ -177,17 +177,17 @@ extern unsigned int nes_debug_level;
40479 extern unsigned int wqm_quanta;
40480 extern struct list_head nes_adapter_list;
40481
40482-extern atomic_t cm_connects;
40483-extern atomic_t cm_accepts;
40484-extern atomic_t cm_disconnects;
40485-extern atomic_t cm_closes;
40486-extern atomic_t cm_connecteds;
40487-extern atomic_t cm_connect_reqs;
40488-extern atomic_t cm_rejects;
40489-extern atomic_t mod_qp_timouts;
40490-extern atomic_t qps_created;
40491-extern atomic_t qps_destroyed;
40492-extern atomic_t sw_qps_destroyed;
40493+extern atomic_unchecked_t cm_connects;
40494+extern atomic_unchecked_t cm_accepts;
40495+extern atomic_unchecked_t cm_disconnects;
40496+extern atomic_unchecked_t cm_closes;
40497+extern atomic_unchecked_t cm_connecteds;
40498+extern atomic_unchecked_t cm_connect_reqs;
40499+extern atomic_unchecked_t cm_rejects;
40500+extern atomic_unchecked_t mod_qp_timouts;
40501+extern atomic_unchecked_t qps_created;
40502+extern atomic_unchecked_t qps_destroyed;
40503+extern atomic_unchecked_t sw_qps_destroyed;
40504 extern u32 mh_detected;
40505 extern u32 mh_pauses_sent;
40506 extern u32 cm_packets_sent;
40507@@ -196,16 +196,16 @@ extern u32 cm_packets_created;
40508 extern u32 cm_packets_received;
40509 extern u32 cm_packets_dropped;
40510 extern u32 cm_packets_retrans;
40511-extern atomic_t cm_listens_created;
40512-extern atomic_t cm_listens_destroyed;
40513+extern atomic_unchecked_t cm_listens_created;
40514+extern atomic_unchecked_t cm_listens_destroyed;
40515 extern u32 cm_backlog_drops;
40516-extern atomic_t cm_loopbacks;
40517-extern atomic_t cm_nodes_created;
40518-extern atomic_t cm_nodes_destroyed;
40519-extern atomic_t cm_accel_dropped_pkts;
40520-extern atomic_t cm_resets_recvd;
40521-extern atomic_t pau_qps_created;
40522-extern atomic_t pau_qps_destroyed;
40523+extern atomic_unchecked_t cm_loopbacks;
40524+extern atomic_unchecked_t cm_nodes_created;
40525+extern atomic_unchecked_t cm_nodes_destroyed;
40526+extern atomic_unchecked_t cm_accel_dropped_pkts;
40527+extern atomic_unchecked_t cm_resets_recvd;
40528+extern atomic_unchecked_t pau_qps_created;
40529+extern atomic_unchecked_t pau_qps_destroyed;
40530
40531 extern u32 int_mod_timer_init;
40532 extern u32 int_mod_cq_depth_256;
40533diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
40534index 6b29249..57081dd 100644
40535--- a/drivers/infiniband/hw/nes/nes_cm.c
40536+++ b/drivers/infiniband/hw/nes/nes_cm.c
40537@@ -68,14 +68,14 @@ u32 cm_packets_dropped;
40538 u32 cm_packets_retrans;
40539 u32 cm_packets_created;
40540 u32 cm_packets_received;
40541-atomic_t cm_listens_created;
40542-atomic_t cm_listens_destroyed;
40543+atomic_unchecked_t cm_listens_created;
40544+atomic_unchecked_t cm_listens_destroyed;
40545 u32 cm_backlog_drops;
40546-atomic_t cm_loopbacks;
40547-atomic_t cm_nodes_created;
40548-atomic_t cm_nodes_destroyed;
40549-atomic_t cm_accel_dropped_pkts;
40550-atomic_t cm_resets_recvd;
40551+atomic_unchecked_t cm_loopbacks;
40552+atomic_unchecked_t cm_nodes_created;
40553+atomic_unchecked_t cm_nodes_destroyed;
40554+atomic_unchecked_t cm_accel_dropped_pkts;
40555+atomic_unchecked_t cm_resets_recvd;
40556
40557 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
40558 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
40559@@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
40560
40561 static struct nes_cm_core *g_cm_core;
40562
40563-atomic_t cm_connects;
40564-atomic_t cm_accepts;
40565-atomic_t cm_disconnects;
40566-atomic_t cm_closes;
40567-atomic_t cm_connecteds;
40568-atomic_t cm_connect_reqs;
40569-atomic_t cm_rejects;
40570+atomic_unchecked_t cm_connects;
40571+atomic_unchecked_t cm_accepts;
40572+atomic_unchecked_t cm_disconnects;
40573+atomic_unchecked_t cm_closes;
40574+atomic_unchecked_t cm_connecteds;
40575+atomic_unchecked_t cm_connect_reqs;
40576+atomic_unchecked_t cm_rejects;
40577
40578 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
40579 {
40580@@ -1272,7 +1272,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
40581 kfree(listener);
40582 listener = NULL;
40583 ret = 0;
40584- atomic_inc(&cm_listens_destroyed);
40585+ atomic_inc_unchecked(&cm_listens_destroyed);
40586 } else {
40587 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
40588 }
40589@@ -1466,7 +1466,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
40590 cm_node->rem_mac);
40591
40592 add_hte_node(cm_core, cm_node);
40593- atomic_inc(&cm_nodes_created);
40594+ atomic_inc_unchecked(&cm_nodes_created);
40595
40596 return cm_node;
40597 }
40598@@ -1524,7 +1524,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
40599 }
40600
40601 atomic_dec(&cm_core->node_cnt);
40602- atomic_inc(&cm_nodes_destroyed);
40603+ atomic_inc_unchecked(&cm_nodes_destroyed);
40604 nesqp = cm_node->nesqp;
40605 if (nesqp) {
40606 nesqp->cm_node = NULL;
40607@@ -1588,7 +1588,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
40608
40609 static void drop_packet(struct sk_buff *skb)
40610 {
40611- atomic_inc(&cm_accel_dropped_pkts);
40612+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
40613 dev_kfree_skb_any(skb);
40614 }
40615
40616@@ -1651,7 +1651,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
40617 {
40618
40619 int reset = 0; /* whether to send reset in case of err.. */
40620- atomic_inc(&cm_resets_recvd);
40621+ atomic_inc_unchecked(&cm_resets_recvd);
40622 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
40623 " refcnt=%d\n", cm_node, cm_node->state,
40624 atomic_read(&cm_node->ref_count));
40625@@ -2292,7 +2292,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
40626 rem_ref_cm_node(cm_node->cm_core, cm_node);
40627 return NULL;
40628 }
40629- atomic_inc(&cm_loopbacks);
40630+ atomic_inc_unchecked(&cm_loopbacks);
40631 loopbackremotenode->loopbackpartner = cm_node;
40632 loopbackremotenode->tcp_cntxt.rcv_wscale =
40633 NES_CM_DEFAULT_RCV_WND_SCALE;
40634@@ -2567,7 +2567,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
40635 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
40636 else {
40637 rem_ref_cm_node(cm_core, cm_node);
40638- atomic_inc(&cm_accel_dropped_pkts);
40639+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
40640 dev_kfree_skb_any(skb);
40641 }
40642 break;
40643@@ -2875,7 +2875,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
40644
40645 if ((cm_id) && (cm_id->event_handler)) {
40646 if (issue_disconn) {
40647- atomic_inc(&cm_disconnects);
40648+ atomic_inc_unchecked(&cm_disconnects);
40649 cm_event.event = IW_CM_EVENT_DISCONNECT;
40650 cm_event.status = disconn_status;
40651 cm_event.local_addr = cm_id->local_addr;
40652@@ -2897,7 +2897,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
40653 }
40654
40655 if (issue_close) {
40656- atomic_inc(&cm_closes);
40657+ atomic_inc_unchecked(&cm_closes);
40658 nes_disconnect(nesqp, 1);
40659
40660 cm_id->provider_data = nesqp;
40661@@ -3035,7 +3035,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
40662
40663 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
40664 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
40665- atomic_inc(&cm_accepts);
40666+ atomic_inc_unchecked(&cm_accepts);
40667
40668 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
40669 netdev_refcnt_read(nesvnic->netdev));
40670@@ -3224,7 +3224,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
40671 struct nes_cm_core *cm_core;
40672 u8 *start_buff;
40673
40674- atomic_inc(&cm_rejects);
40675+ atomic_inc_unchecked(&cm_rejects);
40676 cm_node = (struct nes_cm_node *)cm_id->provider_data;
40677 loopback = cm_node->loopbackpartner;
40678 cm_core = cm_node->cm_core;
40679@@ -3286,7 +3286,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
40680 ntohs(raddr->sin_port), ntohl(laddr->sin_addr.s_addr),
40681 ntohs(laddr->sin_port));
40682
40683- atomic_inc(&cm_connects);
40684+ atomic_inc_unchecked(&cm_connects);
40685 nesqp->active_conn = 1;
40686
40687 /* cache the cm_id in the qp */
40688@@ -3398,7 +3398,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
40689 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
40690 return err;
40691 }
40692- atomic_inc(&cm_listens_created);
40693+ atomic_inc_unchecked(&cm_listens_created);
40694 }
40695
40696 cm_id->add_ref(cm_id);
40697@@ -3505,7 +3505,7 @@ static void cm_event_connected(struct nes_cm_event *event)
40698
40699 if (nesqp->destroyed)
40700 return;
40701- atomic_inc(&cm_connecteds);
40702+ atomic_inc_unchecked(&cm_connecteds);
40703 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
40704 " local port 0x%04X. jiffies = %lu.\n",
40705 nesqp->hwqp.qp_id, ntohl(raddr->sin_addr.s_addr),
40706@@ -3686,7 +3686,7 @@ static void cm_event_reset(struct nes_cm_event *event)
40707
40708 cm_id->add_ref(cm_id);
40709 ret = cm_id->event_handler(cm_id, &cm_event);
40710- atomic_inc(&cm_closes);
40711+ atomic_inc_unchecked(&cm_closes);
40712 cm_event.event = IW_CM_EVENT_CLOSE;
40713 cm_event.status = 0;
40714 cm_event.provider_data = cm_id->provider_data;
40715@@ -3726,7 +3726,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
40716 return;
40717 cm_id = cm_node->cm_id;
40718
40719- atomic_inc(&cm_connect_reqs);
40720+ atomic_inc_unchecked(&cm_connect_reqs);
40721 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
40722 cm_node, cm_id, jiffies);
40723
40724@@ -3770,7 +3770,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
40725 return;
40726 cm_id = cm_node->cm_id;
40727
40728- atomic_inc(&cm_connect_reqs);
40729+ atomic_inc_unchecked(&cm_connect_reqs);
40730 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
40731 cm_node, cm_id, jiffies);
40732
40733diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
40734index 4166452..fc952c3 100644
40735--- a/drivers/infiniband/hw/nes/nes_mgt.c
40736+++ b/drivers/infiniband/hw/nes/nes_mgt.c
40737@@ -40,8 +40,8 @@
40738 #include "nes.h"
40739 #include "nes_mgt.h"
40740
40741-atomic_t pau_qps_created;
40742-atomic_t pau_qps_destroyed;
40743+atomic_unchecked_t pau_qps_created;
40744+atomic_unchecked_t pau_qps_destroyed;
40745
40746 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
40747 {
40748@@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
40749 {
40750 struct sk_buff *skb;
40751 unsigned long flags;
40752- atomic_inc(&pau_qps_destroyed);
40753+ atomic_inc_unchecked(&pau_qps_destroyed);
40754
40755 /* Free packets that have not yet been forwarded */
40756 /* Lock is acquired by skb_dequeue when removing the skb */
40757@@ -810,7 +810,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
40758 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
40759 skb_queue_head_init(&nesqp->pau_list);
40760 spin_lock_init(&nesqp->pau_lock);
40761- atomic_inc(&pau_qps_created);
40762+ atomic_inc_unchecked(&pau_qps_created);
40763 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
40764 }
40765
40766diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
40767index 49eb511..a774366 100644
40768--- a/drivers/infiniband/hw/nes/nes_nic.c
40769+++ b/drivers/infiniband/hw/nes/nes_nic.c
40770@@ -1273,39 +1273,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
40771 target_stat_values[++index] = mh_detected;
40772 target_stat_values[++index] = mh_pauses_sent;
40773 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
40774- target_stat_values[++index] = atomic_read(&cm_connects);
40775- target_stat_values[++index] = atomic_read(&cm_accepts);
40776- target_stat_values[++index] = atomic_read(&cm_disconnects);
40777- target_stat_values[++index] = atomic_read(&cm_connecteds);
40778- target_stat_values[++index] = atomic_read(&cm_connect_reqs);
40779- target_stat_values[++index] = atomic_read(&cm_rejects);
40780- target_stat_values[++index] = atomic_read(&mod_qp_timouts);
40781- target_stat_values[++index] = atomic_read(&qps_created);
40782- target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
40783- target_stat_values[++index] = atomic_read(&qps_destroyed);
40784- target_stat_values[++index] = atomic_read(&cm_closes);
40785+ target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
40786+ target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
40787+ target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
40788+ target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
40789+ target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
40790+ target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
40791+ target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
40792+ target_stat_values[++index] = atomic_read_unchecked(&qps_created);
40793+ target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
40794+ target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
40795+ target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
40796 target_stat_values[++index] = cm_packets_sent;
40797 target_stat_values[++index] = cm_packets_bounced;
40798 target_stat_values[++index] = cm_packets_created;
40799 target_stat_values[++index] = cm_packets_received;
40800 target_stat_values[++index] = cm_packets_dropped;
40801 target_stat_values[++index] = cm_packets_retrans;
40802- target_stat_values[++index] = atomic_read(&cm_listens_created);
40803- target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
40804+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
40805+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
40806 target_stat_values[++index] = cm_backlog_drops;
40807- target_stat_values[++index] = atomic_read(&cm_loopbacks);
40808- target_stat_values[++index] = atomic_read(&cm_nodes_created);
40809- target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
40810- target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
40811- target_stat_values[++index] = atomic_read(&cm_resets_recvd);
40812+ target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
40813+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
40814+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
40815+ target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
40816+ target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
40817 target_stat_values[++index] = nesadapter->free_4kpbl;
40818 target_stat_values[++index] = nesadapter->free_256pbl;
40819 target_stat_values[++index] = int_mod_timer_init;
40820 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
40821 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
40822 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
40823- target_stat_values[++index] = atomic_read(&pau_qps_created);
40824- target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
40825+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
40826+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
40827 }
40828
40829 /**
40830diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
40831index 5b53ca5..443da3c 100644
40832--- a/drivers/infiniband/hw/nes/nes_verbs.c
40833+++ b/drivers/infiniband/hw/nes/nes_verbs.c
40834@@ -46,9 +46,9 @@
40835
40836 #include <rdma/ib_umem.h>
40837
40838-atomic_t mod_qp_timouts;
40839-atomic_t qps_created;
40840-atomic_t sw_qps_destroyed;
40841+atomic_unchecked_t mod_qp_timouts;
40842+atomic_unchecked_t qps_created;
40843+atomic_unchecked_t sw_qps_destroyed;
40844
40845 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
40846
40847@@ -1134,7 +1134,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
40848 if (init_attr->create_flags)
40849 return ERR_PTR(-EINVAL);
40850
40851- atomic_inc(&qps_created);
40852+ atomic_inc_unchecked(&qps_created);
40853 switch (init_attr->qp_type) {
40854 case IB_QPT_RC:
40855 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
40856@@ -1466,7 +1466,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
40857 struct iw_cm_event cm_event;
40858 int ret = 0;
40859
40860- atomic_inc(&sw_qps_destroyed);
40861+ atomic_inc_unchecked(&sw_qps_destroyed);
40862 nesqp->destroyed = 1;
40863
40864 /* Blow away the connection if it exists. */
40865diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
40866index 1946101..09766d2 100644
40867--- a/drivers/infiniband/hw/qib/qib.h
40868+++ b/drivers/infiniband/hw/qib/qib.h
40869@@ -52,6 +52,7 @@
40870 #include <linux/kref.h>
40871 #include <linux/sched.h>
40872 #include <linux/kthread.h>
40873+#include <linux/slab.h>
40874
40875 #include "qib_common.h"
40876 #include "qib_verbs.h"
40877diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
40878index 922a7fe..bb035db 100644
40879--- a/drivers/input/gameport/gameport.c
40880+++ b/drivers/input/gameport/gameport.c
40881@@ -487,14 +487,14 @@ EXPORT_SYMBOL(gameport_set_phys);
40882 */
40883 static void gameport_init_port(struct gameport *gameport)
40884 {
40885- static atomic_t gameport_no = ATOMIC_INIT(0);
40886+ static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
40887
40888 __module_get(THIS_MODULE);
40889
40890 mutex_init(&gameport->drv_mutex);
40891 device_initialize(&gameport->dev);
40892 dev_set_name(&gameport->dev, "gameport%lu",
40893- (unsigned long)atomic_inc_return(&gameport_no) - 1);
40894+ (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
40895 gameport->dev.bus = &gameport_bus;
40896 gameport->dev.release = gameport_release_port;
40897 if (gameport->parent)
40898diff --git a/drivers/input/input.c b/drivers/input/input.c
40899index e75d015..57d1c28 100644
40900--- a/drivers/input/input.c
40901+++ b/drivers/input/input.c
40902@@ -1734,7 +1734,7 @@ EXPORT_SYMBOL_GPL(input_class);
40903 */
40904 struct input_dev *input_allocate_device(void)
40905 {
40906- static atomic_t input_no = ATOMIC_INIT(0);
40907+ static atomic_unchecked_t input_no = ATOMIC_INIT(0);
40908 struct input_dev *dev;
40909
40910 dev = kzalloc(sizeof(struct input_dev), GFP_KERNEL);
40911@@ -1749,7 +1749,7 @@ struct input_dev *input_allocate_device(void)
40912 INIT_LIST_HEAD(&dev->node);
40913
40914 dev_set_name(&dev->dev, "input%ld",
40915- (unsigned long) atomic_inc_return(&input_no) - 1);
40916+ (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
40917
40918 __module_get(THIS_MODULE);
40919 }
40920diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
40921index 04c69af..5f92d00 100644
40922--- a/drivers/input/joystick/sidewinder.c
40923+++ b/drivers/input/joystick/sidewinder.c
40924@@ -30,6 +30,7 @@
40925 #include <linux/kernel.h>
40926 #include <linux/module.h>
40927 #include <linux/slab.h>
40928+#include <linux/sched.h>
40929 #include <linux/init.h>
40930 #include <linux/input.h>
40931 #include <linux/gameport.h>
40932diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
40933index 75e3b10..fb390fd 100644
40934--- a/drivers/input/joystick/xpad.c
40935+++ b/drivers/input/joystick/xpad.c
40936@@ -736,7 +736,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
40937
40938 static int xpad_led_probe(struct usb_xpad *xpad)
40939 {
40940- static atomic_t led_seq = ATOMIC_INIT(0);
40941+ static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
40942 long led_no;
40943 struct xpad_led *led;
40944 struct led_classdev *led_cdev;
40945@@ -749,7 +749,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
40946 if (!led)
40947 return -ENOMEM;
40948
40949- led_no = (long)atomic_inc_return(&led_seq) - 1;
40950+ led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
40951
40952 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
40953 led->xpad = xpad;
40954diff --git a/drivers/input/misc/ims-pcu.c b/drivers/input/misc/ims-pcu.c
40955index e204f26..8459f15 100644
40956--- a/drivers/input/misc/ims-pcu.c
40957+++ b/drivers/input/misc/ims-pcu.c
40958@@ -1621,7 +1621,7 @@ static int ims_pcu_identify_type(struct ims_pcu *pcu, u8 *device_id)
40959
40960 static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
40961 {
40962- static atomic_t device_no = ATOMIC_INIT(0);
40963+ static atomic_unchecked_t device_no = ATOMIC_INIT(0);
40964
40965 const struct ims_pcu_device_info *info;
40966 u8 device_id;
40967@@ -1653,7 +1653,7 @@ static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
40968 }
40969
40970 /* Device appears to be operable, complete initialization */
40971- pcu->device_no = atomic_inc_return(&device_no) - 1;
40972+ pcu->device_no = atomic_inc_return_unchecked(&device_no) - 1;
40973
40974 error = ims_pcu_setup_backlight(pcu);
40975 if (error)
40976diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
40977index 2f0b39d..7370f13 100644
40978--- a/drivers/input/mouse/psmouse.h
40979+++ b/drivers/input/mouse/psmouse.h
40980@@ -116,7 +116,7 @@ struct psmouse_attribute {
40981 ssize_t (*set)(struct psmouse *psmouse, void *data,
40982 const char *buf, size_t count);
40983 bool protect;
40984-};
40985+} __do_const;
40986 #define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr)
40987
40988 ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *attr,
40989diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
40990index 4c842c3..590b0bf 100644
40991--- a/drivers/input/mousedev.c
40992+++ b/drivers/input/mousedev.c
40993@@ -738,7 +738,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
40994
40995 spin_unlock_irq(&client->packet_lock);
40996
40997- if (copy_to_user(buffer, data, count))
40998+ if (count > sizeof(data) || copy_to_user(buffer, data, count))
40999 return -EFAULT;
41000
41001 return count;
41002diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
41003index 2b56855..5a55837 100644
41004--- a/drivers/input/serio/serio.c
41005+++ b/drivers/input/serio/serio.c
41006@@ -496,7 +496,7 @@ static void serio_release_port(struct device *dev)
41007 */
41008 static void serio_init_port(struct serio *serio)
41009 {
41010- static atomic_t serio_no = ATOMIC_INIT(0);
41011+ static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
41012
41013 __module_get(THIS_MODULE);
41014
41015@@ -507,7 +507,7 @@ static void serio_init_port(struct serio *serio)
41016 mutex_init(&serio->drv_mutex);
41017 device_initialize(&serio->dev);
41018 dev_set_name(&serio->dev, "serio%ld",
41019- (long)atomic_inc_return(&serio_no) - 1);
41020+ (long)atomic_inc_return_unchecked(&serio_no) - 1);
41021 serio->dev.bus = &serio_bus;
41022 serio->dev.release = serio_release_port;
41023 serio->dev.groups = serio_device_attr_groups;
41024diff --git a/drivers/input/serio/serio_raw.c b/drivers/input/serio/serio_raw.c
41025index 59df2e7..8f1cafb 100644
41026--- a/drivers/input/serio/serio_raw.c
41027+++ b/drivers/input/serio/serio_raw.c
41028@@ -293,7 +293,7 @@ static irqreturn_t serio_raw_interrupt(struct serio *serio, unsigned char data,
41029
41030 static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
41031 {
41032- static atomic_t serio_raw_no = ATOMIC_INIT(0);
41033+ static atomic_unchecked_t serio_raw_no = ATOMIC_INIT(0);
41034 struct serio_raw *serio_raw;
41035 int err;
41036
41037@@ -304,7 +304,7 @@ static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
41038 }
41039
41040 snprintf(serio_raw->name, sizeof(serio_raw->name),
41041- "serio_raw%ld", (long)atomic_inc_return(&serio_raw_no) - 1);
41042+ "serio_raw%ld", (long)atomic_inc_return_unchecked(&serio_raw_no) - 1);
41043 kref_init(&serio_raw->kref);
41044 INIT_LIST_HEAD(&serio_raw->client_list);
41045 init_waitqueue_head(&serio_raw->wait);
41046diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
41047index fbe9ca7..dbee61d 100644
41048--- a/drivers/iommu/iommu.c
41049+++ b/drivers/iommu/iommu.c
41050@@ -583,7 +583,7 @@ static struct notifier_block iommu_bus_nb = {
41051 static void iommu_bus_init(struct bus_type *bus, struct iommu_ops *ops)
41052 {
41053 bus_register_notifier(bus, &iommu_bus_nb);
41054- bus_for_each_dev(bus, NULL, ops, add_iommu_group);
41055+ bus_for_each_dev(bus, NULL, (void *)ops, add_iommu_group);
41056 }
41057
41058 /**
41059diff --git a/drivers/iommu/irq_remapping.c b/drivers/iommu/irq_remapping.c
41060index 39f81ae..2660096 100644
41061--- a/drivers/iommu/irq_remapping.c
41062+++ b/drivers/iommu/irq_remapping.c
41063@@ -356,7 +356,7 @@ int setup_hpet_msi_remapped(unsigned int irq, unsigned int id)
41064 void panic_if_irq_remap(const char *msg)
41065 {
41066 if (irq_remapping_enabled)
41067- panic(msg);
41068+ panic("%s", msg);
41069 }
41070
41071 static void ir_ack_apic_edge(struct irq_data *data)
41072@@ -377,10 +377,12 @@ static void ir_print_prefix(struct irq_data *data, struct seq_file *p)
41073
41074 void irq_remap_modify_chip_defaults(struct irq_chip *chip)
41075 {
41076- chip->irq_print_chip = ir_print_prefix;
41077- chip->irq_ack = ir_ack_apic_edge;
41078- chip->irq_eoi = ir_ack_apic_level;
41079- chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
41080+ pax_open_kernel();
41081+ *(void **)&chip->irq_print_chip = ir_print_prefix;
41082+ *(void **)&chip->irq_ack = ir_ack_apic_edge;
41083+ *(void **)&chip->irq_eoi = ir_ack_apic_level;
41084+ *(void **)&chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
41085+ pax_close_kernel();
41086 }
41087
41088 bool setup_remapped_irq(int irq, struct irq_cfg *cfg, struct irq_chip *chip)
41089diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c
41090index d0e9480..d2b6340 100644
41091--- a/drivers/irqchip/irq-gic.c
41092+++ b/drivers/irqchip/irq-gic.c
41093@@ -84,7 +84,7 @@ static u8 gic_cpu_map[NR_GIC_CPU_IF] __read_mostly;
41094 * Supported arch specific GIC irq extension.
41095 * Default make them NULL.
41096 */
41097-struct irq_chip gic_arch_extn = {
41098+irq_chip_no_const gic_arch_extn = {
41099 .irq_eoi = NULL,
41100 .irq_mask = NULL,
41101 .irq_unmask = NULL,
41102@@ -333,7 +333,7 @@ static void gic_handle_cascade_irq(unsigned int irq, struct irq_desc *desc)
41103 chained_irq_exit(chip, desc);
41104 }
41105
41106-static struct irq_chip gic_chip = {
41107+static irq_chip_no_const gic_chip __read_only = {
41108 .name = "GIC",
41109 .irq_mask = gic_mask_irq,
41110 .irq_unmask = gic_unmask_irq,
41111diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
41112index ac6f72b..81150f2 100644
41113--- a/drivers/isdn/capi/capi.c
41114+++ b/drivers/isdn/capi/capi.c
41115@@ -81,8 +81,8 @@ struct capiminor {
41116
41117 struct capi20_appl *ap;
41118 u32 ncci;
41119- atomic_t datahandle;
41120- atomic_t msgid;
41121+ atomic_unchecked_t datahandle;
41122+ atomic_unchecked_t msgid;
41123
41124 struct tty_port port;
41125 int ttyinstop;
41126@@ -391,7 +391,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
41127 capimsg_setu16(s, 2, mp->ap->applid);
41128 capimsg_setu8 (s, 4, CAPI_DATA_B3);
41129 capimsg_setu8 (s, 5, CAPI_RESP);
41130- capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
41131+ capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
41132 capimsg_setu32(s, 8, mp->ncci);
41133 capimsg_setu16(s, 12, datahandle);
41134 }
41135@@ -512,14 +512,14 @@ static void handle_minor_send(struct capiminor *mp)
41136 mp->outbytes -= len;
41137 spin_unlock_bh(&mp->outlock);
41138
41139- datahandle = atomic_inc_return(&mp->datahandle);
41140+ datahandle = atomic_inc_return_unchecked(&mp->datahandle);
41141 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
41142 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
41143 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
41144 capimsg_setu16(skb->data, 2, mp->ap->applid);
41145 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
41146 capimsg_setu8 (skb->data, 5, CAPI_REQ);
41147- capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
41148+ capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
41149 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
41150 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
41151 capimsg_setu16(skb->data, 16, len); /* Data length */
41152diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
41153index 600c79b..3752bab 100644
41154--- a/drivers/isdn/gigaset/interface.c
41155+++ b/drivers/isdn/gigaset/interface.c
41156@@ -130,9 +130,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
41157 }
41158 tty->driver_data = cs;
41159
41160- ++cs->port.count;
41161+ atomic_inc(&cs->port.count);
41162
41163- if (cs->port.count == 1) {
41164+ if (atomic_read(&cs->port.count) == 1) {
41165 tty_port_tty_set(&cs->port, tty);
41166 cs->port.low_latency = 1;
41167 }
41168@@ -156,9 +156,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
41169
41170 if (!cs->connected)
41171 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
41172- else if (!cs->port.count)
41173+ else if (!atomic_read(&cs->port.count))
41174 dev_warn(cs->dev, "%s: device not opened\n", __func__);
41175- else if (!--cs->port.count)
41176+ else if (!atomic_dec_return(&cs->port.count))
41177 tty_port_tty_set(&cs->port, NULL);
41178
41179 mutex_unlock(&cs->mutex);
41180diff --git a/drivers/isdn/gigaset/usb-gigaset.c b/drivers/isdn/gigaset/usb-gigaset.c
41181index d0a41cb..f0cdb8c 100644
41182--- a/drivers/isdn/gigaset/usb-gigaset.c
41183+++ b/drivers/isdn/gigaset/usb-gigaset.c
41184@@ -547,7 +547,7 @@ static int gigaset_brkchars(struct cardstate *cs, const unsigned char buf[6])
41185 gigaset_dbg_buffer(DEBUG_USBREQ, "brkchars", 6, buf);
41186 memcpy(cs->hw.usb->bchars, buf, 6);
41187 return usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x19, 0x41,
41188- 0, 0, &buf, 6, 2000);
41189+ 0, 0, buf, 6, 2000);
41190 }
41191
41192 static void gigaset_freebcshw(struct bc_state *bcs)
41193diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
41194index 4d9b195..455075c 100644
41195--- a/drivers/isdn/hardware/avm/b1.c
41196+++ b/drivers/isdn/hardware/avm/b1.c
41197@@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
41198 }
41199 if (left) {
41200 if (t4file->user) {
41201- if (copy_from_user(buf, dp, left))
41202+ if (left > sizeof buf || copy_from_user(buf, dp, left))
41203 return -EFAULT;
41204 } else {
41205 memcpy(buf, dp, left);
41206@@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
41207 }
41208 if (left) {
41209 if (config->user) {
41210- if (copy_from_user(buf, dp, left))
41211+ if (left > sizeof buf || copy_from_user(buf, dp, left))
41212 return -EFAULT;
41213 } else {
41214 memcpy(buf, dp, left);
41215diff --git a/drivers/isdn/i4l/isdn_common.c b/drivers/isdn/i4l/isdn_common.c
41216index 9bb12ba..d4262f7 100644
41217--- a/drivers/isdn/i4l/isdn_common.c
41218+++ b/drivers/isdn/i4l/isdn_common.c
41219@@ -1651,6 +1651,8 @@ isdn_ioctl(struct file *file, uint cmd, ulong arg)
41220 } else
41221 return -EINVAL;
41222 case IIOCDBGVAR:
41223+ if (!capable(CAP_SYS_RAWIO))
41224+ return -EPERM;
41225 if (arg) {
41226 if (copy_to_user(argp, &dev, sizeof(ulong)))
41227 return -EFAULT;
41228diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
41229index 3c5f249..5fac4d0 100644
41230--- a/drivers/isdn/i4l/isdn_tty.c
41231+++ b/drivers/isdn/i4l/isdn_tty.c
41232@@ -1508,9 +1508,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
41233
41234 #ifdef ISDN_DEBUG_MODEM_OPEN
41235 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
41236- port->count);
41237+ atomic_read(&port->count));
41238 #endif
41239- port->count++;
41240+ atomic_inc(&port->count);
41241 port->tty = tty;
41242 /*
41243 * Start up serial port
41244@@ -1554,7 +1554,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
41245 #endif
41246 return;
41247 }
41248- if ((tty->count == 1) && (port->count != 1)) {
41249+ if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
41250 /*
41251 * Uh, oh. tty->count is 1, which means that the tty
41252 * structure will be freed. Info->count should always
41253@@ -1563,15 +1563,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
41254 * serial port won't be shutdown.
41255 */
41256 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
41257- "info->count is %d\n", port->count);
41258- port->count = 1;
41259+ "info->count is %d\n", atomic_read(&port->count));
41260+ atomic_set(&port->count, 1);
41261 }
41262- if (--port->count < 0) {
41263+ if (atomic_dec_return(&port->count) < 0) {
41264 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
41265- info->line, port->count);
41266- port->count = 0;
41267+ info->line, atomic_read(&port->count));
41268+ atomic_set(&port->count, 0);
41269 }
41270- if (port->count) {
41271+ if (atomic_read(&port->count)) {
41272 #ifdef ISDN_DEBUG_MODEM_OPEN
41273 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
41274 #endif
41275@@ -1625,7 +1625,7 @@ isdn_tty_hangup(struct tty_struct *tty)
41276 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
41277 return;
41278 isdn_tty_shutdown(info);
41279- port->count = 0;
41280+ atomic_set(&port->count, 0);
41281 port->flags &= ~ASYNC_NORMAL_ACTIVE;
41282 port->tty = NULL;
41283 wake_up_interruptible(&port->open_wait);
41284@@ -1970,7 +1970,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
41285 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
41286 modem_info *info = &dev->mdm.info[i];
41287
41288- if (info->port.count == 0)
41289+ if (atomic_read(&info->port.count) == 0)
41290 continue;
41291 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
41292 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
41293diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
41294index e74df7c..03a03ba 100644
41295--- a/drivers/isdn/icn/icn.c
41296+++ b/drivers/isdn/icn/icn.c
41297@@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
41298 if (count > len)
41299 count = len;
41300 if (user) {
41301- if (copy_from_user(msg, buf, count))
41302+ if (count > sizeof msg || copy_from_user(msg, buf, count))
41303 return -EFAULT;
41304 } else
41305 memcpy(msg, buf, count);
41306diff --git a/drivers/isdn/isdnloop/isdnloop.c b/drivers/isdn/isdnloop/isdnloop.c
41307index baf2686..02125e6 100644
41308--- a/drivers/isdn/isdnloop/isdnloop.c
41309+++ b/drivers/isdn/isdnloop/isdnloop.c
41310@@ -1083,8 +1083,10 @@ isdnloop_start(isdnloop_card *card, isdnloop_sdef *sdefp)
41311 spin_unlock_irqrestore(&card->isdnloop_lock, flags);
41312 return -ENOMEM;
41313 }
41314- for (i = 0; i < 3; i++)
41315- strcpy(card->s0num[i], sdef.num[i]);
41316+ for (i = 0; i < 3; i++) {
41317+ strlcpy(card->s0num[i], sdef.num[i],
41318+ sizeof(card->s0num[0]));
41319+ }
41320 break;
41321 case ISDN_PTYPE_1TR6:
41322 if (isdnloop_fake(card, "DRV1.04TC-1TR6-CAPI-CNS-BASIS-29.11.95",
41323@@ -1097,7 +1099,7 @@ isdnloop_start(isdnloop_card *card, isdnloop_sdef *sdefp)
41324 spin_unlock_irqrestore(&card->isdnloop_lock, flags);
41325 return -ENOMEM;
41326 }
41327- strcpy(card->s0num[0], sdef.num[0]);
41328+ strlcpy(card->s0num[0], sdef.num[0], sizeof(card->s0num[0]));
41329 card->s0num[1][0] = '\0';
41330 card->s0num[2][0] = '\0';
41331 break;
41332diff --git a/drivers/isdn/mISDN/dsp_cmx.c b/drivers/isdn/mISDN/dsp_cmx.c
41333index a4f05c5..1433bc5 100644
41334--- a/drivers/isdn/mISDN/dsp_cmx.c
41335+++ b/drivers/isdn/mISDN/dsp_cmx.c
41336@@ -1628,7 +1628,7 @@ unsigned long dsp_spl_jiffies; /* calculate the next time to fire */
41337 static u16 dsp_count; /* last sample count */
41338 static int dsp_count_valid; /* if we have last sample count */
41339
41340-void
41341+void __intentional_overflow(-1)
41342 dsp_cmx_send(void *arg)
41343 {
41344 struct dsp_conf *conf;
41345diff --git a/drivers/leds/leds-clevo-mail.c b/drivers/leds/leds-clevo-mail.c
41346index d93e245..e7ece6b 100644
41347--- a/drivers/leds/leds-clevo-mail.c
41348+++ b/drivers/leds/leds-clevo-mail.c
41349@@ -40,7 +40,7 @@ static int __init clevo_mail_led_dmi_callback(const struct dmi_system_id *id)
41350 * detected as working, but in reality it is not) as low as
41351 * possible.
41352 */
41353-static struct dmi_system_id clevo_mail_led_dmi_table[] __initdata = {
41354+static struct dmi_system_id clevo_mail_led_dmi_table[] __initconst = {
41355 {
41356 .callback = clevo_mail_led_dmi_callback,
41357 .ident = "Clevo D410J",
41358diff --git a/drivers/leds/leds-ss4200.c b/drivers/leds/leds-ss4200.c
41359index 5b8f938..b73d657 100644
41360--- a/drivers/leds/leds-ss4200.c
41361+++ b/drivers/leds/leds-ss4200.c
41362@@ -91,7 +91,7 @@ MODULE_PARM_DESC(nodetect, "Skip DMI-based hardware detection");
41363 * detected as working, but in reality it is not) as low as
41364 * possible.
41365 */
41366-static struct dmi_system_id nas_led_whitelist[] __initdata = {
41367+static struct dmi_system_id nas_led_whitelist[] __initconst = {
41368 {
41369 .callback = ss4200_led_dmi_callback,
41370 .ident = "Intel SS4200-E",
41371diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
41372index 0bf1e4e..b4bf44e 100644
41373--- a/drivers/lguest/core.c
41374+++ b/drivers/lguest/core.c
41375@@ -97,9 +97,17 @@ static __init int map_switcher(void)
41376 * The end address needs +1 because __get_vm_area allocates an
41377 * extra guard page, so we need space for that.
41378 */
41379+
41380+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
41381+ switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
41382+ VM_ALLOC | VM_KERNEXEC, switcher_addr, switcher_addr
41383+ + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
41384+#else
41385 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
41386 VM_ALLOC, switcher_addr, switcher_addr
41387 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
41388+#endif
41389+
41390 if (!switcher_vma) {
41391 err = -ENOMEM;
41392 printk("lguest: could not map switcher pages high\n");
41393@@ -124,7 +132,7 @@ static __init int map_switcher(void)
41394 * Now the Switcher is mapped at the right address, we can't fail!
41395 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
41396 */
41397- memcpy(switcher_vma->addr, start_switcher_text,
41398+ memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
41399 end_switcher_text - start_switcher_text);
41400
41401 printk(KERN_INFO "lguest: mapped switcher at %p\n",
41402diff --git a/drivers/lguest/page_tables.c b/drivers/lguest/page_tables.c
41403index bfb39bb..08a603b 100644
41404--- a/drivers/lguest/page_tables.c
41405+++ b/drivers/lguest/page_tables.c
41406@@ -559,7 +559,7 @@ void pin_page(struct lg_cpu *cpu, unsigned long vaddr)
41407 /*:*/
41408
41409 #ifdef CONFIG_X86_PAE
41410-static void release_pmd(pmd_t *spmd)
41411+static void __intentional_overflow(-1) release_pmd(pmd_t *spmd)
41412 {
41413 /* If the entry's not present, there's nothing to release. */
41414 if (pmd_flags(*spmd) & _PAGE_PRESENT) {
41415diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
41416index 5169239..47cb4db 100644
41417--- a/drivers/lguest/x86/core.c
41418+++ b/drivers/lguest/x86/core.c
41419@@ -59,7 +59,7 @@ static struct {
41420 /* Offset from where switcher.S was compiled to where we've copied it */
41421 static unsigned long switcher_offset(void)
41422 {
41423- return switcher_addr - (unsigned long)start_switcher_text;
41424+ return switcher_addr - (unsigned long)ktla_ktva(start_switcher_text);
41425 }
41426
41427 /* This cpu's struct lguest_pages (after the Switcher text page) */
41428@@ -99,7 +99,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
41429 * These copies are pretty cheap, so we do them unconditionally: */
41430 /* Save the current Host top-level page directory.
41431 */
41432+
41433+#ifdef CONFIG_PAX_PER_CPU_PGD
41434+ pages->state.host_cr3 = read_cr3();
41435+#else
41436 pages->state.host_cr3 = __pa(current->mm->pgd);
41437+#endif
41438+
41439 /*
41440 * Set up the Guest's page tables to see this CPU's pages (and no
41441 * other CPU's pages).
41442@@ -475,7 +481,7 @@ void __init lguest_arch_host_init(void)
41443 * compiled-in switcher code and the high-mapped copy we just made.
41444 */
41445 for (i = 0; i < IDT_ENTRIES; i++)
41446- default_idt_entries[i] += switcher_offset();
41447+ default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
41448
41449 /*
41450 * Set up the Switcher's per-cpu areas.
41451@@ -558,7 +564,7 @@ void __init lguest_arch_host_init(void)
41452 * it will be undisturbed when we switch. To change %cs and jump we
41453 * need this structure to feed to Intel's "lcall" instruction.
41454 */
41455- lguest_entry.offset = (long)switch_to_guest + switcher_offset();
41456+ lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
41457 lguest_entry.segment = LGUEST_CS;
41458
41459 /*
41460diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
41461index 40634b0..4f5855e 100644
41462--- a/drivers/lguest/x86/switcher_32.S
41463+++ b/drivers/lguest/x86/switcher_32.S
41464@@ -87,6 +87,7 @@
41465 #include <asm/page.h>
41466 #include <asm/segment.h>
41467 #include <asm/lguest.h>
41468+#include <asm/processor-flags.h>
41469
41470 // We mark the start of the code to copy
41471 // It's placed in .text tho it's never run here
41472@@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
41473 // Changes type when we load it: damn Intel!
41474 // For after we switch over our page tables
41475 // That entry will be read-only: we'd crash.
41476+
41477+#ifdef CONFIG_PAX_KERNEXEC
41478+ mov %cr0, %edx
41479+ xor $X86_CR0_WP, %edx
41480+ mov %edx, %cr0
41481+#endif
41482+
41483 movl $(GDT_ENTRY_TSS*8), %edx
41484 ltr %dx
41485
41486@@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
41487 // Let's clear it again for our return.
41488 // The GDT descriptor of the Host
41489 // Points to the table after two "size" bytes
41490- movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
41491+ movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
41492 // Clear "used" from type field (byte 5, bit 2)
41493- andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
41494+ andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
41495+
41496+#ifdef CONFIG_PAX_KERNEXEC
41497+ mov %cr0, %eax
41498+ xor $X86_CR0_WP, %eax
41499+ mov %eax, %cr0
41500+#endif
41501
41502 // Once our page table's switched, the Guest is live!
41503 // The Host fades as we run this final step.
41504@@ -295,13 +309,12 @@ deliver_to_host:
41505 // I consulted gcc, and it gave
41506 // These instructions, which I gladly credit:
41507 leal (%edx,%ebx,8), %eax
41508- movzwl (%eax),%edx
41509- movl 4(%eax), %eax
41510- xorw %ax, %ax
41511- orl %eax, %edx
41512+ movl 4(%eax), %edx
41513+ movw (%eax), %dx
41514 // Now the address of the handler's in %edx
41515 // We call it now: its "iret" drops us home.
41516- jmp *%edx
41517+ ljmp $__KERNEL_CS, $1f
41518+1: jmp *%edx
41519
41520 // Every interrupt can come to us here
41521 // But we must truly tell each apart.
41522diff --git a/drivers/md/bcache/closure.h b/drivers/md/bcache/closure.h
41523index 0003992..854bbce 100644
41524--- a/drivers/md/bcache/closure.h
41525+++ b/drivers/md/bcache/closure.h
41526@@ -622,7 +622,7 @@ static inline void closure_wake_up(struct closure_waitlist *list)
41527 static inline void set_closure_fn(struct closure *cl, closure_fn *fn,
41528 struct workqueue_struct *wq)
41529 {
41530- BUG_ON(object_is_on_stack(cl));
41531+ BUG_ON(object_starts_on_stack(cl));
41532 closure_set_ip(cl);
41533 cl->fn = fn;
41534 cl->wq = wq;
41535diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c
41536index 547c4c5..5be1de4 100644
41537--- a/drivers/md/bcache/super.c
41538+++ b/drivers/md/bcache/super.c
41539@@ -1644,7 +1644,7 @@ err_unlock_gc:
41540 err:
41541 closure_sync(&op.cl);
41542 /* XXX: test this, it's broken */
41543- bch_cache_set_error(c, err);
41544+ bch_cache_set_error(c, "%s", err);
41545 }
41546
41547 static bool can_attach_cache(struct cache *ca, struct cache_set *c)
41548diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
41549index a7fd821..9dcf6c3 100644
41550--- a/drivers/md/bitmap.c
41551+++ b/drivers/md/bitmap.c
41552@@ -1779,7 +1779,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
41553 chunk_kb ? "KB" : "B");
41554 if (bitmap->storage.file) {
41555 seq_printf(seq, ", file: ");
41556- seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
41557+ seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
41558 }
41559
41560 seq_printf(seq, "\n");
41561diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
41562index afe0814..8cf3794 100644
41563--- a/drivers/md/dm-ioctl.c
41564+++ b/drivers/md/dm-ioctl.c
41565@@ -1745,7 +1745,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
41566 cmd == DM_LIST_VERSIONS_CMD)
41567 return 0;
41568
41569- if ((cmd == DM_DEV_CREATE_CMD)) {
41570+ if (cmd == DM_DEV_CREATE_CMD) {
41571 if (!*param->name) {
41572 DMWARN("name not supplied when creating device");
41573 return -EINVAL;
41574diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
41575index 9584443..9fc9ac9 100644
41576--- a/drivers/md/dm-raid1.c
41577+++ b/drivers/md/dm-raid1.c
41578@@ -40,7 +40,7 @@ enum dm_raid1_error {
41579
41580 struct mirror {
41581 struct mirror_set *ms;
41582- atomic_t error_count;
41583+ atomic_unchecked_t error_count;
41584 unsigned long error_type;
41585 struct dm_dev *dev;
41586 sector_t offset;
41587@@ -186,7 +186,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
41588 struct mirror *m;
41589
41590 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
41591- if (!atomic_read(&m->error_count))
41592+ if (!atomic_read_unchecked(&m->error_count))
41593 return m;
41594
41595 return NULL;
41596@@ -218,7 +218,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
41597 * simple way to tell if a device has encountered
41598 * errors.
41599 */
41600- atomic_inc(&m->error_count);
41601+ atomic_inc_unchecked(&m->error_count);
41602
41603 if (test_and_set_bit(error_type, &m->error_type))
41604 return;
41605@@ -409,7 +409,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
41606 struct mirror *m = get_default_mirror(ms);
41607
41608 do {
41609- if (likely(!atomic_read(&m->error_count)))
41610+ if (likely(!atomic_read_unchecked(&m->error_count)))
41611 return m;
41612
41613 if (m-- == ms->mirror)
41614@@ -423,7 +423,7 @@ static int default_ok(struct mirror *m)
41615 {
41616 struct mirror *default_mirror = get_default_mirror(m->ms);
41617
41618- return !atomic_read(&default_mirror->error_count);
41619+ return !atomic_read_unchecked(&default_mirror->error_count);
41620 }
41621
41622 static int mirror_available(struct mirror_set *ms, struct bio *bio)
41623@@ -560,7 +560,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
41624 */
41625 if (likely(region_in_sync(ms, region, 1)))
41626 m = choose_mirror(ms, bio->bi_sector);
41627- else if (m && atomic_read(&m->error_count))
41628+ else if (m && atomic_read_unchecked(&m->error_count))
41629 m = NULL;
41630
41631 if (likely(m))
41632@@ -927,7 +927,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
41633 }
41634
41635 ms->mirror[mirror].ms = ms;
41636- atomic_set(&(ms->mirror[mirror].error_count), 0);
41637+ atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
41638 ms->mirror[mirror].error_type = 0;
41639 ms->mirror[mirror].offset = offset;
41640
41641@@ -1339,7 +1339,7 @@ static void mirror_resume(struct dm_target *ti)
41642 */
41643 static char device_status_char(struct mirror *m)
41644 {
41645- if (!atomic_read(&(m->error_count)))
41646+ if (!atomic_read_unchecked(&(m->error_count)))
41647 return 'A';
41648
41649 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
41650diff --git a/drivers/md/dm-stats.c b/drivers/md/dm-stats.c
41651index 3d404c1..b62af0e 100644
41652--- a/drivers/md/dm-stats.c
41653+++ b/drivers/md/dm-stats.c
41654@@ -382,7 +382,7 @@ do_sync_free:
41655 synchronize_rcu_expedited();
41656 dm_stat_free(&s->rcu_head);
41657 } else {
41658- ACCESS_ONCE(dm_stat_need_rcu_barrier) = 1;
41659+ ACCESS_ONCE_RW(dm_stat_need_rcu_barrier) = 1;
41660 call_rcu(&s->rcu_head, dm_stat_free);
41661 }
41662 return 0;
41663@@ -554,8 +554,8 @@ void dm_stats_account_io(struct dm_stats *stats, unsigned long bi_rw,
41664 ((bi_rw & (REQ_WRITE | REQ_DISCARD)) ==
41665 (ACCESS_ONCE(last->last_rw) & (REQ_WRITE | REQ_DISCARD)))
41666 ));
41667- ACCESS_ONCE(last->last_sector) = end_sector;
41668- ACCESS_ONCE(last->last_rw) = bi_rw;
41669+ ACCESS_ONCE_RW(last->last_sector) = end_sector;
41670+ ACCESS_ONCE_RW(last->last_rw) = bi_rw;
41671 }
41672
41673 rcu_read_lock();
41674diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
41675index 73c1712..7347292 100644
41676--- a/drivers/md/dm-stripe.c
41677+++ b/drivers/md/dm-stripe.c
41678@@ -21,7 +21,7 @@ struct stripe {
41679 struct dm_dev *dev;
41680 sector_t physical_start;
41681
41682- atomic_t error_count;
41683+ atomic_unchecked_t error_count;
41684 };
41685
41686 struct stripe_c {
41687@@ -186,7 +186,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
41688 kfree(sc);
41689 return r;
41690 }
41691- atomic_set(&(sc->stripe[i].error_count), 0);
41692+ atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
41693 }
41694
41695 ti->private = sc;
41696@@ -327,7 +327,7 @@ static void stripe_status(struct dm_target *ti, status_type_t type,
41697 DMEMIT("%d ", sc->stripes);
41698 for (i = 0; i < sc->stripes; i++) {
41699 DMEMIT("%s ", sc->stripe[i].dev->name);
41700- buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
41701+ buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
41702 'D' : 'A';
41703 }
41704 buffer[i] = '\0';
41705@@ -372,8 +372,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio, int error)
41706 */
41707 for (i = 0; i < sc->stripes; i++)
41708 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
41709- atomic_inc(&(sc->stripe[i].error_count));
41710- if (atomic_read(&(sc->stripe[i].error_count)) <
41711+ atomic_inc_unchecked(&(sc->stripe[i].error_count));
41712+ if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
41713 DM_IO_ERROR_THRESHOLD)
41714 schedule_work(&sc->trigger_event);
41715 }
41716diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
41717index 8f87835..531854d 100644
41718--- a/drivers/md/dm-table.c
41719+++ b/drivers/md/dm-table.c
41720@@ -286,7 +286,7 @@ static struct dm_dev_internal *find_device(struct list_head *l, dev_t dev)
41721 static int open_dev(struct dm_dev_internal *d, dev_t dev,
41722 struct mapped_device *md)
41723 {
41724- static char *_claim_ptr = "I belong to device-mapper";
41725+ static char _claim_ptr[] = "I belong to device-mapper";
41726 struct block_device *bdev;
41727
41728 int r;
41729@@ -354,7 +354,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
41730 if (!dev_size)
41731 return 0;
41732
41733- if ((start >= dev_size) || (start + len > dev_size)) {
41734+ if ((start >= dev_size) || (len > dev_size - start)) {
41735 DMWARN("%s: %s too small for target: "
41736 "start=%llu, len=%llu, dev_size=%llu",
41737 dm_device_name(ti->table->md), bdevname(bdev, b),
41738diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
41739index 60bce43..9b997d0 100644
41740--- a/drivers/md/dm-thin-metadata.c
41741+++ b/drivers/md/dm-thin-metadata.c
41742@@ -397,7 +397,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
41743 {
41744 pmd->info.tm = pmd->tm;
41745 pmd->info.levels = 2;
41746- pmd->info.value_type.context = pmd->data_sm;
41747+ pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
41748 pmd->info.value_type.size = sizeof(__le64);
41749 pmd->info.value_type.inc = data_block_inc;
41750 pmd->info.value_type.dec = data_block_dec;
41751@@ -416,7 +416,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
41752
41753 pmd->bl_info.tm = pmd->tm;
41754 pmd->bl_info.levels = 1;
41755- pmd->bl_info.value_type.context = pmd->data_sm;
41756+ pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
41757 pmd->bl_info.value_type.size = sizeof(__le64);
41758 pmd->bl_info.value_type.inc = data_block_inc;
41759 pmd->bl_info.value_type.dec = data_block_dec;
41760diff --git a/drivers/md/dm.c b/drivers/md/dm.c
41761index b3e26c7..1efca94 100644
41762--- a/drivers/md/dm.c
41763+++ b/drivers/md/dm.c
41764@@ -179,9 +179,9 @@ struct mapped_device {
41765 /*
41766 * Event handling.
41767 */
41768- atomic_t event_nr;
41769+ atomic_unchecked_t event_nr;
41770 wait_queue_head_t eventq;
41771- atomic_t uevent_seq;
41772+ atomic_unchecked_t uevent_seq;
41773 struct list_head uevent_list;
41774 spinlock_t uevent_lock; /* Protect access to uevent_list */
41775
41776@@ -1985,8 +1985,8 @@ static struct mapped_device *alloc_dev(int minor)
41777 spin_lock_init(&md->deferred_lock);
41778 atomic_set(&md->holders, 1);
41779 atomic_set(&md->open_count, 0);
41780- atomic_set(&md->event_nr, 0);
41781- atomic_set(&md->uevent_seq, 0);
41782+ atomic_set_unchecked(&md->event_nr, 0);
41783+ atomic_set_unchecked(&md->uevent_seq, 0);
41784 INIT_LIST_HEAD(&md->uevent_list);
41785 spin_lock_init(&md->uevent_lock);
41786
41787@@ -2139,7 +2139,7 @@ static void event_callback(void *context)
41788
41789 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
41790
41791- atomic_inc(&md->event_nr);
41792+ atomic_inc_unchecked(&md->event_nr);
41793 wake_up(&md->eventq);
41794 }
41795
41796@@ -2832,18 +2832,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
41797
41798 uint32_t dm_next_uevent_seq(struct mapped_device *md)
41799 {
41800- return atomic_add_return(1, &md->uevent_seq);
41801+ return atomic_add_return_unchecked(1, &md->uevent_seq);
41802 }
41803
41804 uint32_t dm_get_event_nr(struct mapped_device *md)
41805 {
41806- return atomic_read(&md->event_nr);
41807+ return atomic_read_unchecked(&md->event_nr);
41808 }
41809
41810 int dm_wait_event(struct mapped_device *md, int event_nr)
41811 {
41812 return wait_event_interruptible(md->eventq,
41813- (event_nr != atomic_read(&md->event_nr)));
41814+ (event_nr != atomic_read_unchecked(&md->event_nr)));
41815 }
41816
41817 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
41818diff --git a/drivers/md/md.c b/drivers/md/md.c
41819index 561a65f..f4e8c71 100644
41820--- a/drivers/md/md.c
41821+++ b/drivers/md/md.c
41822@@ -234,10 +234,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
41823 * start build, activate spare
41824 */
41825 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
41826-static atomic_t md_event_count;
41827+static atomic_unchecked_t md_event_count;
41828 void md_new_event(struct mddev *mddev)
41829 {
41830- atomic_inc(&md_event_count);
41831+ atomic_inc_unchecked(&md_event_count);
41832 wake_up(&md_event_waiters);
41833 }
41834 EXPORT_SYMBOL_GPL(md_new_event);
41835@@ -247,7 +247,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
41836 */
41837 static void md_new_event_inintr(struct mddev *mddev)
41838 {
41839- atomic_inc(&md_event_count);
41840+ atomic_inc_unchecked(&md_event_count);
41841 wake_up(&md_event_waiters);
41842 }
41843
41844@@ -1502,7 +1502,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
41845 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
41846 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
41847 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
41848- atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
41849+ atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
41850
41851 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
41852 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
41853@@ -1746,7 +1746,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
41854 else
41855 sb->resync_offset = cpu_to_le64(0);
41856
41857- sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
41858+ sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
41859
41860 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
41861 sb->size = cpu_to_le64(mddev->dev_sectors);
41862@@ -2751,7 +2751,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
41863 static ssize_t
41864 errors_show(struct md_rdev *rdev, char *page)
41865 {
41866- return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
41867+ return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
41868 }
41869
41870 static ssize_t
41871@@ -2760,7 +2760,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
41872 char *e;
41873 unsigned long n = simple_strtoul(buf, &e, 10);
41874 if (*buf && (*e == 0 || *e == '\n')) {
41875- atomic_set(&rdev->corrected_errors, n);
41876+ atomic_set_unchecked(&rdev->corrected_errors, n);
41877 return len;
41878 }
41879 return -EINVAL;
41880@@ -3208,8 +3208,8 @@ int md_rdev_init(struct md_rdev *rdev)
41881 rdev->sb_loaded = 0;
41882 rdev->bb_page = NULL;
41883 atomic_set(&rdev->nr_pending, 0);
41884- atomic_set(&rdev->read_errors, 0);
41885- atomic_set(&rdev->corrected_errors, 0);
41886+ atomic_set_unchecked(&rdev->read_errors, 0);
41887+ atomic_set_unchecked(&rdev->corrected_errors, 0);
41888
41889 INIT_LIST_HEAD(&rdev->same_set);
41890 init_waitqueue_head(&rdev->blocked_wait);
41891@@ -7042,7 +7042,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
41892
41893 spin_unlock(&pers_lock);
41894 seq_printf(seq, "\n");
41895- seq->poll_event = atomic_read(&md_event_count);
41896+ seq->poll_event = atomic_read_unchecked(&md_event_count);
41897 return 0;
41898 }
41899 if (v == (void*)2) {
41900@@ -7145,7 +7145,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
41901 return error;
41902
41903 seq = file->private_data;
41904- seq->poll_event = atomic_read(&md_event_count);
41905+ seq->poll_event = atomic_read_unchecked(&md_event_count);
41906 return error;
41907 }
41908
41909@@ -7159,7 +7159,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
41910 /* always allow read */
41911 mask = POLLIN | POLLRDNORM;
41912
41913- if (seq->poll_event != atomic_read(&md_event_count))
41914+ if (seq->poll_event != atomic_read_unchecked(&md_event_count))
41915 mask |= POLLERR | POLLPRI;
41916 return mask;
41917 }
41918@@ -7203,7 +7203,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
41919 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
41920 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
41921 (int)part_stat_read(&disk->part0, sectors[1]) -
41922- atomic_read(&disk->sync_io);
41923+ atomic_read_unchecked(&disk->sync_io);
41924 /* sync IO will cause sync_io to increase before the disk_stats
41925 * as sync_io is counted when a request starts, and
41926 * disk_stats is counted when it completes.
41927diff --git a/drivers/md/md.h b/drivers/md/md.h
41928index 608050c..6e77db5d 100644
41929--- a/drivers/md/md.h
41930+++ b/drivers/md/md.h
41931@@ -94,13 +94,13 @@ struct md_rdev {
41932 * only maintained for arrays that
41933 * support hot removal
41934 */
41935- atomic_t read_errors; /* number of consecutive read errors that
41936+ atomic_unchecked_t read_errors; /* number of consecutive read errors that
41937 * we have tried to ignore.
41938 */
41939 struct timespec last_read_error; /* monotonic time since our
41940 * last read error
41941 */
41942- atomic_t corrected_errors; /* number of corrected read errors,
41943+ atomic_unchecked_t corrected_errors; /* number of corrected read errors,
41944 * for reporting to userspace and storing
41945 * in superblock.
41946 */
41947@@ -446,7 +446,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
41948
41949 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
41950 {
41951- atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
41952+ atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
41953 }
41954
41955 struct md_personality
41956diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
41957index 3e6d115..ffecdeb 100644
41958--- a/drivers/md/persistent-data/dm-space-map.h
41959+++ b/drivers/md/persistent-data/dm-space-map.h
41960@@ -71,6 +71,7 @@ struct dm_space_map {
41961 dm_sm_threshold_fn fn,
41962 void *context);
41963 };
41964+typedef struct dm_space_map __no_const dm_space_map_no_const;
41965
41966 /*----------------------------------------------------------------*/
41967
41968diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
41969index aacf6bf..67d63f2 100644
41970--- a/drivers/md/raid1.c
41971+++ b/drivers/md/raid1.c
41972@@ -1824,7 +1824,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
41973 if (r1_sync_page_io(rdev, sect, s,
41974 bio->bi_io_vec[idx].bv_page,
41975 READ) != 0)
41976- atomic_add(s, &rdev->corrected_errors);
41977+ atomic_add_unchecked(s, &rdev->corrected_errors);
41978 }
41979 sectors -= s;
41980 sect += s;
41981@@ -2051,7 +2051,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
41982 test_bit(In_sync, &rdev->flags)) {
41983 if (r1_sync_page_io(rdev, sect, s,
41984 conf->tmppage, READ)) {
41985- atomic_add(s, &rdev->corrected_errors);
41986+ atomic_add_unchecked(s, &rdev->corrected_errors);
41987 printk(KERN_INFO
41988 "md/raid1:%s: read error corrected "
41989 "(%d sectors at %llu on %s)\n",
41990diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
41991index 73dc8a3..bdd515a 100644
41992--- a/drivers/md/raid10.c
41993+++ b/drivers/md/raid10.c
41994@@ -1963,7 +1963,7 @@ static void end_sync_read(struct bio *bio, int error)
41995 /* The write handler will notice the lack of
41996 * R10BIO_Uptodate and record any errors etc
41997 */
41998- atomic_add(r10_bio->sectors,
41999+ atomic_add_unchecked(r10_bio->sectors,
42000 &conf->mirrors[d].rdev->corrected_errors);
42001
42002 /* for reconstruct, we always reschedule after a read.
42003@@ -2321,7 +2321,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
42004 {
42005 struct timespec cur_time_mon;
42006 unsigned long hours_since_last;
42007- unsigned int read_errors = atomic_read(&rdev->read_errors);
42008+ unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
42009
42010 ktime_get_ts(&cur_time_mon);
42011
42012@@ -2343,9 +2343,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
42013 * overflowing the shift of read_errors by hours_since_last.
42014 */
42015 if (hours_since_last >= 8 * sizeof(read_errors))
42016- atomic_set(&rdev->read_errors, 0);
42017+ atomic_set_unchecked(&rdev->read_errors, 0);
42018 else
42019- atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
42020+ atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
42021 }
42022
42023 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
42024@@ -2399,8 +2399,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
42025 return;
42026
42027 check_decay_read_errors(mddev, rdev);
42028- atomic_inc(&rdev->read_errors);
42029- if (atomic_read(&rdev->read_errors) > max_read_errors) {
42030+ atomic_inc_unchecked(&rdev->read_errors);
42031+ if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
42032 char b[BDEVNAME_SIZE];
42033 bdevname(rdev->bdev, b);
42034
42035@@ -2408,7 +2408,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
42036 "md/raid10:%s: %s: Raid device exceeded "
42037 "read_error threshold [cur %d:max %d]\n",
42038 mdname(mddev), b,
42039- atomic_read(&rdev->read_errors), max_read_errors);
42040+ atomic_read_unchecked(&rdev->read_errors), max_read_errors);
42041 printk(KERN_NOTICE
42042 "md/raid10:%s: %s: Failing raid device\n",
42043 mdname(mddev), b);
42044@@ -2563,7 +2563,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
42045 sect +
42046 choose_data_offset(r10_bio, rdev)),
42047 bdevname(rdev->bdev, b));
42048- atomic_add(s, &rdev->corrected_errors);
42049+ atomic_add_unchecked(s, &rdev->corrected_errors);
42050 }
42051
42052 rdev_dec_pending(rdev, mddev);
42053diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
42054index f8b9068..7a2b9fc 100644
42055--- a/drivers/md/raid5.c
42056+++ b/drivers/md/raid5.c
42057@@ -1886,21 +1886,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
42058 mdname(conf->mddev), STRIPE_SECTORS,
42059 (unsigned long long)s,
42060 bdevname(rdev->bdev, b));
42061- atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
42062+ atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
42063 clear_bit(R5_ReadError, &sh->dev[i].flags);
42064 clear_bit(R5_ReWrite, &sh->dev[i].flags);
42065 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
42066 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
42067
42068- if (atomic_read(&rdev->read_errors))
42069- atomic_set(&rdev->read_errors, 0);
42070+ if (atomic_read_unchecked(&rdev->read_errors))
42071+ atomic_set_unchecked(&rdev->read_errors, 0);
42072 } else {
42073 const char *bdn = bdevname(rdev->bdev, b);
42074 int retry = 0;
42075 int set_bad = 0;
42076
42077 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
42078- atomic_inc(&rdev->read_errors);
42079+ atomic_inc_unchecked(&rdev->read_errors);
42080 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
42081 printk_ratelimited(
42082 KERN_WARNING
42083@@ -1928,7 +1928,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
42084 mdname(conf->mddev),
42085 (unsigned long long)s,
42086 bdn);
42087- } else if (atomic_read(&rdev->read_errors)
42088+ } else if (atomic_read_unchecked(&rdev->read_errors)
42089 > conf->max_nr_stripes)
42090 printk(KERN_WARNING
42091 "md/raid:%s: Too many read errors, failing device %s.\n",
42092diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
42093index 401ef64..836e563 100644
42094--- a/drivers/media/dvb-core/dvbdev.c
42095+++ b/drivers/media/dvb-core/dvbdev.c
42096@@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
42097 const struct dvb_device *template, void *priv, int type)
42098 {
42099 struct dvb_device *dvbdev;
42100- struct file_operations *dvbdevfops;
42101+ file_operations_no_const *dvbdevfops;
42102 struct device *clsdev;
42103 int minor;
42104 int id;
42105diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
42106index 9b6c3bb..baeb5c7 100644
42107--- a/drivers/media/dvb-frontends/dib3000.h
42108+++ b/drivers/media/dvb-frontends/dib3000.h
42109@@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
42110 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
42111 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
42112 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
42113-};
42114+} __no_const;
42115
42116 #if IS_ENABLED(CONFIG_DVB_DIB3000MB)
42117 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
42118diff --git a/drivers/media/pci/cx88/cx88-video.c b/drivers/media/pci/cx88/cx88-video.c
42119index ecf21d9..b992428d 100644
42120--- a/drivers/media/pci/cx88/cx88-video.c
42121+++ b/drivers/media/pci/cx88/cx88-video.c
42122@@ -50,9 +50,9 @@ MODULE_VERSION(CX88_VERSION);
42123
42124 /* ------------------------------------------------------------------ */
42125
42126-static unsigned int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
42127-static unsigned int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
42128-static unsigned int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
42129+static int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
42130+static int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
42131+static int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
42132
42133 module_param_array(video_nr, int, NULL, 0444);
42134 module_param_array(vbi_nr, int, NULL, 0444);
42135diff --git a/drivers/media/pci/ivtv/ivtv-driver.c b/drivers/media/pci/ivtv/ivtv-driver.c
42136index c08ae3e..eb59af1 100644
42137--- a/drivers/media/pci/ivtv/ivtv-driver.c
42138+++ b/drivers/media/pci/ivtv/ivtv-driver.c
42139@@ -83,7 +83,7 @@ static struct pci_device_id ivtv_pci_tbl[] = {
42140 MODULE_DEVICE_TABLE(pci,ivtv_pci_tbl);
42141
42142 /* ivtv instance counter */
42143-static atomic_t ivtv_instance = ATOMIC_INIT(0);
42144+static atomic_unchecked_t ivtv_instance = ATOMIC_INIT(0);
42145
42146 /* Parameter declarations */
42147 static int cardtype[IVTV_MAX_CARDS];
42148diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
42149index dfd0a21..6bbb465 100644
42150--- a/drivers/media/platform/omap/omap_vout.c
42151+++ b/drivers/media/platform/omap/omap_vout.c
42152@@ -63,7 +63,6 @@ enum omap_vout_channels {
42153 OMAP_VIDEO2,
42154 };
42155
42156-static struct videobuf_queue_ops video_vbq_ops;
42157 /* Variables configurable through module params*/
42158 static u32 video1_numbuffers = 3;
42159 static u32 video2_numbuffers = 3;
42160@@ -1014,6 +1013,12 @@ static int omap_vout_open(struct file *file)
42161 {
42162 struct videobuf_queue *q;
42163 struct omap_vout_device *vout = NULL;
42164+ static struct videobuf_queue_ops video_vbq_ops = {
42165+ .buf_setup = omap_vout_buffer_setup,
42166+ .buf_prepare = omap_vout_buffer_prepare,
42167+ .buf_release = omap_vout_buffer_release,
42168+ .buf_queue = omap_vout_buffer_queue,
42169+ };
42170
42171 vout = video_drvdata(file);
42172 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
42173@@ -1031,10 +1036,6 @@ static int omap_vout_open(struct file *file)
42174 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
42175
42176 q = &vout->vbq;
42177- video_vbq_ops.buf_setup = omap_vout_buffer_setup;
42178- video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
42179- video_vbq_ops.buf_release = omap_vout_buffer_release;
42180- video_vbq_ops.buf_queue = omap_vout_buffer_queue;
42181 spin_lock_init(&vout->vbq_lock);
42182
42183 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
42184diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
42185index 04e6490..2df65bf 100644
42186--- a/drivers/media/platform/s5p-tv/mixer.h
42187+++ b/drivers/media/platform/s5p-tv/mixer.h
42188@@ -156,7 +156,7 @@ struct mxr_layer {
42189 /** layer index (unique identifier) */
42190 int idx;
42191 /** callbacks for layer methods */
42192- struct mxr_layer_ops ops;
42193+ struct mxr_layer_ops *ops;
42194 /** format array */
42195 const struct mxr_format **fmt_array;
42196 /** size of format array */
42197diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
42198index b93a21f..2535195 100644
42199--- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
42200+++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
42201@@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
42202 {
42203 struct mxr_layer *layer;
42204 int ret;
42205- struct mxr_layer_ops ops = {
42206+ static struct mxr_layer_ops ops = {
42207 .release = mxr_graph_layer_release,
42208 .buffer_set = mxr_graph_buffer_set,
42209 .stream_set = mxr_graph_stream_set,
42210diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
42211index b713403..53cb5ad 100644
42212--- a/drivers/media/platform/s5p-tv/mixer_reg.c
42213+++ b/drivers/media/platform/s5p-tv/mixer_reg.c
42214@@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
42215 layer->update_buf = next;
42216 }
42217
42218- layer->ops.buffer_set(layer, layer->update_buf);
42219+ layer->ops->buffer_set(layer, layer->update_buf);
42220
42221 if (done && done != layer->shadow_buf)
42222 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
42223diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
42224index 641b1f0..49cff30 100644
42225--- a/drivers/media/platform/s5p-tv/mixer_video.c
42226+++ b/drivers/media/platform/s5p-tv/mixer_video.c
42227@@ -210,7 +210,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
42228 layer->geo.src.height = layer->geo.src.full_height;
42229
42230 mxr_geometry_dump(mdev, &layer->geo);
42231- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
42232+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
42233 mxr_geometry_dump(mdev, &layer->geo);
42234 }
42235
42236@@ -228,7 +228,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
42237 layer->geo.dst.full_width = mbus_fmt.width;
42238 layer->geo.dst.full_height = mbus_fmt.height;
42239 layer->geo.dst.field = mbus_fmt.field;
42240- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
42241+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
42242
42243 mxr_geometry_dump(mdev, &layer->geo);
42244 }
42245@@ -334,7 +334,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
42246 /* set source size to highest accepted value */
42247 geo->src.full_width = max(geo->dst.full_width, pix->width);
42248 geo->src.full_height = max(geo->dst.full_height, pix->height);
42249- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
42250+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
42251 mxr_geometry_dump(mdev, &layer->geo);
42252 /* set cropping to total visible screen */
42253 geo->src.width = pix->width;
42254@@ -342,12 +342,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
42255 geo->src.x_offset = 0;
42256 geo->src.y_offset = 0;
42257 /* assure consistency of geometry */
42258- layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
42259+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
42260 mxr_geometry_dump(mdev, &layer->geo);
42261 /* set full size to lowest possible value */
42262 geo->src.full_width = 0;
42263 geo->src.full_height = 0;
42264- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
42265+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
42266 mxr_geometry_dump(mdev, &layer->geo);
42267
42268 /* returning results */
42269@@ -474,7 +474,7 @@ static int mxr_s_selection(struct file *file, void *fh,
42270 target->width = s->r.width;
42271 target->height = s->r.height;
42272
42273- layer->ops.fix_geometry(layer, stage, s->flags);
42274+ layer->ops->fix_geometry(layer, stage, s->flags);
42275
42276 /* retrieve update selection rectangle */
42277 res.left = target->x_offset;
42278@@ -955,13 +955,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
42279 mxr_output_get(mdev);
42280
42281 mxr_layer_update_output(layer);
42282- layer->ops.format_set(layer);
42283+ layer->ops->format_set(layer);
42284 /* enabling layer in hardware */
42285 spin_lock_irqsave(&layer->enq_slock, flags);
42286 layer->state = MXR_LAYER_STREAMING;
42287 spin_unlock_irqrestore(&layer->enq_slock, flags);
42288
42289- layer->ops.stream_set(layer, MXR_ENABLE);
42290+ layer->ops->stream_set(layer, MXR_ENABLE);
42291 mxr_streamer_get(mdev);
42292
42293 return 0;
42294@@ -1031,7 +1031,7 @@ static int stop_streaming(struct vb2_queue *vq)
42295 spin_unlock_irqrestore(&layer->enq_slock, flags);
42296
42297 /* disabling layer in hardware */
42298- layer->ops.stream_set(layer, MXR_DISABLE);
42299+ layer->ops->stream_set(layer, MXR_DISABLE);
42300 /* remove one streamer */
42301 mxr_streamer_put(mdev);
42302 /* allow changes in output configuration */
42303@@ -1070,8 +1070,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
42304
42305 void mxr_layer_release(struct mxr_layer *layer)
42306 {
42307- if (layer->ops.release)
42308- layer->ops.release(layer);
42309+ if (layer->ops->release)
42310+ layer->ops->release(layer);
42311 }
42312
42313 void mxr_base_layer_release(struct mxr_layer *layer)
42314@@ -1097,7 +1097,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
42315
42316 layer->mdev = mdev;
42317 layer->idx = idx;
42318- layer->ops = *ops;
42319+ layer->ops = ops;
42320
42321 spin_lock_init(&layer->enq_slock);
42322 INIT_LIST_HEAD(&layer->enq_list);
42323diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
42324index 3d13a63..da31bf1 100644
42325--- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
42326+++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
42327@@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
42328 {
42329 struct mxr_layer *layer;
42330 int ret;
42331- struct mxr_layer_ops ops = {
42332+ static struct mxr_layer_ops ops = {
42333 .release = mxr_vp_layer_release,
42334 .buffer_set = mxr_vp_buffer_set,
42335 .stream_set = mxr_vp_stream_set,
42336diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
42337index 545c04c..a14bded 100644
42338--- a/drivers/media/radio/radio-cadet.c
42339+++ b/drivers/media/radio/radio-cadet.c
42340@@ -324,6 +324,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
42341 unsigned char readbuf[RDS_BUFFER];
42342 int i = 0;
42343
42344+ if (count > RDS_BUFFER)
42345+ return -EFAULT;
42346 mutex_lock(&dev->lock);
42347 if (dev->rdsstat == 0)
42348 cadet_start_rds(dev);
42349@@ -339,7 +341,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
42350 while (i < count && dev->rdsin != dev->rdsout)
42351 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
42352
42353- if (i && copy_to_user(data, readbuf, i))
42354+ if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
42355 i = -EFAULT;
42356 unlock:
42357 mutex_unlock(&dev->lock);
42358diff --git a/drivers/media/radio/radio-maxiradio.c b/drivers/media/radio/radio-maxiradio.c
42359index 5236035..c622c74 100644
42360--- a/drivers/media/radio/radio-maxiradio.c
42361+++ b/drivers/media/radio/radio-maxiradio.c
42362@@ -61,7 +61,7 @@ MODULE_PARM_DESC(radio_nr, "Radio device number");
42363 /* TEA5757 pin mappings */
42364 static const int clk = 1, data = 2, wren = 4, mo_st = 8, power = 16;
42365
42366-static atomic_t maxiradio_instance = ATOMIC_INIT(0);
42367+static atomic_unchecked_t maxiradio_instance = ATOMIC_INIT(0);
42368
42369 #define PCI_VENDOR_ID_GUILLEMOT 0x5046
42370 #define PCI_DEVICE_ID_GUILLEMOT_MAXIRADIO 0x1001
42371diff --git a/drivers/media/radio/radio-shark.c b/drivers/media/radio/radio-shark.c
42372index b914772..7ddbf9b 100644
42373--- a/drivers/media/radio/radio-shark.c
42374+++ b/drivers/media/radio/radio-shark.c
42375@@ -79,7 +79,7 @@ struct shark_device {
42376 u32 last_val;
42377 };
42378
42379-static atomic_t shark_instance = ATOMIC_INIT(0);
42380+static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
42381
42382 static void shark_write_val(struct snd_tea575x *tea, u32 val)
42383 {
42384diff --git a/drivers/media/radio/radio-shark2.c b/drivers/media/radio/radio-shark2.c
42385index 9fb6697..f167415 100644
42386--- a/drivers/media/radio/radio-shark2.c
42387+++ b/drivers/media/radio/radio-shark2.c
42388@@ -74,7 +74,7 @@ struct shark_device {
42389 u8 *transfer_buffer;
42390 };
42391
42392-static atomic_t shark_instance = ATOMIC_INIT(0);
42393+static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
42394
42395 static int shark_write_reg(struct radio_tea5777 *tea, u64 reg)
42396 {
42397diff --git a/drivers/media/radio/radio-si476x.c b/drivers/media/radio/radio-si476x.c
42398index 9c9084c..a9e8dfb 100644
42399--- a/drivers/media/radio/radio-si476x.c
42400+++ b/drivers/media/radio/radio-si476x.c
42401@@ -1445,7 +1445,7 @@ static int si476x_radio_probe(struct platform_device *pdev)
42402 struct si476x_radio *radio;
42403 struct v4l2_ctrl *ctrl;
42404
42405- static atomic_t instance = ATOMIC_INIT(0);
42406+ static atomic_unchecked_t instance = ATOMIC_INIT(0);
42407
42408 radio = devm_kzalloc(&pdev->dev, sizeof(*radio), GFP_KERNEL);
42409 if (!radio)
42410diff --git a/drivers/media/rc/rc-main.c b/drivers/media/rc/rc-main.c
42411index 46da365..3ba4206 100644
42412--- a/drivers/media/rc/rc-main.c
42413+++ b/drivers/media/rc/rc-main.c
42414@@ -1065,7 +1065,7 @@ EXPORT_SYMBOL_GPL(rc_free_device);
42415 int rc_register_device(struct rc_dev *dev)
42416 {
42417 static bool raw_init = false; /* raw decoders loaded? */
42418- static atomic_t devno = ATOMIC_INIT(0);
42419+ static atomic_unchecked_t devno = ATOMIC_INIT(0);
42420 struct rc_map *rc_map;
42421 const char *path;
42422 int rc;
42423@@ -1096,7 +1096,7 @@ int rc_register_device(struct rc_dev *dev)
42424 */
42425 mutex_lock(&dev->lock);
42426
42427- dev->devno = (unsigned long)(atomic_inc_return(&devno) - 1);
42428+ dev->devno = (unsigned long)(atomic_inc_return_unchecked(&devno) - 1);
42429 dev_set_name(&dev->dev, "rc%ld", dev->devno);
42430 dev_set_drvdata(&dev->dev, dev);
42431 rc = device_add(&dev->dev);
42432diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
42433index 3940bb0..fb3952a 100644
42434--- a/drivers/media/usb/dvb-usb/cxusb.c
42435+++ b/drivers/media/usb/dvb-usb/cxusb.c
42436@@ -1068,7 +1068,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
42437
42438 struct dib0700_adapter_state {
42439 int (*set_param_save) (struct dvb_frontend *);
42440-};
42441+} __no_const;
42442
42443 static int dib7070_set_param_override(struct dvb_frontend *fe)
42444 {
42445diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
42446index 6e237b6..dc25556 100644
42447--- a/drivers/media/usb/dvb-usb/dw2102.c
42448+++ b/drivers/media/usb/dvb-usb/dw2102.c
42449@@ -118,7 +118,7 @@ struct su3000_state {
42450
42451 struct s6x0_state {
42452 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
42453-};
42454+} __no_const;
42455
42456 /* debug */
42457 static int dvb_usb_dw2102_debug;
42458diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
42459index 8f7a6a4..59502dd 100644
42460--- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
42461+++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
42462@@ -326,7 +326,7 @@ struct v4l2_buffer32 {
42463 __u32 reserved;
42464 };
42465
42466-static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
42467+static int get_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
42468 enum v4l2_memory memory)
42469 {
42470 void __user *up_pln;
42471@@ -355,7 +355,7 @@ static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
42472 return 0;
42473 }
42474
42475-static int put_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
42476+static int put_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
42477 enum v4l2_memory memory)
42478 {
42479 if (copy_in_user(up32, up, 2 * sizeof(__u32)) ||
42480@@ -772,7 +772,7 @@ static int put_v4l2_subdev_edid32(struct v4l2_subdev_edid *kp, struct v4l2_subde
42481 put_user(kp->start_block, &up->start_block) ||
42482 put_user(kp->blocks, &up->blocks) ||
42483 put_user(tmp, &up->edid) ||
42484- copy_to_user(kp->reserved, up->reserved, sizeof(kp->reserved)))
42485+ copy_to_user(up->reserved, kp->reserved, sizeof(kp->reserved)))
42486 return -EFAULT;
42487 return 0;
42488 }
42489diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c
42490index 02d1b63..5fd6b16 100644
42491--- a/drivers/media/v4l2-core/v4l2-device.c
42492+++ b/drivers/media/v4l2-core/v4l2-device.c
42493@@ -75,9 +75,9 @@ int v4l2_device_put(struct v4l2_device *v4l2_dev)
42494 EXPORT_SYMBOL_GPL(v4l2_device_put);
42495
42496 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
42497- atomic_t *instance)
42498+ atomic_unchecked_t *instance)
42499 {
42500- int num = atomic_inc_return(instance) - 1;
42501+ int num = atomic_inc_return_unchecked(instance) - 1;
42502 int len = strlen(basename);
42503
42504 if (basename[len - 1] >= '0' && basename[len - 1] <= '9')
42505diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
42506index 68e6b5e..d8b923e 100644
42507--- a/drivers/media/v4l2-core/v4l2-ioctl.c
42508+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
42509@@ -1939,7 +1939,8 @@ struct v4l2_ioctl_info {
42510 struct file *file, void *fh, void *p);
42511 } u;
42512 void (*debug)(const void *arg, bool write_only);
42513-};
42514+} __do_const;
42515+typedef struct v4l2_ioctl_info __no_const v4l2_ioctl_info_no_const;
42516
42517 /* This control needs a priority check */
42518 #define INFO_FL_PRIO (1 << 0)
42519@@ -2120,7 +2121,7 @@ static long __video_do_ioctl(struct file *file,
42520 struct video_device *vfd = video_devdata(file);
42521 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
42522 bool write_only = false;
42523- struct v4l2_ioctl_info default_info;
42524+ v4l2_ioctl_info_no_const default_info;
42525 const struct v4l2_ioctl_info *info;
42526 void *fh = file->private_data;
42527 struct v4l2_fh *vfh = NULL;
42528@@ -2194,7 +2195,7 @@ done:
42529 }
42530
42531 static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
42532- void * __user *user_ptr, void ***kernel_ptr)
42533+ void __user **user_ptr, void ***kernel_ptr)
42534 {
42535 int ret = 0;
42536
42537@@ -2210,7 +2211,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
42538 ret = -EINVAL;
42539 break;
42540 }
42541- *user_ptr = (void __user *)buf->m.planes;
42542+ *user_ptr = (void __force_user *)buf->m.planes;
42543 *kernel_ptr = (void *)&buf->m.planes;
42544 *array_size = sizeof(struct v4l2_plane) * buf->length;
42545 ret = 1;
42546@@ -2245,7 +2246,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
42547 ret = -EINVAL;
42548 break;
42549 }
42550- *user_ptr = (void __user *)ctrls->controls;
42551+ *user_ptr = (void __force_user *)ctrls->controls;
42552 *kernel_ptr = (void *)&ctrls->controls;
42553 *array_size = sizeof(struct v4l2_ext_control)
42554 * ctrls->count;
42555diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
42556index 767ff4d..c69d259 100644
42557--- a/drivers/message/fusion/mptbase.c
42558+++ b/drivers/message/fusion/mptbase.c
42559@@ -6755,8 +6755,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
42560 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
42561 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
42562
42563+#ifdef CONFIG_GRKERNSEC_HIDESYM
42564+ seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
42565+#else
42566 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
42567 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
42568+#endif
42569+
42570 /*
42571 * Rounding UP to nearest 4-kB boundary here...
42572 */
42573@@ -6769,7 +6774,11 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
42574 ioc->facts.GlobalCredits);
42575
42576 seq_printf(m, " Frames @ 0x%p (Dma @ 0x%p)\n",
42577+#ifdef CONFIG_GRKERNSEC_HIDESYM
42578+ NULL, NULL);
42579+#else
42580 (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
42581+#endif
42582 sz = (ioc->reply_sz * ioc->reply_depth) + 128;
42583 seq_printf(m, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
42584 ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
42585diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
42586index dd239bd..689c4f7 100644
42587--- a/drivers/message/fusion/mptsas.c
42588+++ b/drivers/message/fusion/mptsas.c
42589@@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
42590 return 0;
42591 }
42592
42593+static inline void
42594+mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
42595+{
42596+ if (phy_info->port_details) {
42597+ phy_info->port_details->rphy = rphy;
42598+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
42599+ ioc->name, rphy));
42600+ }
42601+
42602+ if (rphy) {
42603+ dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
42604+ &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
42605+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
42606+ ioc->name, rphy, rphy->dev.release));
42607+ }
42608+}
42609+
42610 /* no mutex */
42611 static void
42612 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
42613@@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
42614 return NULL;
42615 }
42616
42617-static inline void
42618-mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
42619-{
42620- if (phy_info->port_details) {
42621- phy_info->port_details->rphy = rphy;
42622- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
42623- ioc->name, rphy));
42624- }
42625-
42626- if (rphy) {
42627- dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
42628- &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
42629- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
42630- ioc->name, rphy, rphy->dev.release));
42631- }
42632-}
42633-
42634 static inline struct sas_port *
42635 mptsas_get_port(struct mptsas_phyinfo *phy_info)
42636 {
42637diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
42638index 727819c..ad74694 100644
42639--- a/drivers/message/fusion/mptscsih.c
42640+++ b/drivers/message/fusion/mptscsih.c
42641@@ -1271,15 +1271,16 @@ mptscsih_info(struct Scsi_Host *SChost)
42642
42643 h = shost_priv(SChost);
42644
42645- if (h) {
42646- if (h->info_kbuf == NULL)
42647- if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
42648- return h->info_kbuf;
42649- h->info_kbuf[0] = '\0';
42650+ if (!h)
42651+ return NULL;
42652
42653- mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
42654- h->info_kbuf[size-1] = '\0';
42655- }
42656+ if (h->info_kbuf == NULL)
42657+ if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
42658+ return h->info_kbuf;
42659+ h->info_kbuf[0] = '\0';
42660+
42661+ mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
42662+ h->info_kbuf[size-1] = '\0';
42663
42664 return h->info_kbuf;
42665 }
42666diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
42667index b7d87cd..3fb36da 100644
42668--- a/drivers/message/i2o/i2o_proc.c
42669+++ b/drivers/message/i2o/i2o_proc.c
42670@@ -255,12 +255,6 @@ static char *scsi_devices[] = {
42671 "Array Controller Device"
42672 };
42673
42674-static char *chtostr(char *tmp, u8 *chars, int n)
42675-{
42676- tmp[0] = 0;
42677- return strncat(tmp, (char *)chars, n);
42678-}
42679-
42680 static int i2o_report_query_status(struct seq_file *seq, int block_status,
42681 char *group)
42682 {
42683@@ -707,9 +701,9 @@ static int i2o_seq_show_status(struct seq_file *seq, void *v)
42684 static int i2o_seq_show_hw(struct seq_file *seq, void *v)
42685 {
42686 struct i2o_controller *c = (struct i2o_controller *)seq->private;
42687- static u32 work32[5];
42688- static u8 *work8 = (u8 *) work32;
42689- static u16 *work16 = (u16 *) work32;
42690+ u32 work32[5];
42691+ u8 *work8 = (u8 *) work32;
42692+ u16 *work16 = (u16 *) work32;
42693 int token;
42694 u32 hwcap;
42695
42696@@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
42697 } *result;
42698
42699 i2o_exec_execute_ddm_table ddm_table;
42700- char tmp[28 + 1];
42701
42702 result = kmalloc(sizeof(*result), GFP_KERNEL);
42703 if (!result)
42704@@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
42705
42706 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
42707 seq_printf(seq, "%-#8x", ddm_table.module_id);
42708- seq_printf(seq, "%-29s",
42709- chtostr(tmp, ddm_table.module_name_version, 28));
42710+ seq_printf(seq, "%-.28s", ddm_table.module_name_version);
42711 seq_printf(seq, "%9d ", ddm_table.data_size);
42712 seq_printf(seq, "%8d", ddm_table.code_size);
42713
42714@@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
42715
42716 i2o_driver_result_table *result;
42717 i2o_driver_store_table *dst;
42718- char tmp[28 + 1];
42719
42720 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
42721 if (result == NULL)
42722@@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
42723
42724 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
42725 seq_printf(seq, "%-#8x", dst->module_id);
42726- seq_printf(seq, "%-29s",
42727- chtostr(tmp, dst->module_name_version, 28));
42728- seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
42729+ seq_printf(seq, "%-.28s", dst->module_name_version);
42730+ seq_printf(seq, "%-.8s", dst->date);
42731 seq_printf(seq, "%8d ", dst->module_size);
42732 seq_printf(seq, "%8d ", dst->mpb_size);
42733 seq_printf(seq, "0x%04x", dst->module_flags);
42734@@ -1246,11 +1236,10 @@ static int i2o_seq_show_authorized_users(struct seq_file *seq, void *v)
42735 static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
42736 {
42737 struct i2o_device *d = (struct i2o_device *)seq->private;
42738- static u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
42739+ u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
42740 // == (allow) 512d bytes (max)
42741- static u16 *work16 = (u16 *) work32;
42742+ u16 *work16 = (u16 *) work32;
42743 int token;
42744- char tmp[16 + 1];
42745
42746 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
42747
42748@@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
42749 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
42750 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
42751 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
42752- seq_printf(seq, "Vendor info : %s\n",
42753- chtostr(tmp, (u8 *) (work32 + 2), 16));
42754- seq_printf(seq, "Product info : %s\n",
42755- chtostr(tmp, (u8 *) (work32 + 6), 16));
42756- seq_printf(seq, "Description : %s\n",
42757- chtostr(tmp, (u8 *) (work32 + 10), 16));
42758- seq_printf(seq, "Product rev. : %s\n",
42759- chtostr(tmp, (u8 *) (work32 + 14), 8));
42760+ seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
42761+ seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
42762+ seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
42763+ seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
42764
42765 seq_printf(seq, "Serial number : ");
42766 print_serial_number(seq, (u8 *) (work32 + 16),
42767@@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
42768 u8 pad[256]; // allow up to 256 byte (max) serial number
42769 } result;
42770
42771- char tmp[24 + 1];
42772-
42773 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
42774
42775 if (token < 0) {
42776@@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
42777 }
42778
42779 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
42780- seq_printf(seq, "Module name : %s\n",
42781- chtostr(tmp, result.module_name, 24));
42782- seq_printf(seq, "Module revision : %s\n",
42783- chtostr(tmp, result.module_rev, 8));
42784+ seq_printf(seq, "Module name : %.24s\n", result.module_name);
42785+ seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
42786
42787 seq_printf(seq, "Serial number : ");
42788 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
42789@@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
42790 u8 instance_number[4];
42791 } result;
42792
42793- char tmp[64 + 1];
42794-
42795 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
42796
42797 if (token < 0) {
42798@@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
42799 return 0;
42800 }
42801
42802- seq_printf(seq, "Device name : %s\n",
42803- chtostr(tmp, result.device_name, 64));
42804- seq_printf(seq, "Service name : %s\n",
42805- chtostr(tmp, result.service_name, 64));
42806- seq_printf(seq, "Physical name : %s\n",
42807- chtostr(tmp, result.physical_location, 64));
42808- seq_printf(seq, "Instance number : %s\n",
42809- chtostr(tmp, result.instance_number, 4));
42810+ seq_printf(seq, "Device name : %.64s\n", result.device_name);
42811+ seq_printf(seq, "Service name : %.64s\n", result.service_name);
42812+ seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
42813+ seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
42814
42815 return 0;
42816 }
42817@@ -1368,9 +1343,9 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
42818 static int i2o_seq_show_sgl_limits(struct seq_file *seq, void *v)
42819 {
42820 struct i2o_device *d = (struct i2o_device *)seq->private;
42821- static u32 work32[12];
42822- static u16 *work16 = (u16 *) work32;
42823- static u8 *work8 = (u8 *) work32;
42824+ u32 work32[12];
42825+ u16 *work16 = (u16 *) work32;
42826+ u8 *work8 = (u8 *) work32;
42827 int token;
42828
42829 token = i2o_parm_field_get(d, 0xF103, -1, &work32, sizeof(work32));
42830diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
42831index a8c08f3..155fe3d 100644
42832--- a/drivers/message/i2o/iop.c
42833+++ b/drivers/message/i2o/iop.c
42834@@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
42835
42836 spin_lock_irqsave(&c->context_list_lock, flags);
42837
42838- if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
42839- atomic_inc(&c->context_list_counter);
42840+ if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
42841+ atomic_inc_unchecked(&c->context_list_counter);
42842
42843- entry->context = atomic_read(&c->context_list_counter);
42844+ entry->context = atomic_read_unchecked(&c->context_list_counter);
42845
42846 list_add(&entry->list, &c->context_list);
42847
42848@@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
42849
42850 #if BITS_PER_LONG == 64
42851 spin_lock_init(&c->context_list_lock);
42852- atomic_set(&c->context_list_counter, 0);
42853+ atomic_set_unchecked(&c->context_list_counter, 0);
42854 INIT_LIST_HEAD(&c->context_list);
42855 #endif
42856
42857diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
42858index fcbb2e9..2635e11 100644
42859--- a/drivers/mfd/janz-cmodio.c
42860+++ b/drivers/mfd/janz-cmodio.c
42861@@ -13,6 +13,7 @@
42862
42863 #include <linux/kernel.h>
42864 #include <linux/module.h>
42865+#include <linux/slab.h>
42866 #include <linux/init.h>
42867 #include <linux/pci.h>
42868 #include <linux/interrupt.h>
42869diff --git a/drivers/mfd/max8925-i2c.c b/drivers/mfd/max8925-i2c.c
42870index de7fb80..7c1b931 100644
42871--- a/drivers/mfd/max8925-i2c.c
42872+++ b/drivers/mfd/max8925-i2c.c
42873@@ -152,7 +152,7 @@ static int max8925_probe(struct i2c_client *client,
42874 const struct i2c_device_id *id)
42875 {
42876 struct max8925_platform_data *pdata = dev_get_platdata(&client->dev);
42877- static struct max8925_chip *chip;
42878+ struct max8925_chip *chip;
42879 struct device_node *node = client->dev.of_node;
42880
42881 if (node && !pdata) {
42882diff --git a/drivers/mfd/tps65910.c b/drivers/mfd/tps65910.c
42883index d792772..cd73ba3 100644
42884--- a/drivers/mfd/tps65910.c
42885+++ b/drivers/mfd/tps65910.c
42886@@ -229,7 +229,7 @@ static int tps65910_irq_init(struct tps65910 *tps65910, int irq,
42887 struct tps65910_platform_data *pdata)
42888 {
42889 int ret = 0;
42890- static struct regmap_irq_chip *tps6591x_irqs_chip;
42891+ struct regmap_irq_chip *tps6591x_irqs_chip;
42892
42893 if (!irq) {
42894 dev_warn(tps65910->dev, "No interrupt support, no core IRQ\n");
42895diff --git a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
42896index 9aa6d1e..1631bfc 100644
42897--- a/drivers/mfd/twl4030-irq.c
42898+++ b/drivers/mfd/twl4030-irq.c
42899@@ -35,6 +35,7 @@
42900 #include <linux/of.h>
42901 #include <linux/irqdomain.h>
42902 #include <linux/i2c/twl.h>
42903+#include <asm/pgtable.h>
42904
42905 #include "twl-core.h"
42906
42907@@ -726,10 +727,12 @@ int twl4030_init_irq(struct device *dev, int irq_num)
42908 * Install an irq handler for each of the SIH modules;
42909 * clone dummy irq_chip since PIH can't *do* anything
42910 */
42911- twl4030_irq_chip = dummy_irq_chip;
42912- twl4030_irq_chip.name = "twl4030";
42913+ pax_open_kernel();
42914+ memcpy((void *)&twl4030_irq_chip, &dummy_irq_chip, sizeof twl4030_irq_chip);
42915+ *(const char **)&twl4030_irq_chip.name = "twl4030";
42916
42917- twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
42918+ *(void **)&twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
42919+ pax_close_kernel();
42920
42921 for (i = irq_base; i < irq_end; i++) {
42922 irq_set_chip_and_handler(i, &twl4030_irq_chip,
42923diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c
42924index 464419b..64bae8d 100644
42925--- a/drivers/misc/c2port/core.c
42926+++ b/drivers/misc/c2port/core.c
42927@@ -922,7 +922,9 @@ struct c2port_device *c2port_device_register(char *name,
42928 goto error_idr_alloc;
42929 c2dev->id = ret;
42930
42931- bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
42932+ pax_open_kernel();
42933+ *(size_t *)&bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
42934+ pax_close_kernel();
42935
42936 c2dev->dev = device_create(c2port_class, NULL, 0, c2dev,
42937 "c2port%d", c2dev->id);
42938diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
42939index 36f5d52..32311c3 100644
42940--- a/drivers/misc/kgdbts.c
42941+++ b/drivers/misc/kgdbts.c
42942@@ -834,7 +834,7 @@ static void run_plant_and_detach_test(int is_early)
42943 char before[BREAK_INSTR_SIZE];
42944 char after[BREAK_INSTR_SIZE];
42945
42946- probe_kernel_read(before, (char *)kgdbts_break_test,
42947+ probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
42948 BREAK_INSTR_SIZE);
42949 init_simple_test();
42950 ts.tst = plant_and_detach_test;
42951@@ -842,7 +842,7 @@ static void run_plant_and_detach_test(int is_early)
42952 /* Activate test with initial breakpoint */
42953 if (!is_early)
42954 kgdb_breakpoint();
42955- probe_kernel_read(after, (char *)kgdbts_break_test,
42956+ probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
42957 BREAK_INSTR_SIZE);
42958 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
42959 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
42960diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
42961index 036effe..b3a6336 100644
42962--- a/drivers/misc/lis3lv02d/lis3lv02d.c
42963+++ b/drivers/misc/lis3lv02d/lis3lv02d.c
42964@@ -498,7 +498,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
42965 * the lid is closed. This leads to interrupts as soon as a little move
42966 * is done.
42967 */
42968- atomic_inc(&lis3->count);
42969+ atomic_inc_unchecked(&lis3->count);
42970
42971 wake_up_interruptible(&lis3->misc_wait);
42972 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
42973@@ -584,7 +584,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
42974 if (lis3->pm_dev)
42975 pm_runtime_get_sync(lis3->pm_dev);
42976
42977- atomic_set(&lis3->count, 0);
42978+ atomic_set_unchecked(&lis3->count, 0);
42979 return 0;
42980 }
42981
42982@@ -616,7 +616,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
42983 add_wait_queue(&lis3->misc_wait, &wait);
42984 while (true) {
42985 set_current_state(TASK_INTERRUPTIBLE);
42986- data = atomic_xchg(&lis3->count, 0);
42987+ data = atomic_xchg_unchecked(&lis3->count, 0);
42988 if (data)
42989 break;
42990
42991@@ -657,7 +657,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
42992 struct lis3lv02d, miscdev);
42993
42994 poll_wait(file, &lis3->misc_wait, wait);
42995- if (atomic_read(&lis3->count))
42996+ if (atomic_read_unchecked(&lis3->count))
42997 return POLLIN | POLLRDNORM;
42998 return 0;
42999 }
43000diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
43001index c439c82..1f20f57 100644
43002--- a/drivers/misc/lis3lv02d/lis3lv02d.h
43003+++ b/drivers/misc/lis3lv02d/lis3lv02d.h
43004@@ -297,7 +297,7 @@ struct lis3lv02d {
43005 struct input_polled_dev *idev; /* input device */
43006 struct platform_device *pdev; /* platform device */
43007 struct regulator_bulk_data regulators[2];
43008- atomic_t count; /* interrupt count after last read */
43009+ atomic_unchecked_t count; /* interrupt count after last read */
43010 union axis_conversion ac; /* hw -> logical axis */
43011 int mapped_btns[3];
43012
43013diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
43014index 2f30bad..c4c13d0 100644
43015--- a/drivers/misc/sgi-gru/gruhandles.c
43016+++ b/drivers/misc/sgi-gru/gruhandles.c
43017@@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
43018 unsigned long nsec;
43019
43020 nsec = CLKS2NSEC(clks);
43021- atomic_long_inc(&mcs_op_statistics[op].count);
43022- atomic_long_add(nsec, &mcs_op_statistics[op].total);
43023+ atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
43024+ atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
43025 if (mcs_op_statistics[op].max < nsec)
43026 mcs_op_statistics[op].max = nsec;
43027 }
43028diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
43029index 4f76359..cdfcb2e 100644
43030--- a/drivers/misc/sgi-gru/gruprocfs.c
43031+++ b/drivers/misc/sgi-gru/gruprocfs.c
43032@@ -32,9 +32,9 @@
43033
43034 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
43035
43036-static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
43037+static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
43038 {
43039- unsigned long val = atomic_long_read(v);
43040+ unsigned long val = atomic_long_read_unchecked(v);
43041
43042 seq_printf(s, "%16lu %s\n", val, id);
43043 }
43044@@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
43045
43046 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
43047 for (op = 0; op < mcsop_last; op++) {
43048- count = atomic_long_read(&mcs_op_statistics[op].count);
43049- total = atomic_long_read(&mcs_op_statistics[op].total);
43050+ count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
43051+ total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
43052 max = mcs_op_statistics[op].max;
43053 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
43054 count ? total / count : 0, max);
43055diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
43056index 5c3ce24..4915ccb 100644
43057--- a/drivers/misc/sgi-gru/grutables.h
43058+++ b/drivers/misc/sgi-gru/grutables.h
43059@@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
43060 * GRU statistics.
43061 */
43062 struct gru_stats_s {
43063- atomic_long_t vdata_alloc;
43064- atomic_long_t vdata_free;
43065- atomic_long_t gts_alloc;
43066- atomic_long_t gts_free;
43067- atomic_long_t gms_alloc;
43068- atomic_long_t gms_free;
43069- atomic_long_t gts_double_allocate;
43070- atomic_long_t assign_context;
43071- atomic_long_t assign_context_failed;
43072- atomic_long_t free_context;
43073- atomic_long_t load_user_context;
43074- atomic_long_t load_kernel_context;
43075- atomic_long_t lock_kernel_context;
43076- atomic_long_t unlock_kernel_context;
43077- atomic_long_t steal_user_context;
43078- atomic_long_t steal_kernel_context;
43079- atomic_long_t steal_context_failed;
43080- atomic_long_t nopfn;
43081- atomic_long_t asid_new;
43082- atomic_long_t asid_next;
43083- atomic_long_t asid_wrap;
43084- atomic_long_t asid_reuse;
43085- atomic_long_t intr;
43086- atomic_long_t intr_cbr;
43087- atomic_long_t intr_tfh;
43088- atomic_long_t intr_spurious;
43089- atomic_long_t intr_mm_lock_failed;
43090- atomic_long_t call_os;
43091- atomic_long_t call_os_wait_queue;
43092- atomic_long_t user_flush_tlb;
43093- atomic_long_t user_unload_context;
43094- atomic_long_t user_exception;
43095- atomic_long_t set_context_option;
43096- atomic_long_t check_context_retarget_intr;
43097- atomic_long_t check_context_unload;
43098- atomic_long_t tlb_dropin;
43099- atomic_long_t tlb_preload_page;
43100- atomic_long_t tlb_dropin_fail_no_asid;
43101- atomic_long_t tlb_dropin_fail_upm;
43102- atomic_long_t tlb_dropin_fail_invalid;
43103- atomic_long_t tlb_dropin_fail_range_active;
43104- atomic_long_t tlb_dropin_fail_idle;
43105- atomic_long_t tlb_dropin_fail_fmm;
43106- atomic_long_t tlb_dropin_fail_no_exception;
43107- atomic_long_t tfh_stale_on_fault;
43108- atomic_long_t mmu_invalidate_range;
43109- atomic_long_t mmu_invalidate_page;
43110- atomic_long_t flush_tlb;
43111- atomic_long_t flush_tlb_gru;
43112- atomic_long_t flush_tlb_gru_tgh;
43113- atomic_long_t flush_tlb_gru_zero_asid;
43114+ atomic_long_unchecked_t vdata_alloc;
43115+ atomic_long_unchecked_t vdata_free;
43116+ atomic_long_unchecked_t gts_alloc;
43117+ atomic_long_unchecked_t gts_free;
43118+ atomic_long_unchecked_t gms_alloc;
43119+ atomic_long_unchecked_t gms_free;
43120+ atomic_long_unchecked_t gts_double_allocate;
43121+ atomic_long_unchecked_t assign_context;
43122+ atomic_long_unchecked_t assign_context_failed;
43123+ atomic_long_unchecked_t free_context;
43124+ atomic_long_unchecked_t load_user_context;
43125+ atomic_long_unchecked_t load_kernel_context;
43126+ atomic_long_unchecked_t lock_kernel_context;
43127+ atomic_long_unchecked_t unlock_kernel_context;
43128+ atomic_long_unchecked_t steal_user_context;
43129+ atomic_long_unchecked_t steal_kernel_context;
43130+ atomic_long_unchecked_t steal_context_failed;
43131+ atomic_long_unchecked_t nopfn;
43132+ atomic_long_unchecked_t asid_new;
43133+ atomic_long_unchecked_t asid_next;
43134+ atomic_long_unchecked_t asid_wrap;
43135+ atomic_long_unchecked_t asid_reuse;
43136+ atomic_long_unchecked_t intr;
43137+ atomic_long_unchecked_t intr_cbr;
43138+ atomic_long_unchecked_t intr_tfh;
43139+ atomic_long_unchecked_t intr_spurious;
43140+ atomic_long_unchecked_t intr_mm_lock_failed;
43141+ atomic_long_unchecked_t call_os;
43142+ atomic_long_unchecked_t call_os_wait_queue;
43143+ atomic_long_unchecked_t user_flush_tlb;
43144+ atomic_long_unchecked_t user_unload_context;
43145+ atomic_long_unchecked_t user_exception;
43146+ atomic_long_unchecked_t set_context_option;
43147+ atomic_long_unchecked_t check_context_retarget_intr;
43148+ atomic_long_unchecked_t check_context_unload;
43149+ atomic_long_unchecked_t tlb_dropin;
43150+ atomic_long_unchecked_t tlb_preload_page;
43151+ atomic_long_unchecked_t tlb_dropin_fail_no_asid;
43152+ atomic_long_unchecked_t tlb_dropin_fail_upm;
43153+ atomic_long_unchecked_t tlb_dropin_fail_invalid;
43154+ atomic_long_unchecked_t tlb_dropin_fail_range_active;
43155+ atomic_long_unchecked_t tlb_dropin_fail_idle;
43156+ atomic_long_unchecked_t tlb_dropin_fail_fmm;
43157+ atomic_long_unchecked_t tlb_dropin_fail_no_exception;
43158+ atomic_long_unchecked_t tfh_stale_on_fault;
43159+ atomic_long_unchecked_t mmu_invalidate_range;
43160+ atomic_long_unchecked_t mmu_invalidate_page;
43161+ atomic_long_unchecked_t flush_tlb;
43162+ atomic_long_unchecked_t flush_tlb_gru;
43163+ atomic_long_unchecked_t flush_tlb_gru_tgh;
43164+ atomic_long_unchecked_t flush_tlb_gru_zero_asid;
43165
43166- atomic_long_t copy_gpa;
43167- atomic_long_t read_gpa;
43168+ atomic_long_unchecked_t copy_gpa;
43169+ atomic_long_unchecked_t read_gpa;
43170
43171- atomic_long_t mesq_receive;
43172- atomic_long_t mesq_receive_none;
43173- atomic_long_t mesq_send;
43174- atomic_long_t mesq_send_failed;
43175- atomic_long_t mesq_noop;
43176- atomic_long_t mesq_send_unexpected_error;
43177- atomic_long_t mesq_send_lb_overflow;
43178- atomic_long_t mesq_send_qlimit_reached;
43179- atomic_long_t mesq_send_amo_nacked;
43180- atomic_long_t mesq_send_put_nacked;
43181- atomic_long_t mesq_page_overflow;
43182- atomic_long_t mesq_qf_locked;
43183- atomic_long_t mesq_qf_noop_not_full;
43184- atomic_long_t mesq_qf_switch_head_failed;
43185- atomic_long_t mesq_qf_unexpected_error;
43186- atomic_long_t mesq_noop_unexpected_error;
43187- atomic_long_t mesq_noop_lb_overflow;
43188- atomic_long_t mesq_noop_qlimit_reached;
43189- atomic_long_t mesq_noop_amo_nacked;
43190- atomic_long_t mesq_noop_put_nacked;
43191- atomic_long_t mesq_noop_page_overflow;
43192+ atomic_long_unchecked_t mesq_receive;
43193+ atomic_long_unchecked_t mesq_receive_none;
43194+ atomic_long_unchecked_t mesq_send;
43195+ atomic_long_unchecked_t mesq_send_failed;
43196+ atomic_long_unchecked_t mesq_noop;
43197+ atomic_long_unchecked_t mesq_send_unexpected_error;
43198+ atomic_long_unchecked_t mesq_send_lb_overflow;
43199+ atomic_long_unchecked_t mesq_send_qlimit_reached;
43200+ atomic_long_unchecked_t mesq_send_amo_nacked;
43201+ atomic_long_unchecked_t mesq_send_put_nacked;
43202+ atomic_long_unchecked_t mesq_page_overflow;
43203+ atomic_long_unchecked_t mesq_qf_locked;
43204+ atomic_long_unchecked_t mesq_qf_noop_not_full;
43205+ atomic_long_unchecked_t mesq_qf_switch_head_failed;
43206+ atomic_long_unchecked_t mesq_qf_unexpected_error;
43207+ atomic_long_unchecked_t mesq_noop_unexpected_error;
43208+ atomic_long_unchecked_t mesq_noop_lb_overflow;
43209+ atomic_long_unchecked_t mesq_noop_qlimit_reached;
43210+ atomic_long_unchecked_t mesq_noop_amo_nacked;
43211+ atomic_long_unchecked_t mesq_noop_put_nacked;
43212+ atomic_long_unchecked_t mesq_noop_page_overflow;
43213
43214 };
43215
43216@@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
43217 tghop_invalidate, mcsop_last};
43218
43219 struct mcs_op_statistic {
43220- atomic_long_t count;
43221- atomic_long_t total;
43222+ atomic_long_unchecked_t count;
43223+ atomic_long_unchecked_t total;
43224 unsigned long max;
43225 };
43226
43227@@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
43228
43229 #define STAT(id) do { \
43230 if (gru_options & OPT_STATS) \
43231- atomic_long_inc(&gru_stats.id); \
43232+ atomic_long_inc_unchecked(&gru_stats.id); \
43233 } while (0)
43234
43235 #ifdef CONFIG_SGI_GRU_DEBUG
43236diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
43237index c862cd4..0d176fe 100644
43238--- a/drivers/misc/sgi-xp/xp.h
43239+++ b/drivers/misc/sgi-xp/xp.h
43240@@ -288,7 +288,7 @@ struct xpc_interface {
43241 xpc_notify_func, void *);
43242 void (*received) (short, int, void *);
43243 enum xp_retval (*partid_to_nasids) (short, void *);
43244-};
43245+} __no_const;
43246
43247 extern struct xpc_interface xpc_interface;
43248
43249diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
43250index b94d5f7..7f494c5 100644
43251--- a/drivers/misc/sgi-xp/xpc.h
43252+++ b/drivers/misc/sgi-xp/xpc.h
43253@@ -835,6 +835,7 @@ struct xpc_arch_operations {
43254 void (*received_payload) (struct xpc_channel *, void *);
43255 void (*notify_senders_of_disconnect) (struct xpc_channel *);
43256 };
43257+typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
43258
43259 /* struct xpc_partition act_state values (for XPC HB) */
43260
43261@@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
43262 /* found in xpc_main.c */
43263 extern struct device *xpc_part;
43264 extern struct device *xpc_chan;
43265-extern struct xpc_arch_operations xpc_arch_ops;
43266+extern xpc_arch_operations_no_const xpc_arch_ops;
43267 extern int xpc_disengage_timelimit;
43268 extern int xpc_disengage_timedout;
43269 extern int xpc_activate_IRQ_rcvd;
43270diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
43271index 82dc574..8539ab2 100644
43272--- a/drivers/misc/sgi-xp/xpc_main.c
43273+++ b/drivers/misc/sgi-xp/xpc_main.c
43274@@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
43275 .notifier_call = xpc_system_die,
43276 };
43277
43278-struct xpc_arch_operations xpc_arch_ops;
43279+xpc_arch_operations_no_const xpc_arch_ops;
43280
43281 /*
43282 * Timer function to enforce the timelimit on the partition disengage.
43283@@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
43284
43285 if (((die_args->trapnr == X86_TRAP_MF) ||
43286 (die_args->trapnr == X86_TRAP_XF)) &&
43287- !user_mode_vm(die_args->regs))
43288+ !user_mode(die_args->regs))
43289 xpc_die_deactivate();
43290
43291 break;
43292diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
43293index ef18348..1b53cf0 100644
43294--- a/drivers/mmc/core/mmc_ops.c
43295+++ b/drivers/mmc/core/mmc_ops.c
43296@@ -213,7 +213,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
43297 void *data_buf;
43298 int is_on_stack;
43299
43300- is_on_stack = object_is_on_stack(buf);
43301+ is_on_stack = object_starts_on_stack(buf);
43302 if (is_on_stack) {
43303 /*
43304 * dma onto stack is unsafe/nonportable, but callers to this
43305diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
43306index 81b2994..dce857e 100644
43307--- a/drivers/mmc/host/dw_mmc.h
43308+++ b/drivers/mmc/host/dw_mmc.h
43309@@ -203,5 +203,5 @@ struct dw_mci_drv_data {
43310 void (*prepare_command)(struct dw_mci *host, u32 *cmdr);
43311 void (*set_ios)(struct dw_mci *host, struct mmc_ios *ios);
43312 int (*parse_dt)(struct dw_mci *host);
43313-};
43314+} __do_const;
43315 #endif /* _DW_MMC_H_ */
43316diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c
43317index c3785ed..1984c44 100644
43318--- a/drivers/mmc/host/mmci.c
43319+++ b/drivers/mmc/host/mmci.c
43320@@ -1482,7 +1482,9 @@ static int mmci_probe(struct amba_device *dev,
43321 }
43322
43323 if (variant->busy_detect) {
43324- mmci_ops.card_busy = mmci_card_busy;
43325+ pax_open_kernel();
43326+ *(void **)&mmci_ops.card_busy = mmci_card_busy;
43327+ pax_close_kernel();
43328 mmci_write_datactrlreg(host, MCI_ST_DPSM_BUSYMODE);
43329 }
43330
43331diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
43332index 6debda9..2ba7427 100644
43333--- a/drivers/mmc/host/sdhci-s3c.c
43334+++ b/drivers/mmc/host/sdhci-s3c.c
43335@@ -668,9 +668,11 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
43336 * we can use overriding functions instead of default.
43337 */
43338 if (host->quirks & SDHCI_QUIRK_NONSTANDARD_CLOCK) {
43339- sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
43340- sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
43341- sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
43342+ pax_open_kernel();
43343+ *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
43344+ *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
43345+ *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
43346+ pax_close_kernel();
43347 }
43348
43349 /* It supports additional host capabilities if needed */
43350diff --git a/drivers/mtd/chips/cfi_cmdset_0020.c b/drivers/mtd/chips/cfi_cmdset_0020.c
43351index 096993f..f02c23b 100644
43352--- a/drivers/mtd/chips/cfi_cmdset_0020.c
43353+++ b/drivers/mtd/chips/cfi_cmdset_0020.c
43354@@ -669,7 +669,7 @@ cfi_staa_writev(struct mtd_info *mtd, const struct kvec *vecs,
43355 size_t totlen = 0, thislen;
43356 int ret = 0;
43357 size_t buflen = 0;
43358- static char *buffer;
43359+ char *buffer;
43360
43361 if (!ECCBUF_SIZE) {
43362 /* We should fall back to a general writev implementation.
43363diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
43364index 2ed2bb3..2d0b82e 100644
43365--- a/drivers/mtd/nand/denali.c
43366+++ b/drivers/mtd/nand/denali.c
43367@@ -24,6 +24,7 @@
43368 #include <linux/slab.h>
43369 #include <linux/mtd/mtd.h>
43370 #include <linux/module.h>
43371+#include <linux/slab.h>
43372
43373 #include "denali.h"
43374
43375diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
43376index 51b9d6a..52af9a7 100644
43377--- a/drivers/mtd/nftlmount.c
43378+++ b/drivers/mtd/nftlmount.c
43379@@ -24,6 +24,7 @@
43380 #include <asm/errno.h>
43381 #include <linux/delay.h>
43382 #include <linux/slab.h>
43383+#include <linux/sched.h>
43384 #include <linux/mtd/mtd.h>
43385 #include <linux/mtd/nand.h>
43386 #include <linux/mtd/nftl.h>
43387diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
43388index 4b8e895..6b3c498 100644
43389--- a/drivers/mtd/sm_ftl.c
43390+++ b/drivers/mtd/sm_ftl.c
43391@@ -56,7 +56,7 @@ static ssize_t sm_attr_show(struct device *dev, struct device_attribute *attr,
43392 #define SM_CIS_VENDOR_OFFSET 0x59
43393 static struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl)
43394 {
43395- struct attribute_group *attr_group;
43396+ attribute_group_no_const *attr_group;
43397 struct attribute **attributes;
43398 struct sm_sysfs_attribute *vendor_attribute;
43399
43400diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
43401index e883bfe..e51a1ec 100644
43402--- a/drivers/net/bonding/bond_main.c
43403+++ b/drivers/net/bonding/bond_main.c
43404@@ -4511,7 +4511,7 @@ static unsigned int bond_get_num_tx_queues(void)
43405 return tx_queues;
43406 }
43407
43408-static struct rtnl_link_ops bond_link_ops __read_mostly = {
43409+static struct rtnl_link_ops bond_link_ops = {
43410 .kind = "bond",
43411 .priv_size = sizeof(struct bonding),
43412 .setup = bond_setup,
43413@@ -4636,8 +4636,8 @@ static void __exit bonding_exit(void)
43414
43415 bond_destroy_debugfs();
43416
43417- rtnl_link_unregister(&bond_link_ops);
43418 unregister_pernet_subsys(&bond_net_ops);
43419+ rtnl_link_unregister(&bond_link_ops);
43420
43421 #ifdef CONFIG_NET_POLL_CONTROLLER
43422 /*
43423diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
43424index f92f001..0b2f9bf 100644
43425--- a/drivers/net/ethernet/8390/ax88796.c
43426+++ b/drivers/net/ethernet/8390/ax88796.c
43427@@ -872,9 +872,11 @@ static int ax_probe(struct platform_device *pdev)
43428 if (ax->plat->reg_offsets)
43429 ei_local->reg_offset = ax->plat->reg_offsets;
43430 else {
43431+ resource_size_t _mem_size = mem_size;
43432+ do_div(_mem_size, 0x18);
43433 ei_local->reg_offset = ax->reg_offsets;
43434 for (ret = 0; ret < 0x18; ret++)
43435- ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
43436+ ax->reg_offsets[ret] = _mem_size * ret;
43437 }
43438
43439 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
43440diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
43441index da8fcaa..f4b5d3b 100644
43442--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
43443+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
43444@@ -1138,7 +1138,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
43445 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
43446 {
43447 /* RX_MODE controlling object */
43448- bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
43449+ bnx2x_init_rx_mode_obj(bp);
43450
43451 /* multicast configuration controlling object */
43452 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
43453diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
43454index 9fbeee5..5e3e37a 100644
43455--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
43456+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
43457@@ -2590,15 +2590,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
43458 return rc;
43459 }
43460
43461-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
43462- struct bnx2x_rx_mode_obj *o)
43463+void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
43464 {
43465 if (CHIP_IS_E1x(bp)) {
43466- o->wait_comp = bnx2x_empty_rx_mode_wait;
43467- o->config_rx_mode = bnx2x_set_rx_mode_e1x;
43468+ bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
43469+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
43470 } else {
43471- o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
43472- o->config_rx_mode = bnx2x_set_rx_mode_e2;
43473+ bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
43474+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
43475 }
43476 }
43477
43478diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
43479index 658f4e3..15074a6 100644
43480--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
43481+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
43482@@ -1325,8 +1325,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
43483
43484 /********************* RX MODE ****************/
43485
43486-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
43487- struct bnx2x_rx_mode_obj *o);
43488+void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
43489
43490 /**
43491 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
43492diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
43493index 7025780..e55a71c 100644
43494--- a/drivers/net/ethernet/broadcom/tg3.h
43495+++ b/drivers/net/ethernet/broadcom/tg3.h
43496@@ -147,6 +147,7 @@
43497 #define CHIPREV_ID_5750_A0 0x4000
43498 #define CHIPREV_ID_5750_A1 0x4001
43499 #define CHIPREV_ID_5750_A3 0x4003
43500+#define CHIPREV_ID_5750_C1 0x4201
43501 #define CHIPREV_ID_5750_C2 0x4202
43502 #define CHIPREV_ID_5752_A0_HW 0x5000
43503 #define CHIPREV_ID_5752_A0 0x6000
43504diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
43505index 8cffcdf..aadf043 100644
43506--- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
43507+++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
43508@@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
43509 */
43510 struct l2t_skb_cb {
43511 arp_failure_handler_func arp_failure_handler;
43512-};
43513+} __no_const;
43514
43515 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
43516
43517diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
43518index c73cabd..cd278b1 100644
43519--- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
43520+++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
43521@@ -2186,7 +2186,7 @@ static void get_regs(struct net_device *dev, struct ethtool_regs *regs,
43522
43523 int i;
43524 struct adapter *ap = netdev2adap(dev);
43525- static const unsigned int *reg_ranges;
43526+ const unsigned int *reg_ranges;
43527 int arr_size = 0, buf_size = 0;
43528
43529 if (is_t4(ap->chip)) {
43530diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
43531index 263b92c..f05134b 100644
43532--- a/drivers/net/ethernet/dec/tulip/de4x5.c
43533+++ b/drivers/net/ethernet/dec/tulip/de4x5.c
43534@@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
43535 for (i=0; i<ETH_ALEN; i++) {
43536 tmp.addr[i] = dev->dev_addr[i];
43537 }
43538- if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
43539+ if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
43540 break;
43541
43542 case DE4X5_SET_HWADDR: /* Set the hardware address */
43543@@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
43544 spin_lock_irqsave(&lp->lock, flags);
43545 memcpy(&statbuf, &lp->pktStats, ioc->len);
43546 spin_unlock_irqrestore(&lp->lock, flags);
43547- if (copy_to_user(ioc->data, &statbuf, ioc->len))
43548+ if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
43549 return -EFAULT;
43550 break;
43551 }
43552diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
43553index 2c38cc4..0323f6e 100644
43554--- a/drivers/net/ethernet/emulex/benet/be_main.c
43555+++ b/drivers/net/ethernet/emulex/benet/be_main.c
43556@@ -470,7 +470,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
43557
43558 if (wrapped)
43559 newacc += 65536;
43560- ACCESS_ONCE(*acc) = newacc;
43561+ ACCESS_ONCE_RW(*acc) = newacc;
43562 }
43563
43564 static void populate_erx_stats(struct be_adapter *adapter,
43565diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
43566index 212f44b..fb69959 100644
43567--- a/drivers/net/ethernet/faraday/ftgmac100.c
43568+++ b/drivers/net/ethernet/faraday/ftgmac100.c
43569@@ -31,6 +31,8 @@
43570 #include <linux/netdevice.h>
43571 #include <linux/phy.h>
43572 #include <linux/platform_device.h>
43573+#include <linux/interrupt.h>
43574+#include <linux/irqreturn.h>
43575 #include <net/ip.h>
43576
43577 #include "ftgmac100.h"
43578diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
43579index 8be5b40..081bc1b 100644
43580--- a/drivers/net/ethernet/faraday/ftmac100.c
43581+++ b/drivers/net/ethernet/faraday/ftmac100.c
43582@@ -31,6 +31,8 @@
43583 #include <linux/module.h>
43584 #include <linux/netdevice.h>
43585 #include <linux/platform_device.h>
43586+#include <linux/interrupt.h>
43587+#include <linux/irqreturn.h>
43588
43589 #include "ftmac100.h"
43590
43591diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
43592index 5184e2a..acb28c3 100644
43593--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
43594+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
43595@@ -776,7 +776,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
43596 }
43597
43598 /* update the base incval used to calculate frequency adjustment */
43599- ACCESS_ONCE(adapter->base_incval) = incval;
43600+ ACCESS_ONCE_RW(adapter->base_incval) = incval;
43601 smp_mb();
43602
43603 /* need lock to prevent incorrect read while modifying cyclecounter */
43604diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
43605index fbe5363..266b4e3 100644
43606--- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
43607+++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
43608@@ -3461,7 +3461,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
43609 struct __vxge_hw_fifo *fifo;
43610 struct vxge_hw_fifo_config *config;
43611 u32 txdl_size, txdl_per_memblock;
43612- struct vxge_hw_mempool_cbs fifo_mp_callback;
43613+ static struct vxge_hw_mempool_cbs fifo_mp_callback = {
43614+ .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
43615+ };
43616+
43617 struct __vxge_hw_virtualpath *vpath;
43618
43619 if ((vp == NULL) || (attr == NULL)) {
43620@@ -3544,8 +3547,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
43621 goto exit;
43622 }
43623
43624- fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
43625-
43626 fifo->mempool =
43627 __vxge_hw_mempool_create(vpath->hldev,
43628 fifo->config->memblock_size,
43629diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
43630index f09e787..f3916a8 100644
43631--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
43632+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
43633@@ -2055,7 +2055,9 @@ int qlcnic_83xx_configure_opmode(struct qlcnic_adapter *adapter)
43634
43635 } else if (ret == QLC_83XX_DEFAULT_OPMODE) {
43636 ahw->nic_mode = QLC_83XX_DEFAULT_MODE;
43637- adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
43638+ pax_open_kernel();
43639+ *(void **)&adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
43640+ pax_close_kernel();
43641 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
43642 } else {
43643 return -EIO;
43644diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
43645index 0248a4c..9648d96 100644
43646--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
43647+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
43648@@ -191,17 +191,23 @@ int qlcnic_83xx_config_vnic_opmode(struct qlcnic_adapter *adapter)
43649 case QLCNIC_NON_PRIV_FUNC:
43650 ahw->op_mode = QLCNIC_NON_PRIV_FUNC;
43651 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
43652- nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
43653+ pax_open_kernel();
43654+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
43655+ pax_close_kernel();
43656 break;
43657 case QLCNIC_PRIV_FUNC:
43658 ahw->op_mode = QLCNIC_PRIV_FUNC;
43659 ahw->idc.state_entry = qlcnic_83xx_idc_vnic_pf_entry;
43660- nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
43661+ pax_open_kernel();
43662+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
43663+ pax_close_kernel();
43664 break;
43665 case QLCNIC_MGMT_FUNC:
43666 ahw->op_mode = QLCNIC_MGMT_FUNC;
43667 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
43668- nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
43669+ pax_open_kernel();
43670+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
43671+ pax_close_kernel();
43672 break;
43673 default:
43674 dev_err(&adapter->pdev->dev, "Invalid Virtual NIC opmode\n");
43675diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
43676index 1551360..ed6510f 100644
43677--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
43678+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
43679@@ -1108,7 +1108,7 @@ int qlcnic_dump_fw(struct qlcnic_adapter *adapter)
43680 struct qlcnic_dump_entry *entry;
43681 struct qlcnic_fw_dump *fw_dump = &adapter->ahw->fw_dump;
43682 struct qlcnic_dump_template_hdr *tmpl_hdr = fw_dump->tmpl_hdr;
43683- static const struct qlcnic_dump_operations *fw_dump_ops;
43684+ const struct qlcnic_dump_operations *fw_dump_ops;
43685 struct device *dev = &adapter->pdev->dev;
43686 struct qlcnic_hardware_context *ahw;
43687 void *temp_buffer;
43688diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
43689index 3397cee..101f8fa 100644
43690--- a/drivers/net/ethernet/realtek/r8169.c
43691+++ b/drivers/net/ethernet/realtek/r8169.c
43692@@ -759,22 +759,22 @@ struct rtl8169_private {
43693 struct mdio_ops {
43694 void (*write)(struct rtl8169_private *, int, int);
43695 int (*read)(struct rtl8169_private *, int);
43696- } mdio_ops;
43697+ } __no_const mdio_ops;
43698
43699 struct pll_power_ops {
43700 void (*down)(struct rtl8169_private *);
43701 void (*up)(struct rtl8169_private *);
43702- } pll_power_ops;
43703+ } __no_const pll_power_ops;
43704
43705 struct jumbo_ops {
43706 void (*enable)(struct rtl8169_private *);
43707 void (*disable)(struct rtl8169_private *);
43708- } jumbo_ops;
43709+ } __no_const jumbo_ops;
43710
43711 struct csi_ops {
43712 void (*write)(struct rtl8169_private *, int, int);
43713 u32 (*read)(struct rtl8169_private *, int);
43714- } csi_ops;
43715+ } __no_const csi_ops;
43716
43717 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
43718 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
43719diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
43720index 03acf57..e1251ff 100644
43721--- a/drivers/net/ethernet/sfc/ptp.c
43722+++ b/drivers/net/ethernet/sfc/ptp.c
43723@@ -539,7 +539,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
43724 ptp->start.dma_addr);
43725
43726 /* Clear flag that signals MC ready */
43727- ACCESS_ONCE(*start) = 0;
43728+ ACCESS_ONCE_RW(*start) = 0;
43729 rc = efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
43730 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
43731 EFX_BUG_ON_PARANOID(rc);
43732diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
43733index 50617c5..b13724c 100644
43734--- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
43735+++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
43736@@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
43737
43738 writel(value, ioaddr + MMC_CNTRL);
43739
43740- pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
43741- MMC_CNTRL, value);
43742+// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
43743+// MMC_CNTRL, value);
43744 }
43745
43746 /* To mask all all interrupts.*/
43747diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
43748index e6fe0d8..2b7d752 100644
43749--- a/drivers/net/hyperv/hyperv_net.h
43750+++ b/drivers/net/hyperv/hyperv_net.h
43751@@ -101,7 +101,7 @@ struct rndis_device {
43752
43753 enum rndis_device_state state;
43754 bool link_state;
43755- atomic_t new_req_id;
43756+ atomic_unchecked_t new_req_id;
43757
43758 spinlock_t request_lock;
43759 struct list_head req_list;
43760diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
43761index 0775f0a..d4fb316 100644
43762--- a/drivers/net/hyperv/rndis_filter.c
43763+++ b/drivers/net/hyperv/rndis_filter.c
43764@@ -104,7 +104,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
43765 * template
43766 */
43767 set = &rndis_msg->msg.set_req;
43768- set->req_id = atomic_inc_return(&dev->new_req_id);
43769+ set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
43770
43771 /* Add to the request list */
43772 spin_lock_irqsave(&dev->request_lock, flags);
43773@@ -752,7 +752,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
43774
43775 /* Setup the rndis set */
43776 halt = &request->request_msg.msg.halt_req;
43777- halt->req_id = atomic_inc_return(&dev->new_req_id);
43778+ halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
43779
43780 /* Ignore return since this msg is optional. */
43781 rndis_filter_send_request(dev, request);
43782diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
43783index bf0d55e..82bcfbd1 100644
43784--- a/drivers/net/ieee802154/fakehard.c
43785+++ b/drivers/net/ieee802154/fakehard.c
43786@@ -364,7 +364,7 @@ static int ieee802154fake_probe(struct platform_device *pdev)
43787 phy->transmit_power = 0xbf;
43788
43789 dev->netdev_ops = &fake_ops;
43790- dev->ml_priv = &fake_mlme;
43791+ dev->ml_priv = (void *)&fake_mlme;
43792
43793 priv = netdev_priv(dev);
43794 priv->phy = phy;
43795diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
43796index 9bf46bd..bfdaa84 100644
43797--- a/drivers/net/macvlan.c
43798+++ b/drivers/net/macvlan.c
43799@@ -939,13 +939,15 @@ static const struct nla_policy macvlan_policy[IFLA_MACVLAN_MAX + 1] = {
43800 int macvlan_link_register(struct rtnl_link_ops *ops)
43801 {
43802 /* common fields */
43803- ops->priv_size = sizeof(struct macvlan_dev);
43804- ops->validate = macvlan_validate;
43805- ops->maxtype = IFLA_MACVLAN_MAX;
43806- ops->policy = macvlan_policy;
43807- ops->changelink = macvlan_changelink;
43808- ops->get_size = macvlan_get_size;
43809- ops->fill_info = macvlan_fill_info;
43810+ pax_open_kernel();
43811+ *(size_t *)&ops->priv_size = sizeof(struct macvlan_dev);
43812+ *(void **)&ops->validate = macvlan_validate;
43813+ *(int *)&ops->maxtype = IFLA_MACVLAN_MAX;
43814+ *(const void **)&ops->policy = macvlan_policy;
43815+ *(void **)&ops->changelink = macvlan_changelink;
43816+ *(void **)&ops->get_size = macvlan_get_size;
43817+ *(void **)&ops->fill_info = macvlan_fill_info;
43818+ pax_close_kernel();
43819
43820 return rtnl_link_register(ops);
43821 };
43822@@ -1001,7 +1003,7 @@ static int macvlan_device_event(struct notifier_block *unused,
43823 return NOTIFY_DONE;
43824 }
43825
43826-static struct notifier_block macvlan_notifier_block __read_mostly = {
43827+static struct notifier_block macvlan_notifier_block = {
43828 .notifier_call = macvlan_device_event,
43829 };
43830
43831diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
43832index 9dccb1e..19fd4c9 100644
43833--- a/drivers/net/macvtap.c
43834+++ b/drivers/net/macvtap.c
43835@@ -1183,7 +1183,7 @@ static int macvtap_device_event(struct notifier_block *unused,
43836 return NOTIFY_DONE;
43837 }
43838
43839-static struct notifier_block macvtap_notifier_block __read_mostly = {
43840+static struct notifier_block macvtap_notifier_block = {
43841 .notifier_call = macvtap_device_event,
43842 };
43843
43844diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c
43845index daec9b0..6428fcb 100644
43846--- a/drivers/net/phy/mdio-bitbang.c
43847+++ b/drivers/net/phy/mdio-bitbang.c
43848@@ -234,6 +234,7 @@ void free_mdio_bitbang(struct mii_bus *bus)
43849 struct mdiobb_ctrl *ctrl = bus->priv;
43850
43851 module_put(ctrl->ops->owner);
43852+ mdiobus_unregister(bus);
43853 mdiobus_free(bus);
43854 }
43855 EXPORT_SYMBOL(free_mdio_bitbang);
43856diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
43857index 72ff14b..11d442d 100644
43858--- a/drivers/net/ppp/ppp_generic.c
43859+++ b/drivers/net/ppp/ppp_generic.c
43860@@ -999,7 +999,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
43861 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
43862 struct ppp_stats stats;
43863 struct ppp_comp_stats cstats;
43864- char *vers;
43865
43866 switch (cmd) {
43867 case SIOCGPPPSTATS:
43868@@ -1021,8 +1020,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
43869 break;
43870
43871 case SIOCGPPPVER:
43872- vers = PPP_VERSION;
43873- if (copy_to_user(addr, vers, strlen(vers) + 1))
43874+ if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
43875 break;
43876 err = 0;
43877 break;
43878diff --git a/drivers/net/slip/slhc.c b/drivers/net/slip/slhc.c
43879index 1252d9c..80e660b 100644
43880--- a/drivers/net/slip/slhc.c
43881+++ b/drivers/net/slip/slhc.c
43882@@ -488,7 +488,7 @@ slhc_uncompress(struct slcompress *comp, unsigned char *icp, int isize)
43883 register struct tcphdr *thp;
43884 register struct iphdr *ip;
43885 register struct cstate *cs;
43886- int len, hdrlen;
43887+ long len, hdrlen;
43888 unsigned char *cp = icp;
43889
43890 /* We've got a compressed packet; read the change byte */
43891diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
43892index 50e43e6..e1a5807 100644
43893--- a/drivers/net/team/team.c
43894+++ b/drivers/net/team/team.c
43895@@ -2869,7 +2869,7 @@ static int team_device_event(struct notifier_block *unused,
43896 return NOTIFY_DONE;
43897 }
43898
43899-static struct notifier_block team_notifier_block __read_mostly = {
43900+static struct notifier_block team_notifier_block = {
43901 .notifier_call = team_device_event,
43902 };
43903
43904diff --git a/drivers/net/tun.c b/drivers/net/tun.c
43905index 7cb105c..11214ff 100644
43906--- a/drivers/net/tun.c
43907+++ b/drivers/net/tun.c
43908@@ -1826,7 +1826,7 @@ unlock:
43909 }
43910
43911 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
43912- unsigned long arg, int ifreq_len)
43913+ unsigned long arg, size_t ifreq_len)
43914 {
43915 struct tun_file *tfile = file->private_data;
43916 struct tun_struct *tun;
43917@@ -1839,6 +1839,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
43918 unsigned int ifindex;
43919 int ret;
43920
43921+ if (ifreq_len > sizeof ifr)
43922+ return -EFAULT;
43923+
43924 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
43925 if (copy_from_user(&ifr, argp, ifreq_len))
43926 return -EFAULT;
43927diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
43928index 86292e6..8d34433 100644
43929--- a/drivers/net/usb/hso.c
43930+++ b/drivers/net/usb/hso.c
43931@@ -71,7 +71,7 @@
43932 #include <asm/byteorder.h>
43933 #include <linux/serial_core.h>
43934 #include <linux/serial.h>
43935-
43936+#include <asm/local.h>
43937
43938 #define MOD_AUTHOR "Option Wireless"
43939 #define MOD_DESCRIPTION "USB High Speed Option driver"
43940@@ -1180,7 +1180,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
43941 struct urb *urb;
43942
43943 urb = serial->rx_urb[0];
43944- if (serial->port.count > 0) {
43945+ if (atomic_read(&serial->port.count) > 0) {
43946 count = put_rxbuf_data(urb, serial);
43947 if (count == -1)
43948 return;
43949@@ -1216,7 +1216,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
43950 DUMP1(urb->transfer_buffer, urb->actual_length);
43951
43952 /* Anyone listening? */
43953- if (serial->port.count == 0)
43954+ if (atomic_read(&serial->port.count) == 0)
43955 return;
43956
43957 if (status == 0) {
43958@@ -1298,8 +1298,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
43959 tty_port_tty_set(&serial->port, tty);
43960
43961 /* check for port already opened, if not set the termios */
43962- serial->port.count++;
43963- if (serial->port.count == 1) {
43964+ if (atomic_inc_return(&serial->port.count) == 1) {
43965 serial->rx_state = RX_IDLE;
43966 /* Force default termio settings */
43967 _hso_serial_set_termios(tty, NULL);
43968@@ -1311,7 +1310,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
43969 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
43970 if (result) {
43971 hso_stop_serial_device(serial->parent);
43972- serial->port.count--;
43973+ atomic_dec(&serial->port.count);
43974 kref_put(&serial->parent->ref, hso_serial_ref_free);
43975 }
43976 } else {
43977@@ -1348,10 +1347,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
43978
43979 /* reset the rts and dtr */
43980 /* do the actual close */
43981- serial->port.count--;
43982+ atomic_dec(&serial->port.count);
43983
43984- if (serial->port.count <= 0) {
43985- serial->port.count = 0;
43986+ if (atomic_read(&serial->port.count) <= 0) {
43987+ atomic_set(&serial->port.count, 0);
43988 tty_port_tty_set(&serial->port, NULL);
43989 if (!usb_gone)
43990 hso_stop_serial_device(serial->parent);
43991@@ -1427,7 +1426,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
43992
43993 /* the actual setup */
43994 spin_lock_irqsave(&serial->serial_lock, flags);
43995- if (serial->port.count)
43996+ if (atomic_read(&serial->port.count))
43997 _hso_serial_set_termios(tty, old);
43998 else
43999 tty->termios = *old;
44000@@ -1886,7 +1885,7 @@ static void intr_callback(struct urb *urb)
44001 D1("Pending read interrupt on port %d\n", i);
44002 spin_lock(&serial->serial_lock);
44003 if (serial->rx_state == RX_IDLE &&
44004- serial->port.count > 0) {
44005+ atomic_read(&serial->port.count) > 0) {
44006 /* Setup and send a ctrl req read on
44007 * port i */
44008 if (!serial->rx_urb_filled[0]) {
44009@@ -3062,7 +3061,7 @@ static int hso_resume(struct usb_interface *iface)
44010 /* Start all serial ports */
44011 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
44012 if (serial_table[i] && (serial_table[i]->interface == iface)) {
44013- if (dev2ser(serial_table[i])->port.count) {
44014+ if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
44015 result =
44016 hso_start_serial_device(serial_table[i], GFP_NOIO);
44017 hso_kick_transmit(dev2ser(serial_table[i]));
44018diff --git a/drivers/net/usb/sierra_net.c b/drivers/net/usb/sierra_net.c
44019index a79e9d3..78cd4fa 100644
44020--- a/drivers/net/usb/sierra_net.c
44021+++ b/drivers/net/usb/sierra_net.c
44022@@ -52,7 +52,7 @@ static const char driver_name[] = "sierra_net";
44023 /* atomic counter partially included in MAC address to make sure 2 devices
44024 * do not end up with the same MAC - concept breaks in case of > 255 ifaces
44025 */
44026-static atomic_t iface_counter = ATOMIC_INIT(0);
44027+static atomic_unchecked_t iface_counter = ATOMIC_INIT(0);
44028
44029 /*
44030 * SYNC Timer Delay definition used to set the expiry time
44031@@ -698,7 +698,7 @@ static int sierra_net_bind(struct usbnet *dev, struct usb_interface *intf)
44032 dev->net->netdev_ops = &sierra_net_device_ops;
44033
44034 /* change MAC addr to include, ifacenum, and to be unique */
44035- dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return(&iface_counter);
44036+ dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return_unchecked(&iface_counter);
44037 dev->net->dev_addr[ETH_ALEN-1] = ifacenum;
44038
44039 /* we will have to manufacture ethernet headers, prepare template */
44040diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
44041index 2ef5b62..6fa0ec3 100644
44042--- a/drivers/net/vxlan.c
44043+++ b/drivers/net/vxlan.c
44044@@ -2615,7 +2615,7 @@ nla_put_failure:
44045 return -EMSGSIZE;
44046 }
44047
44048-static struct rtnl_link_ops vxlan_link_ops __read_mostly = {
44049+static struct rtnl_link_ops vxlan_link_ops = {
44050 .kind = "vxlan",
44051 .maxtype = IFLA_VXLAN_MAX,
44052 .policy = vxlan_policy,
44053diff --git a/drivers/net/wimax/i2400m/rx.c b/drivers/net/wimax/i2400m/rx.c
44054index 0b60295..b8bfa5b 100644
44055--- a/drivers/net/wimax/i2400m/rx.c
44056+++ b/drivers/net/wimax/i2400m/rx.c
44057@@ -1359,7 +1359,7 @@ int i2400m_rx_setup(struct i2400m *i2400m)
44058 if (i2400m->rx_roq == NULL)
44059 goto error_roq_alloc;
44060
44061- rd = kcalloc(I2400M_RO_CIN + 1, sizeof(*i2400m->rx_roq[0].log),
44062+ rd = kcalloc(sizeof(*i2400m->rx_roq[0].log), I2400M_RO_CIN + 1,
44063 GFP_KERNEL);
44064 if (rd == NULL) {
44065 result = -ENOMEM;
44066diff --git a/drivers/net/wireless/airo.c b/drivers/net/wireless/airo.c
44067index 7fe1964..7016de0 100644
44068--- a/drivers/net/wireless/airo.c
44069+++ b/drivers/net/wireless/airo.c
44070@@ -7844,7 +7844,7 @@ static int writerids(struct net_device *dev, aironet_ioctl *comp) {
44071 struct airo_info *ai = dev->ml_priv;
44072 int ridcode;
44073 int enabled;
44074- static int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
44075+ int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
44076 unsigned char *iobuf;
44077
44078 /* Only super-user can write RIDs */
44079diff --git a/drivers/net/wireless/at76c50x-usb.c b/drivers/net/wireless/at76c50x-usb.c
44080index 34c8a33..3261fdc 100644
44081--- a/drivers/net/wireless/at76c50x-usb.c
44082+++ b/drivers/net/wireless/at76c50x-usb.c
44083@@ -353,7 +353,7 @@ static int at76_dfu_get_state(struct usb_device *udev, u8 *state)
44084 }
44085
44086 /* Convert timeout from the DFU status to jiffies */
44087-static inline unsigned long at76_get_timeout(struct dfu_status *s)
44088+static inline unsigned long __intentional_overflow(-1) at76_get_timeout(struct dfu_status *s)
44089 {
44090 return msecs_to_jiffies((s->poll_timeout[2] << 16)
44091 | (s->poll_timeout[1] << 8)
44092diff --git a/drivers/net/wireless/ath/ath10k/htc.c b/drivers/net/wireless/ath/ath10k/htc.c
44093index ef3329e..c28ff5d 100644
44094--- a/drivers/net/wireless/ath/ath10k/htc.c
44095+++ b/drivers/net/wireless/ath/ath10k/htc.c
44096@@ -963,7 +963,10 @@ void ath10k_htc_stop(struct ath10k_htc *htc)
44097 /* registered target arrival callback from the HIF layer */
44098 int ath10k_htc_init(struct ath10k *ar)
44099 {
44100- struct ath10k_hif_cb htc_callbacks;
44101+ static struct ath10k_hif_cb htc_callbacks = {
44102+ .rx_completion = ath10k_htc_rx_completion_handler,
44103+ .tx_completion = ath10k_htc_tx_completion_handler,
44104+ };
44105 struct ath10k_htc_ep *ep = NULL;
44106 struct ath10k_htc *htc = &ar->htc;
44107
44108@@ -973,8 +976,6 @@ int ath10k_htc_init(struct ath10k *ar)
44109 ath10k_htc_reset_endpoint_states(htc);
44110
44111 /* setup HIF layer callbacks */
44112- htc_callbacks.rx_completion = ath10k_htc_rx_completion_handler;
44113- htc_callbacks.tx_completion = ath10k_htc_tx_completion_handler;
44114 htc->ar = ar;
44115
44116 /* Get HIF default pipe for HTC message exchange */
44117diff --git a/drivers/net/wireless/ath/ath10k/htc.h b/drivers/net/wireless/ath/ath10k/htc.h
44118index e1dd8c7..9f91b3f 100644
44119--- a/drivers/net/wireless/ath/ath10k/htc.h
44120+++ b/drivers/net/wireless/ath/ath10k/htc.h
44121@@ -271,12 +271,12 @@ enum ath10k_htc_ep_id {
44122
44123 struct ath10k_htc_ops {
44124 void (*target_send_suspend_complete)(struct ath10k *ar);
44125-};
44126+} __no_const;
44127
44128 struct ath10k_htc_ep_ops {
44129 void (*ep_tx_complete)(struct ath10k *, struct sk_buff *);
44130 void (*ep_rx_complete)(struct ath10k *, struct sk_buff *);
44131-};
44132+} __no_const;
44133
44134 /* service connection information */
44135 struct ath10k_htc_svc_conn_req {
44136diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
44137index 8d78253..bebbb68 100644
44138--- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
44139+++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
44140@@ -184,8 +184,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44141 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
44142 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
44143
44144- ACCESS_ONCE(ads->ds_link) = i->link;
44145- ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
44146+ ACCESS_ONCE_RW(ads->ds_link) = i->link;
44147+ ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
44148
44149 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
44150 ctl6 = SM(i->keytype, AR_EncrType);
44151@@ -199,26 +199,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44152
44153 if ((i->is_first || i->is_last) &&
44154 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
44155- ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
44156+ ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
44157 | set11nTries(i->rates, 1)
44158 | set11nTries(i->rates, 2)
44159 | set11nTries(i->rates, 3)
44160 | (i->dur_update ? AR_DurUpdateEna : 0)
44161 | SM(0, AR_BurstDur);
44162
44163- ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
44164+ ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
44165 | set11nRate(i->rates, 1)
44166 | set11nRate(i->rates, 2)
44167 | set11nRate(i->rates, 3);
44168 } else {
44169- ACCESS_ONCE(ads->ds_ctl2) = 0;
44170- ACCESS_ONCE(ads->ds_ctl3) = 0;
44171+ ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
44172+ ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
44173 }
44174
44175 if (!i->is_first) {
44176- ACCESS_ONCE(ads->ds_ctl0) = 0;
44177- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
44178- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
44179+ ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
44180+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
44181+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
44182 return;
44183 }
44184
44185@@ -243,7 +243,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44186 break;
44187 }
44188
44189- ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
44190+ ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
44191 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
44192 | SM(i->txpower, AR_XmitPower)
44193 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
44194@@ -253,19 +253,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44195 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
44196 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
44197
44198- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
44199- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
44200+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
44201+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
44202
44203 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
44204 return;
44205
44206- ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
44207+ ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
44208 | set11nPktDurRTSCTS(i->rates, 1);
44209
44210- ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
44211+ ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
44212 | set11nPktDurRTSCTS(i->rates, 3);
44213
44214- ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
44215+ ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
44216 | set11nRateFlags(i->rates, 1)
44217 | set11nRateFlags(i->rates, 2)
44218 | set11nRateFlags(i->rates, 3)
44219diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
44220index f6c5c1b..6058354 100644
44221--- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
44222+++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
44223@@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44224 (i->qcu << AR_TxQcuNum_S) | desc_len;
44225
44226 checksum += val;
44227- ACCESS_ONCE(ads->info) = val;
44228+ ACCESS_ONCE_RW(ads->info) = val;
44229
44230 checksum += i->link;
44231- ACCESS_ONCE(ads->link) = i->link;
44232+ ACCESS_ONCE_RW(ads->link) = i->link;
44233
44234 checksum += i->buf_addr[0];
44235- ACCESS_ONCE(ads->data0) = i->buf_addr[0];
44236+ ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
44237 checksum += i->buf_addr[1];
44238- ACCESS_ONCE(ads->data1) = i->buf_addr[1];
44239+ ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
44240 checksum += i->buf_addr[2];
44241- ACCESS_ONCE(ads->data2) = i->buf_addr[2];
44242+ ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
44243 checksum += i->buf_addr[3];
44244- ACCESS_ONCE(ads->data3) = i->buf_addr[3];
44245+ ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
44246
44247 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
44248- ACCESS_ONCE(ads->ctl3) = val;
44249+ ACCESS_ONCE_RW(ads->ctl3) = val;
44250 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
44251- ACCESS_ONCE(ads->ctl5) = val;
44252+ ACCESS_ONCE_RW(ads->ctl5) = val;
44253 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
44254- ACCESS_ONCE(ads->ctl7) = val;
44255+ ACCESS_ONCE_RW(ads->ctl7) = val;
44256 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
44257- ACCESS_ONCE(ads->ctl9) = val;
44258+ ACCESS_ONCE_RW(ads->ctl9) = val;
44259
44260 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
44261- ACCESS_ONCE(ads->ctl10) = checksum;
44262+ ACCESS_ONCE_RW(ads->ctl10) = checksum;
44263
44264 if (i->is_first || i->is_last) {
44265- ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
44266+ ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
44267 | set11nTries(i->rates, 1)
44268 | set11nTries(i->rates, 2)
44269 | set11nTries(i->rates, 3)
44270 | (i->dur_update ? AR_DurUpdateEna : 0)
44271 | SM(0, AR_BurstDur);
44272
44273- ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
44274+ ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
44275 | set11nRate(i->rates, 1)
44276 | set11nRate(i->rates, 2)
44277 | set11nRate(i->rates, 3);
44278 } else {
44279- ACCESS_ONCE(ads->ctl13) = 0;
44280- ACCESS_ONCE(ads->ctl14) = 0;
44281+ ACCESS_ONCE_RW(ads->ctl13) = 0;
44282+ ACCESS_ONCE_RW(ads->ctl14) = 0;
44283 }
44284
44285 ads->ctl20 = 0;
44286@@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44287
44288 ctl17 = SM(i->keytype, AR_EncrType);
44289 if (!i->is_first) {
44290- ACCESS_ONCE(ads->ctl11) = 0;
44291- ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
44292- ACCESS_ONCE(ads->ctl15) = 0;
44293- ACCESS_ONCE(ads->ctl16) = 0;
44294- ACCESS_ONCE(ads->ctl17) = ctl17;
44295- ACCESS_ONCE(ads->ctl18) = 0;
44296- ACCESS_ONCE(ads->ctl19) = 0;
44297+ ACCESS_ONCE_RW(ads->ctl11) = 0;
44298+ ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
44299+ ACCESS_ONCE_RW(ads->ctl15) = 0;
44300+ ACCESS_ONCE_RW(ads->ctl16) = 0;
44301+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
44302+ ACCESS_ONCE_RW(ads->ctl18) = 0;
44303+ ACCESS_ONCE_RW(ads->ctl19) = 0;
44304 return;
44305 }
44306
44307- ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
44308+ ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
44309 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
44310 | SM(i->txpower, AR_XmitPower)
44311 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
44312@@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44313 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
44314 ctl12 |= SM(val, AR_PAPRDChainMask);
44315
44316- ACCESS_ONCE(ads->ctl12) = ctl12;
44317- ACCESS_ONCE(ads->ctl17) = ctl17;
44318+ ACCESS_ONCE_RW(ads->ctl12) = ctl12;
44319+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
44320
44321- ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
44322+ ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
44323 | set11nPktDurRTSCTS(i->rates, 1);
44324
44325- ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
44326+ ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
44327 | set11nPktDurRTSCTS(i->rates, 3);
44328
44329- ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
44330+ ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
44331 | set11nRateFlags(i->rates, 1)
44332 | set11nRateFlags(i->rates, 2)
44333 | set11nRateFlags(i->rates, 3)
44334 | SM(i->rtscts_rate, AR_RTSCTSRate);
44335
44336- ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
44337+ ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
44338 }
44339
44340 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
44341diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
44342index 69a907b..91e071c 100644
44343--- a/drivers/net/wireless/ath/ath9k/hw.h
44344+++ b/drivers/net/wireless/ath/ath9k/hw.h
44345@@ -657,7 +657,7 @@ struct ath_hw_private_ops {
44346
44347 /* ANI */
44348 void (*ani_cache_ini_regs)(struct ath_hw *ah);
44349-};
44350+} __no_const;
44351
44352 /**
44353 * struct ath_spec_scan - parameters for Atheros spectral scan
44354@@ -729,7 +729,7 @@ struct ath_hw_ops {
44355 #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
44356 void (*set_bt_ant_diversity)(struct ath_hw *hw, bool enable);
44357 #endif
44358-};
44359+} __no_const;
44360
44361 struct ath_nf_limits {
44362 s16 max;
44363diff --git a/drivers/net/wireless/b43/phy_lp.c b/drivers/net/wireless/b43/phy_lp.c
44364index 92190da..f3a4c4c 100644
44365--- a/drivers/net/wireless/b43/phy_lp.c
44366+++ b/drivers/net/wireless/b43/phy_lp.c
44367@@ -2514,7 +2514,7 @@ static int lpphy_b2063_tune(struct b43_wldev *dev,
44368 {
44369 struct ssb_bus *bus = dev->dev->sdev->bus;
44370
44371- static const struct b206x_channel *chandata = NULL;
44372+ const struct b206x_channel *chandata = NULL;
44373 u32 crystal_freq = bus->chipco.pmu.crystalfreq * 1000;
44374 u32 freqref, vco_freq, val1, val2, val3, timeout, timeoutref, count;
44375 u16 old_comm15, scale;
44376diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
44377index 9581d07..84f6a76 100644
44378--- a/drivers/net/wireless/iwlegacy/3945-mac.c
44379+++ b/drivers/net/wireless/iwlegacy/3945-mac.c
44380@@ -3639,7 +3639,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
44381 */
44382 if (il3945_mod_params.disable_hw_scan) {
44383 D_INFO("Disabling hw_scan\n");
44384- il3945_mac_ops.hw_scan = NULL;
44385+ pax_open_kernel();
44386+ *(void **)&il3945_mac_ops.hw_scan = NULL;
44387+ pax_close_kernel();
44388 }
44389
44390 D_INFO("*** LOAD DRIVER ***\n");
44391diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
44392index d94f8ab..5b568c8 100644
44393--- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
44394+++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
44395@@ -188,7 +188,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
44396 {
44397 struct iwl_priv *priv = file->private_data;
44398 char buf[64];
44399- int buf_size;
44400+ size_t buf_size;
44401 u32 offset, len;
44402
44403 memset(buf, 0, sizeof(buf));
44404@@ -458,7 +458,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
44405 struct iwl_priv *priv = file->private_data;
44406
44407 char buf[8];
44408- int buf_size;
44409+ size_t buf_size;
44410 u32 reset_flag;
44411
44412 memset(buf, 0, sizeof(buf));
44413@@ -539,7 +539,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
44414 {
44415 struct iwl_priv *priv = file->private_data;
44416 char buf[8];
44417- int buf_size;
44418+ size_t buf_size;
44419 int ht40;
44420
44421 memset(buf, 0, sizeof(buf));
44422@@ -591,7 +591,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
44423 {
44424 struct iwl_priv *priv = file->private_data;
44425 char buf[8];
44426- int buf_size;
44427+ size_t buf_size;
44428 int value;
44429
44430 memset(buf, 0, sizeof(buf));
44431@@ -683,10 +683,10 @@ DEBUGFS_READ_FILE_OPS(temperature);
44432 DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
44433 DEBUGFS_READ_FILE_OPS(current_sleep_command);
44434
44435-static const char *fmt_value = " %-30s %10u\n";
44436-static const char *fmt_hex = " %-30s 0x%02X\n";
44437-static const char *fmt_table = " %-30s %10u %10u %10u %10u\n";
44438-static const char *fmt_header =
44439+static const char fmt_value[] = " %-30s %10u\n";
44440+static const char fmt_hex[] = " %-30s 0x%02X\n";
44441+static const char fmt_table[] = " %-30s %10u %10u %10u %10u\n";
44442+static const char fmt_header[] =
44443 "%-32s current cumulative delta max\n";
44444
44445 static int iwl_statistics_flag(struct iwl_priv *priv, char *buf, int bufsz)
44446@@ -1856,7 +1856,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
44447 {
44448 struct iwl_priv *priv = file->private_data;
44449 char buf[8];
44450- int buf_size;
44451+ size_t buf_size;
44452 int clear;
44453
44454 memset(buf, 0, sizeof(buf));
44455@@ -1901,7 +1901,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
44456 {
44457 struct iwl_priv *priv = file->private_data;
44458 char buf[8];
44459- int buf_size;
44460+ size_t buf_size;
44461 int trace;
44462
44463 memset(buf, 0, sizeof(buf));
44464@@ -1972,7 +1972,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
44465 {
44466 struct iwl_priv *priv = file->private_data;
44467 char buf[8];
44468- int buf_size;
44469+ size_t buf_size;
44470 int missed;
44471
44472 memset(buf, 0, sizeof(buf));
44473@@ -2013,7 +2013,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
44474
44475 struct iwl_priv *priv = file->private_data;
44476 char buf[8];
44477- int buf_size;
44478+ size_t buf_size;
44479 int plcp;
44480
44481 memset(buf, 0, sizeof(buf));
44482@@ -2073,7 +2073,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
44483
44484 struct iwl_priv *priv = file->private_data;
44485 char buf[8];
44486- int buf_size;
44487+ size_t buf_size;
44488 int flush;
44489
44490 memset(buf, 0, sizeof(buf));
44491@@ -2163,7 +2163,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
44492
44493 struct iwl_priv *priv = file->private_data;
44494 char buf[8];
44495- int buf_size;
44496+ size_t buf_size;
44497 int rts;
44498
44499 if (!priv->cfg->ht_params)
44500@@ -2205,7 +2205,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
44501 {
44502 struct iwl_priv *priv = file->private_data;
44503 char buf[8];
44504- int buf_size;
44505+ size_t buf_size;
44506
44507 memset(buf, 0, sizeof(buf));
44508 buf_size = min(count, sizeof(buf) - 1);
44509@@ -2239,7 +2239,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
44510 struct iwl_priv *priv = file->private_data;
44511 u32 event_log_flag;
44512 char buf[8];
44513- int buf_size;
44514+ size_t buf_size;
44515
44516 /* check that the interface is up */
44517 if (!iwl_is_ready(priv))
44518@@ -2293,7 +2293,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
44519 struct iwl_priv *priv = file->private_data;
44520 char buf[8];
44521 u32 calib_disabled;
44522- int buf_size;
44523+ size_t buf_size;
44524
44525 memset(buf, 0, sizeof(buf));
44526 buf_size = min(count, sizeof(buf) - 1);
44527diff --git a/drivers/net/wireless/iwlwifi/dvm/main.c b/drivers/net/wireless/iwlwifi/dvm/main.c
44528index 7aad766..06addb4 100644
44529--- a/drivers/net/wireless/iwlwifi/dvm/main.c
44530+++ b/drivers/net/wireless/iwlwifi/dvm/main.c
44531@@ -1123,7 +1123,7 @@ static void iwl_option_config(struct iwl_priv *priv)
44532 static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
44533 {
44534 struct iwl_nvm_data *data = priv->nvm_data;
44535- char *debug_msg;
44536+ static const char debug_msg[] = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
44537
44538 if (data->sku_cap_11n_enable &&
44539 !priv->cfg->ht_params) {
44540@@ -1137,7 +1137,6 @@ static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
44541 return -EINVAL;
44542 }
44543
44544- debug_msg = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
44545 IWL_DEBUG_INFO(priv, debug_msg,
44546 data->sku_cap_band_24GHz_enable ? "" : "NOT", "enabled",
44547 data->sku_cap_band_52GHz_enable ? "" : "NOT", "enabled",
44548diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
44549index c3f904d..4cadf83 100644
44550--- a/drivers/net/wireless/iwlwifi/pcie/trans.c
44551+++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
44552@@ -1252,7 +1252,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
44553 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
44554
44555 char buf[8];
44556- int buf_size;
44557+ size_t buf_size;
44558 u32 reset_flag;
44559
44560 memset(buf, 0, sizeof(buf));
44561@@ -1273,7 +1273,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
44562 {
44563 struct iwl_trans *trans = file->private_data;
44564 char buf[8];
44565- int buf_size;
44566+ size_t buf_size;
44567 int csr;
44568
44569 memset(buf, 0, sizeof(buf));
44570diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
44571index 2cd3f54..e936f90 100644
44572--- a/drivers/net/wireless/mac80211_hwsim.c
44573+++ b/drivers/net/wireless/mac80211_hwsim.c
44574@@ -2196,25 +2196,19 @@ static int __init init_mac80211_hwsim(void)
44575
44576 if (channels > 1) {
44577 hwsim_if_comb.num_different_channels = channels;
44578- mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
44579- mac80211_hwsim_ops.cancel_hw_scan =
44580- mac80211_hwsim_cancel_hw_scan;
44581- mac80211_hwsim_ops.sw_scan_start = NULL;
44582- mac80211_hwsim_ops.sw_scan_complete = NULL;
44583- mac80211_hwsim_ops.remain_on_channel =
44584- mac80211_hwsim_roc;
44585- mac80211_hwsim_ops.cancel_remain_on_channel =
44586- mac80211_hwsim_croc;
44587- mac80211_hwsim_ops.add_chanctx =
44588- mac80211_hwsim_add_chanctx;
44589- mac80211_hwsim_ops.remove_chanctx =
44590- mac80211_hwsim_remove_chanctx;
44591- mac80211_hwsim_ops.change_chanctx =
44592- mac80211_hwsim_change_chanctx;
44593- mac80211_hwsim_ops.assign_vif_chanctx =
44594- mac80211_hwsim_assign_vif_chanctx;
44595- mac80211_hwsim_ops.unassign_vif_chanctx =
44596- mac80211_hwsim_unassign_vif_chanctx;
44597+ pax_open_kernel();
44598+ *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
44599+ *(void **)&mac80211_hwsim_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
44600+ *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
44601+ *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
44602+ *(void **)&mac80211_hwsim_ops.remain_on_channel = mac80211_hwsim_roc;
44603+ *(void **)&mac80211_hwsim_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
44604+ *(void **)&mac80211_hwsim_ops.add_chanctx = mac80211_hwsim_add_chanctx;
44605+ *(void **)&mac80211_hwsim_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
44606+ *(void **)&mac80211_hwsim_ops.change_chanctx = mac80211_hwsim_change_chanctx;
44607+ *(void **)&mac80211_hwsim_ops.assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx;
44608+ *(void **)&mac80211_hwsim_ops.unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx;
44609+ pax_close_kernel();
44610 }
44611
44612 spin_lock_init(&hwsim_radio_lock);
44613diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
44614index 8169a85..7fa3b47 100644
44615--- a/drivers/net/wireless/rndis_wlan.c
44616+++ b/drivers/net/wireless/rndis_wlan.c
44617@@ -1238,7 +1238,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
44618
44619 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
44620
44621- if (rts_threshold < 0 || rts_threshold > 2347)
44622+ if (rts_threshold > 2347)
44623 rts_threshold = 2347;
44624
44625 tmp = cpu_to_le32(rts_threshold);
44626diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
44627index fe4c572..99dedfa 100644
44628--- a/drivers/net/wireless/rt2x00/rt2x00.h
44629+++ b/drivers/net/wireless/rt2x00/rt2x00.h
44630@@ -387,7 +387,7 @@ struct rt2x00_intf {
44631 * for hardware which doesn't support hardware
44632 * sequence counting.
44633 */
44634- atomic_t seqno;
44635+ atomic_unchecked_t seqno;
44636 };
44637
44638 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
44639diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
44640index 6c8a33b..78212fa 100644
44641--- a/drivers/net/wireless/rt2x00/rt2x00queue.c
44642+++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
44643@@ -252,9 +252,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
44644 * sequence counter given by mac80211.
44645 */
44646 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
44647- seqno = atomic_add_return(0x10, &intf->seqno);
44648+ seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
44649 else
44650- seqno = atomic_read(&intf->seqno);
44651+ seqno = atomic_read_unchecked(&intf->seqno);
44652
44653 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
44654 hdr->seq_ctrl |= cpu_to_le16(seqno);
44655diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
44656index e2b3d9c..67a5184 100644
44657--- a/drivers/net/wireless/ti/wl1251/sdio.c
44658+++ b/drivers/net/wireless/ti/wl1251/sdio.c
44659@@ -271,13 +271,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
44660
44661 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
44662
44663- wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
44664- wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
44665+ pax_open_kernel();
44666+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
44667+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
44668+ pax_close_kernel();
44669
44670 wl1251_info("using dedicated interrupt line");
44671 } else {
44672- wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
44673- wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
44674+ pax_open_kernel();
44675+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
44676+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
44677+ pax_close_kernel();
44678
44679 wl1251_info("using SDIO interrupt");
44680 }
44681diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
44682index 1c627da..69f7d17 100644
44683--- a/drivers/net/wireless/ti/wl12xx/main.c
44684+++ b/drivers/net/wireless/ti/wl12xx/main.c
44685@@ -656,7 +656,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
44686 sizeof(wl->conf.mem));
44687
44688 /* read data preparation is only needed by wl127x */
44689- wl->ops->prepare_read = wl127x_prepare_read;
44690+ pax_open_kernel();
44691+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
44692+ pax_close_kernel();
44693
44694 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
44695 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
44696@@ -681,7 +683,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
44697 sizeof(wl->conf.mem));
44698
44699 /* read data preparation is only needed by wl127x */
44700- wl->ops->prepare_read = wl127x_prepare_read;
44701+ pax_open_kernel();
44702+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
44703+ pax_close_kernel();
44704
44705 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
44706 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
44707diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
44708index 7aa0eb8..5a9ef38 100644
44709--- a/drivers/net/wireless/ti/wl18xx/main.c
44710+++ b/drivers/net/wireless/ti/wl18xx/main.c
44711@@ -1730,8 +1730,10 @@ static int wl18xx_setup(struct wl1271 *wl)
44712 }
44713
44714 if (!checksum_param) {
44715- wl18xx_ops.set_rx_csum = NULL;
44716- wl18xx_ops.init_vif = NULL;
44717+ pax_open_kernel();
44718+ *(void **)&wl18xx_ops.set_rx_csum = NULL;
44719+ *(void **)&wl18xx_ops.init_vif = NULL;
44720+ pax_close_kernel();
44721 }
44722
44723 /* Enable 11a Band only if we have 5G antennas */
44724diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c
44725index 7ef0b4a..ff65c28 100644
44726--- a/drivers/net/wireless/zd1211rw/zd_usb.c
44727+++ b/drivers/net/wireless/zd1211rw/zd_usb.c
44728@@ -386,7 +386,7 @@ static inline void handle_regs_int(struct urb *urb)
44729 {
44730 struct zd_usb *usb = urb->context;
44731 struct zd_usb_interrupt *intr = &usb->intr;
44732- int len;
44733+ unsigned int len;
44734 u16 int_num;
44735
44736 ZD_ASSERT(in_interrupt());
44737diff --git a/drivers/nfc/nfcwilink.c b/drivers/nfc/nfcwilink.c
44738index 59f95d8..53e0e7f 100644
44739--- a/drivers/nfc/nfcwilink.c
44740+++ b/drivers/nfc/nfcwilink.c
44741@@ -513,7 +513,7 @@ static struct nci_ops nfcwilink_ops = {
44742
44743 static int nfcwilink_probe(struct platform_device *pdev)
44744 {
44745- static struct nfcwilink *drv;
44746+ struct nfcwilink *drv;
44747 int rc;
44748 __u32 protocols;
44749
44750diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
44751index d93b2b6..ae50401 100644
44752--- a/drivers/oprofile/buffer_sync.c
44753+++ b/drivers/oprofile/buffer_sync.c
44754@@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
44755 if (cookie == NO_COOKIE)
44756 offset = pc;
44757 if (cookie == INVALID_COOKIE) {
44758- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
44759+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
44760 offset = pc;
44761 }
44762 if (cookie != last_cookie) {
44763@@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
44764 /* add userspace sample */
44765
44766 if (!mm) {
44767- atomic_inc(&oprofile_stats.sample_lost_no_mm);
44768+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
44769 return 0;
44770 }
44771
44772 cookie = lookup_dcookie(mm, s->eip, &offset);
44773
44774 if (cookie == INVALID_COOKIE) {
44775- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
44776+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
44777 return 0;
44778 }
44779
44780@@ -552,7 +552,7 @@ void sync_buffer(int cpu)
44781 /* ignore backtraces if failed to add a sample */
44782 if (state == sb_bt_start) {
44783 state = sb_bt_ignore;
44784- atomic_inc(&oprofile_stats.bt_lost_no_mapping);
44785+ atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
44786 }
44787 }
44788 release_mm(mm);
44789diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
44790index c0cc4e7..44d4e54 100644
44791--- a/drivers/oprofile/event_buffer.c
44792+++ b/drivers/oprofile/event_buffer.c
44793@@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
44794 }
44795
44796 if (buffer_pos == buffer_size) {
44797- atomic_inc(&oprofile_stats.event_lost_overflow);
44798+ atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
44799 return;
44800 }
44801
44802diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
44803index ed2c3ec..deda85a 100644
44804--- a/drivers/oprofile/oprof.c
44805+++ b/drivers/oprofile/oprof.c
44806@@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
44807 if (oprofile_ops.switch_events())
44808 return;
44809
44810- atomic_inc(&oprofile_stats.multiplex_counter);
44811+ atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
44812 start_switch_worker();
44813 }
44814
44815diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
44816index ee2cfce..7f8f699 100644
44817--- a/drivers/oprofile/oprofile_files.c
44818+++ b/drivers/oprofile/oprofile_files.c
44819@@ -27,7 +27,7 @@ unsigned long oprofile_time_slice;
44820
44821 #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
44822
44823-static ssize_t timeout_read(struct file *file, char __user *buf,
44824+static ssize_t __intentional_overflow(-1) timeout_read(struct file *file, char __user *buf,
44825 size_t count, loff_t *offset)
44826 {
44827 return oprofilefs_ulong_to_user(jiffies_to_msecs(oprofile_time_slice),
44828diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
44829index 59659ce..6c860a0 100644
44830--- a/drivers/oprofile/oprofile_stats.c
44831+++ b/drivers/oprofile/oprofile_stats.c
44832@@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
44833 cpu_buf->sample_invalid_eip = 0;
44834 }
44835
44836- atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
44837- atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
44838- atomic_set(&oprofile_stats.event_lost_overflow, 0);
44839- atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
44840- atomic_set(&oprofile_stats.multiplex_counter, 0);
44841+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
44842+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
44843+ atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
44844+ atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
44845+ atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
44846 }
44847
44848
44849diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
44850index 1fc622b..8c48fc3 100644
44851--- a/drivers/oprofile/oprofile_stats.h
44852+++ b/drivers/oprofile/oprofile_stats.h
44853@@ -13,11 +13,11 @@
44854 #include <linux/atomic.h>
44855
44856 struct oprofile_stat_struct {
44857- atomic_t sample_lost_no_mm;
44858- atomic_t sample_lost_no_mapping;
44859- atomic_t bt_lost_no_mapping;
44860- atomic_t event_lost_overflow;
44861- atomic_t multiplex_counter;
44862+ atomic_unchecked_t sample_lost_no_mm;
44863+ atomic_unchecked_t sample_lost_no_mapping;
44864+ atomic_unchecked_t bt_lost_no_mapping;
44865+ atomic_unchecked_t event_lost_overflow;
44866+ atomic_unchecked_t multiplex_counter;
44867 };
44868
44869 extern struct oprofile_stat_struct oprofile_stats;
44870diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
44871index 3f49345..c750d0b 100644
44872--- a/drivers/oprofile/oprofilefs.c
44873+++ b/drivers/oprofile/oprofilefs.c
44874@@ -176,8 +176,8 @@ int oprofilefs_create_ro_ulong(struct dentry *root,
44875
44876 static ssize_t atomic_read_file(struct file *file, char __user *buf, size_t count, loff_t *offset)
44877 {
44878- atomic_t *val = file->private_data;
44879- return oprofilefs_ulong_to_user(atomic_read(val), buf, count, offset);
44880+ atomic_unchecked_t *val = file->private_data;
44881+ return oprofilefs_ulong_to_user(atomic_read_unchecked(val), buf, count, offset);
44882 }
44883
44884
44885@@ -189,7 +189,7 @@ static const struct file_operations atomic_ro_fops = {
44886
44887
44888 int oprofilefs_create_ro_atomic(struct dentry *root,
44889- char const *name, atomic_t *val)
44890+ char const *name, atomic_unchecked_t *val)
44891 {
44892 return __oprofilefs_create_file(root, name,
44893 &atomic_ro_fops, 0444, val);
44894diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
44895index 61be1d9..dec05d7 100644
44896--- a/drivers/oprofile/timer_int.c
44897+++ b/drivers/oprofile/timer_int.c
44898@@ -93,7 +93,7 @@ static int oprofile_cpu_notify(struct notifier_block *self,
44899 return NOTIFY_OK;
44900 }
44901
44902-static struct notifier_block __refdata oprofile_cpu_notifier = {
44903+static struct notifier_block oprofile_cpu_notifier = {
44904 .notifier_call = oprofile_cpu_notify,
44905 };
44906
44907diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
44908index 92ed045..62d39bd7 100644
44909--- a/drivers/parport/procfs.c
44910+++ b/drivers/parport/procfs.c
44911@@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
44912
44913 *ppos += len;
44914
44915- return copy_to_user(result, buffer, len) ? -EFAULT : 0;
44916+ return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
44917 }
44918
44919 #ifdef CONFIG_PARPORT_1284
44920@@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
44921
44922 *ppos += len;
44923
44924- return copy_to_user (result, buffer, len) ? -EFAULT : 0;
44925+ return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
44926 }
44927 #endif /* IEEE1284.3 support. */
44928
44929diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
44930index 2f5786c..61ab4d1 100644
44931--- a/drivers/pci/hotplug/acpiphp_ibm.c
44932+++ b/drivers/pci/hotplug/acpiphp_ibm.c
44933@@ -463,7 +463,9 @@ static int __init ibm_acpiphp_init(void)
44934 goto init_cleanup;
44935 }
44936
44937- ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
44938+ pax_open_kernel();
44939+ *(size_t *)&ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
44940+ pax_close_kernel();
44941 retval = sysfs_create_bin_file(sysdir, &ibm_apci_table_attr);
44942
44943 return retval;
44944diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
44945index a6a71c4..c91097b 100644
44946--- a/drivers/pci/hotplug/cpcihp_generic.c
44947+++ b/drivers/pci/hotplug/cpcihp_generic.c
44948@@ -73,7 +73,6 @@ static u16 port;
44949 static unsigned int enum_bit;
44950 static u8 enum_mask;
44951
44952-static struct cpci_hp_controller_ops generic_hpc_ops;
44953 static struct cpci_hp_controller generic_hpc;
44954
44955 static int __init validate_parameters(void)
44956@@ -139,6 +138,10 @@ static int query_enum(void)
44957 return ((value & enum_mask) == enum_mask);
44958 }
44959
44960+static struct cpci_hp_controller_ops generic_hpc_ops = {
44961+ .query_enum = query_enum,
44962+};
44963+
44964 static int __init cpcihp_generic_init(void)
44965 {
44966 int status;
44967@@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
44968 pci_dev_put(dev);
44969
44970 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
44971- generic_hpc_ops.query_enum = query_enum;
44972 generic_hpc.ops = &generic_hpc_ops;
44973
44974 status = cpci_hp_register_controller(&generic_hpc);
44975diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
44976index 449b4bb..257e2e8 100644
44977--- a/drivers/pci/hotplug/cpcihp_zt5550.c
44978+++ b/drivers/pci/hotplug/cpcihp_zt5550.c
44979@@ -59,7 +59,6 @@
44980 /* local variables */
44981 static bool debug;
44982 static bool poll;
44983-static struct cpci_hp_controller_ops zt5550_hpc_ops;
44984 static struct cpci_hp_controller zt5550_hpc;
44985
44986 /* Primary cPCI bus bridge device */
44987@@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
44988 return 0;
44989 }
44990
44991+static struct cpci_hp_controller_ops zt5550_hpc_ops = {
44992+ .query_enum = zt5550_hc_query_enum,
44993+};
44994+
44995 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
44996 {
44997 int status;
44998@@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
44999 dbg("returned from zt5550_hc_config");
45000
45001 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
45002- zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
45003 zt5550_hpc.ops = &zt5550_hpc_ops;
45004 if(!poll) {
45005 zt5550_hpc.irq = hc_dev->irq;
45006 zt5550_hpc.irq_flags = IRQF_SHARED;
45007 zt5550_hpc.dev_id = hc_dev;
45008
45009- zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
45010- zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
45011- zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
45012+ pax_open_kernel();
45013+ *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
45014+ *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
45015+ *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
45016+ pax_open_kernel();
45017 } else {
45018 info("using ENUM# polling mode");
45019 }
45020diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
45021index 76ba8a1..20ca857 100644
45022--- a/drivers/pci/hotplug/cpqphp_nvram.c
45023+++ b/drivers/pci/hotplug/cpqphp_nvram.c
45024@@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
45025
45026 void compaq_nvram_init (void __iomem *rom_start)
45027 {
45028+
45029+#ifndef CONFIG_PAX_KERNEXEC
45030 if (rom_start) {
45031 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
45032 }
45033+#endif
45034+
45035 dbg("int15 entry = %p\n", compaq_int15_entry_point);
45036
45037 /* initialize our int15 lock */
45038diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
45039index ec20f74..c1d961e 100644
45040--- a/drivers/pci/hotplug/pci_hotplug_core.c
45041+++ b/drivers/pci/hotplug/pci_hotplug_core.c
45042@@ -441,8 +441,10 @@ int __pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus,
45043 return -EINVAL;
45044 }
45045
45046- slot->ops->owner = owner;
45047- slot->ops->mod_name = mod_name;
45048+ pax_open_kernel();
45049+ *(struct module **)&slot->ops->owner = owner;
45050+ *(const char **)&slot->ops->mod_name = mod_name;
45051+ pax_close_kernel();
45052
45053 mutex_lock(&pci_hp_mutex);
45054 /*
45055diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
45056index f4a18f5..ff2463c 100644
45057--- a/drivers/pci/hotplug/pciehp_core.c
45058+++ b/drivers/pci/hotplug/pciehp_core.c
45059@@ -92,7 +92,7 @@ static int init_slot(struct controller *ctrl)
45060 struct slot *slot = ctrl->slot;
45061 struct hotplug_slot *hotplug = NULL;
45062 struct hotplug_slot_info *info = NULL;
45063- struct hotplug_slot_ops *ops = NULL;
45064+ hotplug_slot_ops_no_const *ops = NULL;
45065 char name[SLOT_NAME_SIZE];
45066 int retval = -ENOMEM;
45067
45068diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
45069index 7128cfd..a0640d6 100644
45070--- a/drivers/pci/pci-sysfs.c
45071+++ b/drivers/pci/pci-sysfs.c
45072@@ -1083,7 +1083,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
45073 {
45074 /* allocate attribute structure, piggyback attribute name */
45075 int name_len = write_combine ? 13 : 10;
45076- struct bin_attribute *res_attr;
45077+ bin_attribute_no_const *res_attr;
45078 int retval;
45079
45080 res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);
45081@@ -1268,7 +1268,7 @@ static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_stor
45082 static int pci_create_capabilities_sysfs(struct pci_dev *dev)
45083 {
45084 int retval;
45085- struct bin_attribute *attr;
45086+ bin_attribute_no_const *attr;
45087
45088 /* If the device has VPD, try to expose it in sysfs. */
45089 if (dev->vpd) {
45090@@ -1315,7 +1315,7 @@ int __must_check pci_create_sysfs_dev_files (struct pci_dev *pdev)
45091 {
45092 int retval;
45093 int rom_size = 0;
45094- struct bin_attribute *attr;
45095+ bin_attribute_no_const *attr;
45096
45097 if (!sysfs_initialized)
45098 return -EACCES;
45099diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
45100index 8a00c06..18a9715 100644
45101--- a/drivers/pci/pci.h
45102+++ b/drivers/pci/pci.h
45103@@ -95,7 +95,7 @@ struct pci_vpd_ops {
45104 struct pci_vpd {
45105 unsigned int len;
45106 const struct pci_vpd_ops *ops;
45107- struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
45108+ bin_attribute_no_const *attr; /* descriptor for sysfs VPD entry */
45109 };
45110
45111 int pci_vpd_pci22_init(struct pci_dev *dev);
45112diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
45113index 403a443..034e050 100644
45114--- a/drivers/pci/pcie/aspm.c
45115+++ b/drivers/pci/pcie/aspm.c
45116@@ -27,9 +27,9 @@
45117 #define MODULE_PARAM_PREFIX "pcie_aspm."
45118
45119 /* Note: those are not register definitions */
45120-#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
45121-#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
45122-#define ASPM_STATE_L1 (4) /* L1 state */
45123+#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
45124+#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
45125+#define ASPM_STATE_L1 (4U) /* L1 state */
45126 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
45127 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
45128
45129diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
45130index 7ef0f86..17b710f 100644
45131--- a/drivers/pci/probe.c
45132+++ b/drivers/pci/probe.c
45133@@ -175,7 +175,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
45134 struct pci_bus_region region, inverted_region;
45135 bool bar_too_big = false, bar_disabled = false;
45136
45137- mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
45138+ mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
45139
45140 /* No printks while decoding is disabled! */
45141 if (!dev->mmio_always_on) {
45142diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
45143index cdc7836..528635c 100644
45144--- a/drivers/pci/proc.c
45145+++ b/drivers/pci/proc.c
45146@@ -434,7 +434,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
45147 static int __init pci_proc_init(void)
45148 {
45149 struct pci_dev *dev = NULL;
45150+
45151+#ifdef CONFIG_GRKERNSEC_PROC_ADD
45152+#ifdef CONFIG_GRKERNSEC_PROC_USER
45153+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
45154+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
45155+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
45156+#endif
45157+#else
45158 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
45159+#endif
45160 proc_create("devices", 0, proc_bus_pci_dir,
45161 &proc_bus_pci_dev_operations);
45162 proc_initialized = 1;
45163diff --git a/drivers/platform/x86/chromeos_laptop.c b/drivers/platform/x86/chromeos_laptop.c
45164index 3e5b4497..dcdfb70 100644
45165--- a/drivers/platform/x86/chromeos_laptop.c
45166+++ b/drivers/platform/x86/chromeos_laptop.c
45167@@ -301,7 +301,7 @@ static int __init setup_tsl2563_als(const struct dmi_system_id *id)
45168 return 0;
45169 }
45170
45171-static struct dmi_system_id __initdata chromeos_laptop_dmi_table[] = {
45172+static struct dmi_system_id __initconst chromeos_laptop_dmi_table[] = {
45173 {
45174 .ident = "Samsung Series 5 550 - Touchpad",
45175 .matches = {
45176diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
45177index 62f8030..c7f2a45 100644
45178--- a/drivers/platform/x86/msi-laptop.c
45179+++ b/drivers/platform/x86/msi-laptop.c
45180@@ -1000,12 +1000,14 @@ static int __init load_scm_model_init(struct platform_device *sdev)
45181
45182 if (!quirks->ec_read_only) {
45183 /* allow userland write sysfs file */
45184- dev_attr_bluetooth.store = store_bluetooth;
45185- dev_attr_wlan.store = store_wlan;
45186- dev_attr_threeg.store = store_threeg;
45187- dev_attr_bluetooth.attr.mode |= S_IWUSR;
45188- dev_attr_wlan.attr.mode |= S_IWUSR;
45189- dev_attr_threeg.attr.mode |= S_IWUSR;
45190+ pax_open_kernel();
45191+ *(void **)&dev_attr_bluetooth.store = store_bluetooth;
45192+ *(void **)&dev_attr_wlan.store = store_wlan;
45193+ *(void **)&dev_attr_threeg.store = store_threeg;
45194+ *(umode_t *)&dev_attr_bluetooth.attr.mode |= S_IWUSR;
45195+ *(umode_t *)&dev_attr_wlan.attr.mode |= S_IWUSR;
45196+ *(umode_t *)&dev_attr_threeg.attr.mode |= S_IWUSR;
45197+ pax_close_kernel();
45198 }
45199
45200 /* disable hardware control by fn key */
45201diff --git a/drivers/platform/x86/msi-wmi.c b/drivers/platform/x86/msi-wmi.c
45202index 70222f2..8c8ce66 100644
45203--- a/drivers/platform/x86/msi-wmi.c
45204+++ b/drivers/platform/x86/msi-wmi.c
45205@@ -183,7 +183,7 @@ static const struct backlight_ops msi_backlight_ops = {
45206 static void msi_wmi_notify(u32 value, void *context)
45207 {
45208 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
45209- static struct key_entry *key;
45210+ struct key_entry *key;
45211 union acpi_object *obj;
45212 acpi_status status;
45213
45214diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
45215index 13ec195..6af61af 100644
45216--- a/drivers/platform/x86/sony-laptop.c
45217+++ b/drivers/platform/x86/sony-laptop.c
45218@@ -2475,7 +2475,7 @@ static void sony_nc_gfx_switch_cleanup(struct platform_device *pd)
45219 }
45220
45221 /* High speed charging function */
45222-static struct device_attribute *hsc_handle;
45223+static device_attribute_no_const *hsc_handle;
45224
45225 static ssize_t sony_nc_highspeed_charging_store(struct device *dev,
45226 struct device_attribute *attr,
45227diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
45228index 03ca6c1..1ef2ddd 100644
45229--- a/drivers/platform/x86/thinkpad_acpi.c
45230+++ b/drivers/platform/x86/thinkpad_acpi.c
45231@@ -2091,7 +2091,7 @@ static int hotkey_mask_get(void)
45232 return 0;
45233 }
45234
45235-void static hotkey_mask_warn_incomplete_mask(void)
45236+static void hotkey_mask_warn_incomplete_mask(void)
45237 {
45238 /* log only what the user can fix... */
45239 const u32 wantedmask = hotkey_driver_mask &
45240@@ -2318,11 +2318,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
45241 }
45242 }
45243
45244-static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
45245- struct tp_nvram_state *newn,
45246- const u32 event_mask)
45247-{
45248-
45249 #define TPACPI_COMPARE_KEY(__scancode, __member) \
45250 do { \
45251 if ((event_mask & (1 << __scancode)) && \
45252@@ -2336,36 +2331,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
45253 tpacpi_hotkey_send_key(__scancode); \
45254 } while (0)
45255
45256- void issue_volchange(const unsigned int oldvol,
45257- const unsigned int newvol)
45258- {
45259- unsigned int i = oldvol;
45260+static void issue_volchange(const unsigned int oldvol,
45261+ const unsigned int newvol,
45262+ const u32 event_mask)
45263+{
45264+ unsigned int i = oldvol;
45265
45266- while (i > newvol) {
45267- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
45268- i--;
45269- }
45270- while (i < newvol) {
45271- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
45272- i++;
45273- }
45274+ while (i > newvol) {
45275+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
45276+ i--;
45277 }
45278+ while (i < newvol) {
45279+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
45280+ i++;
45281+ }
45282+}
45283
45284- void issue_brightnesschange(const unsigned int oldbrt,
45285- const unsigned int newbrt)
45286- {
45287- unsigned int i = oldbrt;
45288+static void issue_brightnesschange(const unsigned int oldbrt,
45289+ const unsigned int newbrt,
45290+ const u32 event_mask)
45291+{
45292+ unsigned int i = oldbrt;
45293
45294- while (i > newbrt) {
45295- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
45296- i--;
45297- }
45298- while (i < newbrt) {
45299- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
45300- i++;
45301- }
45302+ while (i > newbrt) {
45303+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
45304+ i--;
45305+ }
45306+ while (i < newbrt) {
45307+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
45308+ i++;
45309 }
45310+}
45311
45312+static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
45313+ struct tp_nvram_state *newn,
45314+ const u32 event_mask)
45315+{
45316 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
45317 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
45318 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
45319@@ -2399,7 +2400,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
45320 oldn->volume_level != newn->volume_level) {
45321 /* recently muted, or repeated mute keypress, or
45322 * multiple presses ending in mute */
45323- issue_volchange(oldn->volume_level, newn->volume_level);
45324+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
45325 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
45326 }
45327 } else {
45328@@ -2409,7 +2410,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
45329 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
45330 }
45331 if (oldn->volume_level != newn->volume_level) {
45332- issue_volchange(oldn->volume_level, newn->volume_level);
45333+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
45334 } else if (oldn->volume_toggle != newn->volume_toggle) {
45335 /* repeated vol up/down keypress at end of scale ? */
45336 if (newn->volume_level == 0)
45337@@ -2422,7 +2423,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
45338 /* handle brightness */
45339 if (oldn->brightness_level != newn->brightness_level) {
45340 issue_brightnesschange(oldn->brightness_level,
45341- newn->brightness_level);
45342+ newn->brightness_level,
45343+ event_mask);
45344 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
45345 /* repeated key presses that didn't change state */
45346 if (newn->brightness_level == 0)
45347@@ -2431,10 +2433,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
45348 && !tp_features.bright_unkfw)
45349 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
45350 }
45351+}
45352
45353 #undef TPACPI_COMPARE_KEY
45354 #undef TPACPI_MAY_SEND_KEY
45355-}
45356
45357 /*
45358 * Polling driver
45359diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
45360index 769d265..a3a05ca 100644
45361--- a/drivers/pnp/pnpbios/bioscalls.c
45362+++ b/drivers/pnp/pnpbios/bioscalls.c
45363@@ -58,7 +58,7 @@ do { \
45364 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
45365 } while(0)
45366
45367-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
45368+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
45369 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
45370
45371 /*
45372@@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
45373
45374 cpu = get_cpu();
45375 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
45376+
45377+ pax_open_kernel();
45378 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
45379+ pax_close_kernel();
45380
45381 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
45382 spin_lock_irqsave(&pnp_bios_lock, flags);
45383@@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
45384 :"memory");
45385 spin_unlock_irqrestore(&pnp_bios_lock, flags);
45386
45387+ pax_open_kernel();
45388 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
45389+ pax_close_kernel();
45390+
45391 put_cpu();
45392
45393 /* If we get here and this is set then the PnP BIOS faulted on us. */
45394@@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
45395 return status;
45396 }
45397
45398-void pnpbios_calls_init(union pnp_bios_install_struct *header)
45399+void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
45400 {
45401 int i;
45402
45403@@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
45404 pnp_bios_callpoint.offset = header->fields.pm16offset;
45405 pnp_bios_callpoint.segment = PNP_CS16;
45406
45407+ pax_open_kernel();
45408+
45409 for_each_possible_cpu(i) {
45410 struct desc_struct *gdt = get_cpu_gdt_table(i);
45411 if (!gdt)
45412@@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
45413 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
45414 (unsigned long)__va(header->fields.pm16dseg));
45415 }
45416+
45417+ pax_close_kernel();
45418 }
45419diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
45420index d95e101..67f0c3f 100644
45421--- a/drivers/pnp/resource.c
45422+++ b/drivers/pnp/resource.c
45423@@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
45424 return 1;
45425
45426 /* check if the resource is valid */
45427- if (*irq < 0 || *irq > 15)
45428+ if (*irq > 15)
45429 return 0;
45430
45431 /* check if the resource is reserved */
45432@@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
45433 return 1;
45434
45435 /* check if the resource is valid */
45436- if (*dma < 0 || *dma == 4 || *dma > 7)
45437+ if (*dma == 4 || *dma > 7)
45438 return 0;
45439
45440 /* check if the resource is reserved */
45441diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
45442index 0c52e2a..3421ab7 100644
45443--- a/drivers/power/pda_power.c
45444+++ b/drivers/power/pda_power.c
45445@@ -37,7 +37,11 @@ static int polling;
45446
45447 #if IS_ENABLED(CONFIG_USB_PHY)
45448 static struct usb_phy *transceiver;
45449-static struct notifier_block otg_nb;
45450+static int otg_handle_notification(struct notifier_block *nb,
45451+ unsigned long event, void *unused);
45452+static struct notifier_block otg_nb = {
45453+ .notifier_call = otg_handle_notification
45454+};
45455 #endif
45456
45457 static struct regulator *ac_draw;
45458@@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
45459
45460 #if IS_ENABLED(CONFIG_USB_PHY)
45461 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
45462- otg_nb.notifier_call = otg_handle_notification;
45463 ret = usb_register_notifier(transceiver, &otg_nb);
45464 if (ret) {
45465 dev_err(dev, "failure to register otg notifier\n");
45466diff --git a/drivers/power/power_supply.h b/drivers/power/power_supply.h
45467index cc439fd..8fa30df 100644
45468--- a/drivers/power/power_supply.h
45469+++ b/drivers/power/power_supply.h
45470@@ -16,12 +16,12 @@ struct power_supply;
45471
45472 #ifdef CONFIG_SYSFS
45473
45474-extern void power_supply_init_attrs(struct device_type *dev_type);
45475+extern void power_supply_init_attrs(void);
45476 extern int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env);
45477
45478 #else
45479
45480-static inline void power_supply_init_attrs(struct device_type *dev_type) {}
45481+static inline void power_supply_init_attrs(void) {}
45482 #define power_supply_uevent NULL
45483
45484 #endif /* CONFIG_SYSFS */
45485diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
45486index 00e6672..2642c08 100644
45487--- a/drivers/power/power_supply_core.c
45488+++ b/drivers/power/power_supply_core.c
45489@@ -24,7 +24,10 @@
45490 struct class *power_supply_class;
45491 EXPORT_SYMBOL_GPL(power_supply_class);
45492
45493-static struct device_type power_supply_dev_type;
45494+extern const struct attribute_group *power_supply_attr_groups[];
45495+static struct device_type power_supply_dev_type = {
45496+ .groups = power_supply_attr_groups,
45497+};
45498
45499 static bool __power_supply_is_supplied_by(struct power_supply *supplier,
45500 struct power_supply *supply)
45501@@ -584,7 +587,7 @@ static int __init power_supply_class_init(void)
45502 return PTR_ERR(power_supply_class);
45503
45504 power_supply_class->dev_uevent = power_supply_uevent;
45505- power_supply_init_attrs(&power_supply_dev_type);
45506+ power_supply_init_attrs();
45507
45508 return 0;
45509 }
45510diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
45511index 44420d1..967126e 100644
45512--- a/drivers/power/power_supply_sysfs.c
45513+++ b/drivers/power/power_supply_sysfs.c
45514@@ -230,17 +230,15 @@ static struct attribute_group power_supply_attr_group = {
45515 .is_visible = power_supply_attr_is_visible,
45516 };
45517
45518-static const struct attribute_group *power_supply_attr_groups[] = {
45519+const struct attribute_group *power_supply_attr_groups[] = {
45520 &power_supply_attr_group,
45521 NULL,
45522 };
45523
45524-void power_supply_init_attrs(struct device_type *dev_type)
45525+void power_supply_init_attrs(void)
45526 {
45527 int i;
45528
45529- dev_type->groups = power_supply_attr_groups;
45530-
45531 for (i = 0; i < ARRAY_SIZE(power_supply_attrs); i++)
45532 __power_supply_attrs[i] = &power_supply_attrs[i].attr;
45533 }
45534diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
45535index a01b8b3..37c2afe 100644
45536--- a/drivers/regulator/core.c
45537+++ b/drivers/regulator/core.c
45538@@ -3307,7 +3307,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
45539 {
45540 const struct regulation_constraints *constraints = NULL;
45541 const struct regulator_init_data *init_data;
45542- static atomic_t regulator_no = ATOMIC_INIT(0);
45543+ static atomic_unchecked_t regulator_no = ATOMIC_INIT(0);
45544 struct regulator_dev *rdev;
45545 struct device *dev;
45546 int ret, i;
45547@@ -3377,7 +3377,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
45548 rdev->dev.of_node = config->of_node;
45549 rdev->dev.parent = dev;
45550 dev_set_name(&rdev->dev, "regulator.%d",
45551- atomic_inc_return(&regulator_no) - 1);
45552+ atomic_inc_return_unchecked(&regulator_no) - 1);
45553 ret = device_register(&rdev->dev);
45554 if (ret != 0) {
45555 put_device(&rdev->dev);
45556diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
45557index 144bcac..d20e7db 100644
45558--- a/drivers/regulator/max8660.c
45559+++ b/drivers/regulator/max8660.c
45560@@ -420,8 +420,10 @@ static int max8660_probe(struct i2c_client *client,
45561 max8660->shadow_regs[MAX8660_OVER1] = 5;
45562 } else {
45563 /* Otherwise devices can be toggled via software */
45564- max8660_dcdc_ops.enable = max8660_dcdc_enable;
45565- max8660_dcdc_ops.disable = max8660_dcdc_disable;
45566+ pax_open_kernel();
45567+ *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
45568+ *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
45569+ pax_close_kernel();
45570 }
45571
45572 /*
45573diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
45574index 5b77ab7..a62f061 100644
45575--- a/drivers/regulator/max8973-regulator.c
45576+++ b/drivers/regulator/max8973-regulator.c
45577@@ -406,9 +406,11 @@ static int max8973_probe(struct i2c_client *client,
45578 if (!pdata || !pdata->enable_ext_control) {
45579 max->desc.enable_reg = MAX8973_VOUT;
45580 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
45581- max->ops.enable = regulator_enable_regmap;
45582- max->ops.disable = regulator_disable_regmap;
45583- max->ops.is_enabled = regulator_is_enabled_regmap;
45584+ pax_open_kernel();
45585+ *(void **)&max->ops.enable = regulator_enable_regmap;
45586+ *(void **)&max->ops.disable = regulator_disable_regmap;
45587+ *(void **)&max->ops.is_enabled = regulator_is_enabled_regmap;
45588+ pax_close_kernel();
45589 }
45590
45591 if (pdata) {
45592diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
45593index 1037e07..e64dea1 100644
45594--- a/drivers/regulator/mc13892-regulator.c
45595+++ b/drivers/regulator/mc13892-regulator.c
45596@@ -582,10 +582,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
45597 }
45598 mc13xxx_unlock(mc13892);
45599
45600- mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
45601+ pax_open_kernel();
45602+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
45603 = mc13892_vcam_set_mode;
45604- mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
45605+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
45606 = mc13892_vcam_get_mode;
45607+ pax_close_kernel();
45608
45609 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
45610 ARRAY_SIZE(mc13892_regulators));
45611diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
45612index 24e733c..bfbaa3e 100644
45613--- a/drivers/rtc/rtc-cmos.c
45614+++ b/drivers/rtc/rtc-cmos.c
45615@@ -731,7 +731,9 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
45616 hpet_rtc_timer_init();
45617
45618 /* export at least the first block of NVRAM */
45619- nvram.size = address_space - NVRAM_OFFSET;
45620+ pax_open_kernel();
45621+ *(size_t *)&nvram.size = address_space - NVRAM_OFFSET;
45622+ pax_close_kernel();
45623 retval = sysfs_create_bin_file(&dev->kobj, &nvram);
45624 if (retval < 0) {
45625 dev_dbg(dev, "can't create nvram file? %d\n", retval);
45626diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
45627index d049393..bb20be0 100644
45628--- a/drivers/rtc/rtc-dev.c
45629+++ b/drivers/rtc/rtc-dev.c
45630@@ -16,6 +16,7 @@
45631 #include <linux/module.h>
45632 #include <linux/rtc.h>
45633 #include <linux/sched.h>
45634+#include <linux/grsecurity.h>
45635 #include "rtc-core.h"
45636
45637 static dev_t rtc_devt;
45638@@ -347,6 +348,8 @@ static long rtc_dev_ioctl(struct file *file,
45639 if (copy_from_user(&tm, uarg, sizeof(tm)))
45640 return -EFAULT;
45641
45642+ gr_log_timechange();
45643+
45644 return rtc_set_time(rtc, &tm);
45645
45646 case RTC_PIE_ON:
45647diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
45648index ca18fd1..055e42d 100644
45649--- a/drivers/rtc/rtc-ds1307.c
45650+++ b/drivers/rtc/rtc-ds1307.c
45651@@ -107,7 +107,7 @@ struct ds1307 {
45652 u8 offset; /* register's offset */
45653 u8 regs[11];
45654 u16 nvram_offset;
45655- struct bin_attribute *nvram;
45656+ bin_attribute_no_const *nvram;
45657 enum ds_type type;
45658 unsigned long flags;
45659 #define HAS_NVRAM 0 /* bit 0 == sysfs file active */
45660diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
45661index fcb0329..d77b7f2 100644
45662--- a/drivers/rtc/rtc-m48t59.c
45663+++ b/drivers/rtc/rtc-m48t59.c
45664@@ -483,7 +483,9 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
45665 if (IS_ERR(m48t59->rtc))
45666 return PTR_ERR(m48t59->rtc);
45667
45668- m48t59_nvram_attr.size = pdata->offset;
45669+ pax_open_kernel();
45670+ *(size_t *)&m48t59_nvram_attr.size = pdata->offset;
45671+ pax_close_kernel();
45672
45673 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
45674 if (ret)
45675diff --git a/drivers/scsi/aic7xxx/aic79xx_pci.c b/drivers/scsi/aic7xxx/aic79xx_pci.c
45676index 14b5f8d..cc9bd26 100644
45677--- a/drivers/scsi/aic7xxx/aic79xx_pci.c
45678+++ b/drivers/scsi/aic7xxx/aic79xx_pci.c
45679@@ -827,7 +827,7 @@ ahd_pci_intr(struct ahd_softc *ahd)
45680 for (bit = 0; bit < 8; bit++) {
45681
45682 if ((pci_status[i] & (0x1 << bit)) != 0) {
45683- static const char *s;
45684+ const char *s;
45685
45686 s = pci_status_strings[bit];
45687 if (i == 7/*TARG*/ && bit == 3)
45688@@ -887,23 +887,15 @@ ahd_pci_split_intr(struct ahd_softc *ahd, u_int intstat)
45689
45690 for (bit = 0; bit < 8; bit++) {
45691
45692- if ((split_status[i] & (0x1 << bit)) != 0) {
45693- static const char *s;
45694-
45695- s = split_status_strings[bit];
45696- printk(s, ahd_name(ahd),
45697+ if ((split_status[i] & (0x1 << bit)) != 0)
45698+ printk(split_status_strings[bit], ahd_name(ahd),
45699 split_status_source[i]);
45700- }
45701
45702 if (i > 1)
45703 continue;
45704
45705- if ((sg_split_status[i] & (0x1 << bit)) != 0) {
45706- static const char *s;
45707-
45708- s = split_status_strings[bit];
45709- printk(s, ahd_name(ahd), "SG");
45710- }
45711+ if ((sg_split_status[i] & (0x1 << bit)) != 0)
45712+ printk(split_status_strings[bit], ahd_name(ahd), "SG");
45713 }
45714 }
45715 /*
45716diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
45717index e693af6..2e525b6 100644
45718--- a/drivers/scsi/bfa/bfa_fcpim.h
45719+++ b/drivers/scsi/bfa/bfa_fcpim.h
45720@@ -36,7 +36,7 @@ struct bfa_iotag_s {
45721
45722 struct bfa_itn_s {
45723 bfa_isr_func_t isr;
45724-};
45725+} __no_const;
45726
45727 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
45728 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
45729diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
45730index 90814fe..4384138 100644
45731--- a/drivers/scsi/bfa/bfa_ioc.h
45732+++ b/drivers/scsi/bfa/bfa_ioc.h
45733@@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
45734 bfa_ioc_disable_cbfn_t disable_cbfn;
45735 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
45736 bfa_ioc_reset_cbfn_t reset_cbfn;
45737-};
45738+} __no_const;
45739
45740 /*
45741 * IOC event notification mechanism.
45742@@ -352,7 +352,7 @@ struct bfa_ioc_hwif_s {
45743 void (*ioc_set_alt_fwstate) (struct bfa_ioc_s *ioc,
45744 enum bfi_ioc_state fwstate);
45745 enum bfi_ioc_state (*ioc_get_alt_fwstate) (struct bfa_ioc_s *ioc);
45746-};
45747+} __no_const;
45748
45749 /*
45750 * Queue element to wait for room in request queue. FIFO order is
45751diff --git a/drivers/scsi/fcoe/fcoe_sysfs.c b/drivers/scsi/fcoe/fcoe_sysfs.c
45752index c9382d6..6619864 100644
45753--- a/drivers/scsi/fcoe/fcoe_sysfs.c
45754+++ b/drivers/scsi/fcoe/fcoe_sysfs.c
45755@@ -33,8 +33,8 @@
45756 */
45757 #include "libfcoe.h"
45758
45759-static atomic_t ctlr_num;
45760-static atomic_t fcf_num;
45761+static atomic_unchecked_t ctlr_num;
45762+static atomic_unchecked_t fcf_num;
45763
45764 /*
45765 * fcoe_fcf_dev_loss_tmo: the default number of seconds that fcoe sysfs
45766@@ -681,7 +681,7 @@ struct fcoe_ctlr_device *fcoe_ctlr_device_add(struct device *parent,
45767 if (!ctlr)
45768 goto out;
45769
45770- ctlr->id = atomic_inc_return(&ctlr_num) - 1;
45771+ ctlr->id = atomic_inc_return_unchecked(&ctlr_num) - 1;
45772 ctlr->f = f;
45773 ctlr->mode = FIP_CONN_TYPE_FABRIC;
45774 INIT_LIST_HEAD(&ctlr->fcfs);
45775@@ -898,7 +898,7 @@ struct fcoe_fcf_device *fcoe_fcf_device_add(struct fcoe_ctlr_device *ctlr,
45776 fcf->dev.parent = &ctlr->dev;
45777 fcf->dev.bus = &fcoe_bus_type;
45778 fcf->dev.type = &fcoe_fcf_device_type;
45779- fcf->id = atomic_inc_return(&fcf_num) - 1;
45780+ fcf->id = atomic_inc_return_unchecked(&fcf_num) - 1;
45781 fcf->state = FCOE_FCF_STATE_UNKNOWN;
45782
45783 fcf->dev_loss_tmo = ctlr->fcf_dev_loss_tmo;
45784@@ -934,8 +934,8 @@ int __init fcoe_sysfs_setup(void)
45785 {
45786 int error;
45787
45788- atomic_set(&ctlr_num, 0);
45789- atomic_set(&fcf_num, 0);
45790+ atomic_set_unchecked(&ctlr_num, 0);
45791+ atomic_set_unchecked(&fcf_num, 0);
45792
45793 error = bus_register(&fcoe_bus_type);
45794 if (error)
45795diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
45796index df0c3c7..b00e1d0 100644
45797--- a/drivers/scsi/hosts.c
45798+++ b/drivers/scsi/hosts.c
45799@@ -42,7 +42,7 @@
45800 #include "scsi_logging.h"
45801
45802
45803-static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
45804+static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
45805
45806
45807 static void scsi_host_cls_release(struct device *dev)
45808@@ -361,7 +361,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
45809 * subtract one because we increment first then return, but we need to
45810 * know what the next host number was before increment
45811 */
45812- shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
45813+ shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
45814 shost->dma_channel = 0xff;
45815
45816 /* These three are default values which can be overridden */
45817diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
45818index 891c86b..dd1224a0 100644
45819--- a/drivers/scsi/hpsa.c
45820+++ b/drivers/scsi/hpsa.c
45821@@ -578,7 +578,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
45822 unsigned long flags;
45823
45824 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
45825- return h->access.command_completed(h, q);
45826+ return h->access->command_completed(h, q);
45827
45828 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
45829 a = rq->head[rq->current_entry];
45830@@ -3444,7 +3444,7 @@ static void start_io(struct ctlr_info *h)
45831 while (!list_empty(&h->reqQ)) {
45832 c = list_entry(h->reqQ.next, struct CommandList, list);
45833 /* can't do anything if fifo is full */
45834- if ((h->access.fifo_full(h))) {
45835+ if ((h->access->fifo_full(h))) {
45836 dev_warn(&h->pdev->dev, "fifo full\n");
45837 break;
45838 }
45839@@ -3466,7 +3466,7 @@ static void start_io(struct ctlr_info *h)
45840
45841 /* Tell the controller execute command */
45842 spin_unlock_irqrestore(&h->lock, flags);
45843- h->access.submit_command(h, c);
45844+ h->access->submit_command(h, c);
45845 spin_lock_irqsave(&h->lock, flags);
45846 }
45847 spin_unlock_irqrestore(&h->lock, flags);
45848@@ -3474,17 +3474,17 @@ static void start_io(struct ctlr_info *h)
45849
45850 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
45851 {
45852- return h->access.command_completed(h, q);
45853+ return h->access->command_completed(h, q);
45854 }
45855
45856 static inline bool interrupt_pending(struct ctlr_info *h)
45857 {
45858- return h->access.intr_pending(h);
45859+ return h->access->intr_pending(h);
45860 }
45861
45862 static inline long interrupt_not_for_us(struct ctlr_info *h)
45863 {
45864- return (h->access.intr_pending(h) == 0) ||
45865+ return (h->access->intr_pending(h) == 0) ||
45866 (h->interrupts_enabled == 0);
45867 }
45868
45869@@ -4386,7 +4386,7 @@ static int hpsa_pci_init(struct ctlr_info *h)
45870 if (prod_index < 0)
45871 return -ENODEV;
45872 h->product_name = products[prod_index].product_name;
45873- h->access = *(products[prod_index].access);
45874+ h->access = products[prod_index].access;
45875
45876 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
45877 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
45878@@ -4668,7 +4668,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
45879
45880 assert_spin_locked(&lockup_detector_lock);
45881 remove_ctlr_from_lockup_detector_list(h);
45882- h->access.set_intr_mask(h, HPSA_INTR_OFF);
45883+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
45884 spin_lock_irqsave(&h->lock, flags);
45885 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
45886 spin_unlock_irqrestore(&h->lock, flags);
45887@@ -4845,7 +4845,7 @@ reinit_after_soft_reset:
45888 }
45889
45890 /* make sure the board interrupts are off */
45891- h->access.set_intr_mask(h, HPSA_INTR_OFF);
45892+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
45893
45894 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
45895 goto clean2;
45896@@ -4879,7 +4879,7 @@ reinit_after_soft_reset:
45897 * fake ones to scoop up any residual completions.
45898 */
45899 spin_lock_irqsave(&h->lock, flags);
45900- h->access.set_intr_mask(h, HPSA_INTR_OFF);
45901+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
45902 spin_unlock_irqrestore(&h->lock, flags);
45903 free_irqs(h);
45904 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
45905@@ -4898,9 +4898,9 @@ reinit_after_soft_reset:
45906 dev_info(&h->pdev->dev, "Board READY.\n");
45907 dev_info(&h->pdev->dev,
45908 "Waiting for stale completions to drain.\n");
45909- h->access.set_intr_mask(h, HPSA_INTR_ON);
45910+ h->access->set_intr_mask(h, HPSA_INTR_ON);
45911 msleep(10000);
45912- h->access.set_intr_mask(h, HPSA_INTR_OFF);
45913+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
45914
45915 rc = controller_reset_failed(h->cfgtable);
45916 if (rc)
45917@@ -4921,7 +4921,7 @@ reinit_after_soft_reset:
45918 }
45919
45920 /* Turn the interrupts on so we can service requests */
45921- h->access.set_intr_mask(h, HPSA_INTR_ON);
45922+ h->access->set_intr_mask(h, HPSA_INTR_ON);
45923
45924 hpsa_hba_inquiry(h);
45925 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
45926@@ -4976,7 +4976,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
45927 * To write all data in the battery backed cache to disks
45928 */
45929 hpsa_flush_cache(h);
45930- h->access.set_intr_mask(h, HPSA_INTR_OFF);
45931+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
45932 hpsa_free_irqs_and_disable_msix(h);
45933 }
45934
45935@@ -5144,7 +5144,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 use_short_tags)
45936 return;
45937 }
45938 /* Change the access methods to the performant access methods */
45939- h->access = SA5_performant_access;
45940+ h->access = &SA5_performant_access;
45941 h->transMethod = CFGTBL_Trans_Performant;
45942 }
45943
45944diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
45945index bc85e72..ae04a39 100644
45946--- a/drivers/scsi/hpsa.h
45947+++ b/drivers/scsi/hpsa.h
45948@@ -79,7 +79,7 @@ struct ctlr_info {
45949 unsigned int msix_vector;
45950 unsigned int msi_vector;
45951 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
45952- struct access_method access;
45953+ struct access_method *access;
45954
45955 /* queue and queue Info */
45956 struct list_head reqQ;
45957diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
45958index 5879929..32b241d 100644
45959--- a/drivers/scsi/libfc/fc_exch.c
45960+++ b/drivers/scsi/libfc/fc_exch.c
45961@@ -100,12 +100,12 @@ struct fc_exch_mgr {
45962 u16 pool_max_index;
45963
45964 struct {
45965- atomic_t no_free_exch;
45966- atomic_t no_free_exch_xid;
45967- atomic_t xid_not_found;
45968- atomic_t xid_busy;
45969- atomic_t seq_not_found;
45970- atomic_t non_bls_resp;
45971+ atomic_unchecked_t no_free_exch;
45972+ atomic_unchecked_t no_free_exch_xid;
45973+ atomic_unchecked_t xid_not_found;
45974+ atomic_unchecked_t xid_busy;
45975+ atomic_unchecked_t seq_not_found;
45976+ atomic_unchecked_t non_bls_resp;
45977 } stats;
45978 };
45979
45980@@ -736,7 +736,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
45981 /* allocate memory for exchange */
45982 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
45983 if (!ep) {
45984- atomic_inc(&mp->stats.no_free_exch);
45985+ atomic_inc_unchecked(&mp->stats.no_free_exch);
45986 goto out;
45987 }
45988 memset(ep, 0, sizeof(*ep));
45989@@ -797,7 +797,7 @@ out:
45990 return ep;
45991 err:
45992 spin_unlock_bh(&pool->lock);
45993- atomic_inc(&mp->stats.no_free_exch_xid);
45994+ atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
45995 mempool_free(ep, mp->ep_pool);
45996 return NULL;
45997 }
45998@@ -940,7 +940,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
45999 xid = ntohs(fh->fh_ox_id); /* we originated exch */
46000 ep = fc_exch_find(mp, xid);
46001 if (!ep) {
46002- atomic_inc(&mp->stats.xid_not_found);
46003+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46004 reject = FC_RJT_OX_ID;
46005 goto out;
46006 }
46007@@ -970,7 +970,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
46008 ep = fc_exch_find(mp, xid);
46009 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
46010 if (ep) {
46011- atomic_inc(&mp->stats.xid_busy);
46012+ atomic_inc_unchecked(&mp->stats.xid_busy);
46013 reject = FC_RJT_RX_ID;
46014 goto rel;
46015 }
46016@@ -981,7 +981,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
46017 }
46018 xid = ep->xid; /* get our XID */
46019 } else if (!ep) {
46020- atomic_inc(&mp->stats.xid_not_found);
46021+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46022 reject = FC_RJT_RX_ID; /* XID not found */
46023 goto out;
46024 }
46025@@ -998,7 +998,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
46026 } else {
46027 sp = &ep->seq;
46028 if (sp->id != fh->fh_seq_id) {
46029- atomic_inc(&mp->stats.seq_not_found);
46030+ atomic_inc_unchecked(&mp->stats.seq_not_found);
46031 if (f_ctl & FC_FC_END_SEQ) {
46032 /*
46033 * Update sequence_id based on incoming last
46034@@ -1448,22 +1448,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
46035
46036 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
46037 if (!ep) {
46038- atomic_inc(&mp->stats.xid_not_found);
46039+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46040 goto out;
46041 }
46042 if (ep->esb_stat & ESB_ST_COMPLETE) {
46043- atomic_inc(&mp->stats.xid_not_found);
46044+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46045 goto rel;
46046 }
46047 if (ep->rxid == FC_XID_UNKNOWN)
46048 ep->rxid = ntohs(fh->fh_rx_id);
46049 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
46050- atomic_inc(&mp->stats.xid_not_found);
46051+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46052 goto rel;
46053 }
46054 if (ep->did != ntoh24(fh->fh_s_id) &&
46055 ep->did != FC_FID_FLOGI) {
46056- atomic_inc(&mp->stats.xid_not_found);
46057+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46058 goto rel;
46059 }
46060 sof = fr_sof(fp);
46061@@ -1472,7 +1472,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
46062 sp->ssb_stat |= SSB_ST_RESP;
46063 sp->id = fh->fh_seq_id;
46064 } else if (sp->id != fh->fh_seq_id) {
46065- atomic_inc(&mp->stats.seq_not_found);
46066+ atomic_inc_unchecked(&mp->stats.seq_not_found);
46067 goto rel;
46068 }
46069
46070@@ -1536,9 +1536,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
46071 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
46072
46073 if (!sp)
46074- atomic_inc(&mp->stats.xid_not_found);
46075+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46076 else
46077- atomic_inc(&mp->stats.non_bls_resp);
46078+ atomic_inc_unchecked(&mp->stats.non_bls_resp);
46079
46080 fc_frame_free(fp);
46081 }
46082@@ -2185,13 +2185,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
46083
46084 list_for_each_entry(ema, &lport->ema_list, ema_list) {
46085 mp = ema->mp;
46086- st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
46087+ st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
46088 st->fc_no_free_exch_xid +=
46089- atomic_read(&mp->stats.no_free_exch_xid);
46090- st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
46091- st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
46092- st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
46093- st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
46094+ atomic_read_unchecked(&mp->stats.no_free_exch_xid);
46095+ st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
46096+ st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
46097+ st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
46098+ st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
46099 }
46100 }
46101 EXPORT_SYMBOL(fc_exch_update_stats);
46102diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
46103index 161c98e..6d563b3 100644
46104--- a/drivers/scsi/libsas/sas_ata.c
46105+++ b/drivers/scsi/libsas/sas_ata.c
46106@@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
46107 .postreset = ata_std_postreset,
46108 .error_handler = ata_std_error_handler,
46109 .post_internal_cmd = sas_ata_post_internal,
46110- .qc_defer = ata_std_qc_defer,
46111+ .qc_defer = ata_std_qc_defer,
46112 .qc_prep = ata_noop_qc_prep,
46113 .qc_issue = sas_ata_qc_issue,
46114 .qc_fill_rtf = sas_ata_qc_fill_rtf,
46115diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
46116index 4e1b75c..0bbdfa9 100644
46117--- a/drivers/scsi/lpfc/lpfc.h
46118+++ b/drivers/scsi/lpfc/lpfc.h
46119@@ -432,7 +432,7 @@ struct lpfc_vport {
46120 struct dentry *debug_nodelist;
46121 struct dentry *vport_debugfs_root;
46122 struct lpfc_debugfs_trc *disc_trc;
46123- atomic_t disc_trc_cnt;
46124+ atomic_unchecked_t disc_trc_cnt;
46125 #endif
46126 uint8_t stat_data_enabled;
46127 uint8_t stat_data_blocked;
46128@@ -865,8 +865,8 @@ struct lpfc_hba {
46129 struct timer_list fabric_block_timer;
46130 unsigned long bit_flags;
46131 #define FABRIC_COMANDS_BLOCKED 0
46132- atomic_t num_rsrc_err;
46133- atomic_t num_cmd_success;
46134+ atomic_unchecked_t num_rsrc_err;
46135+ atomic_unchecked_t num_cmd_success;
46136 unsigned long last_rsrc_error_time;
46137 unsigned long last_ramp_down_time;
46138 unsigned long last_ramp_up_time;
46139@@ -902,7 +902,7 @@ struct lpfc_hba {
46140
46141 struct dentry *debug_slow_ring_trc;
46142 struct lpfc_debugfs_trc *slow_ring_trc;
46143- atomic_t slow_ring_trc_cnt;
46144+ atomic_unchecked_t slow_ring_trc_cnt;
46145 /* iDiag debugfs sub-directory */
46146 struct dentry *idiag_root;
46147 struct dentry *idiag_pci_cfg;
46148diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
46149index 60084e6..0e2e700 100644
46150--- a/drivers/scsi/lpfc/lpfc_debugfs.c
46151+++ b/drivers/scsi/lpfc/lpfc_debugfs.c
46152@@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
46153
46154 #include <linux/debugfs.h>
46155
46156-static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
46157+static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
46158 static unsigned long lpfc_debugfs_start_time = 0L;
46159
46160 /* iDiag */
46161@@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
46162 lpfc_debugfs_enable = 0;
46163
46164 len = 0;
46165- index = (atomic_read(&vport->disc_trc_cnt) + 1) &
46166+ index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
46167 (lpfc_debugfs_max_disc_trc - 1);
46168 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
46169 dtp = vport->disc_trc + i;
46170@@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
46171 lpfc_debugfs_enable = 0;
46172
46173 len = 0;
46174- index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
46175+ index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
46176 (lpfc_debugfs_max_slow_ring_trc - 1);
46177 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
46178 dtp = phba->slow_ring_trc + i;
46179@@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
46180 !vport || !vport->disc_trc)
46181 return;
46182
46183- index = atomic_inc_return(&vport->disc_trc_cnt) &
46184+ index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
46185 (lpfc_debugfs_max_disc_trc - 1);
46186 dtp = vport->disc_trc + index;
46187 dtp->fmt = fmt;
46188 dtp->data1 = data1;
46189 dtp->data2 = data2;
46190 dtp->data3 = data3;
46191- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
46192+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
46193 dtp->jif = jiffies;
46194 #endif
46195 return;
46196@@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
46197 !phba || !phba->slow_ring_trc)
46198 return;
46199
46200- index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
46201+ index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
46202 (lpfc_debugfs_max_slow_ring_trc - 1);
46203 dtp = phba->slow_ring_trc + index;
46204 dtp->fmt = fmt;
46205 dtp->data1 = data1;
46206 dtp->data2 = data2;
46207 dtp->data3 = data3;
46208- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
46209+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
46210 dtp->jif = jiffies;
46211 #endif
46212 return;
46213@@ -4168,7 +4168,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
46214 "slow_ring buffer\n");
46215 goto debug_failed;
46216 }
46217- atomic_set(&phba->slow_ring_trc_cnt, 0);
46218+ atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
46219 memset(phba->slow_ring_trc, 0,
46220 (sizeof(struct lpfc_debugfs_trc) *
46221 lpfc_debugfs_max_slow_ring_trc));
46222@@ -4214,7 +4214,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
46223 "buffer\n");
46224 goto debug_failed;
46225 }
46226- atomic_set(&vport->disc_trc_cnt, 0);
46227+ atomic_set_unchecked(&vport->disc_trc_cnt, 0);
46228
46229 snprintf(name, sizeof(name), "discovery_trace");
46230 vport->debug_disc_trc =
46231diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
46232index 647f5bf..d0068b9 100644
46233--- a/drivers/scsi/lpfc/lpfc_init.c
46234+++ b/drivers/scsi/lpfc/lpfc_init.c
46235@@ -10952,8 +10952,10 @@ lpfc_init(void)
46236 "misc_register returned with status %d", error);
46237
46238 if (lpfc_enable_npiv) {
46239- lpfc_transport_functions.vport_create = lpfc_vport_create;
46240- lpfc_transport_functions.vport_delete = lpfc_vport_delete;
46241+ pax_open_kernel();
46242+ *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
46243+ *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
46244+ pax_close_kernel();
46245 }
46246 lpfc_transport_template =
46247 fc_attach_transport(&lpfc_transport_functions);
46248diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
46249index c913e8c..d34a119 100644
46250--- a/drivers/scsi/lpfc/lpfc_scsi.c
46251+++ b/drivers/scsi/lpfc/lpfc_scsi.c
46252@@ -353,7 +353,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
46253 uint32_t evt_posted;
46254
46255 spin_lock_irqsave(&phba->hbalock, flags);
46256- atomic_inc(&phba->num_rsrc_err);
46257+ atomic_inc_unchecked(&phba->num_rsrc_err);
46258 phba->last_rsrc_error_time = jiffies;
46259
46260 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
46261@@ -394,7 +394,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
46262 unsigned long flags;
46263 struct lpfc_hba *phba = vport->phba;
46264 uint32_t evt_posted;
46265- atomic_inc(&phba->num_cmd_success);
46266+ atomic_inc_unchecked(&phba->num_cmd_success);
46267
46268 if (vport->cfg_lun_queue_depth <= queue_depth)
46269 return;
46270@@ -438,8 +438,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
46271 unsigned long num_rsrc_err, num_cmd_success;
46272 int i;
46273
46274- num_rsrc_err = atomic_read(&phba->num_rsrc_err);
46275- num_cmd_success = atomic_read(&phba->num_cmd_success);
46276+ num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
46277+ num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
46278
46279 /*
46280 * The error and success command counters are global per
46281@@ -467,8 +467,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
46282 }
46283 }
46284 lpfc_destroy_vport_work_array(phba, vports);
46285- atomic_set(&phba->num_rsrc_err, 0);
46286- atomic_set(&phba->num_cmd_success, 0);
46287+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
46288+ atomic_set_unchecked(&phba->num_cmd_success, 0);
46289 }
46290
46291 /**
46292@@ -502,8 +502,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
46293 }
46294 }
46295 lpfc_destroy_vport_work_array(phba, vports);
46296- atomic_set(&phba->num_rsrc_err, 0);
46297- atomic_set(&phba->num_cmd_success, 0);
46298+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
46299+ atomic_set_unchecked(&phba->num_cmd_success, 0);
46300 }
46301
46302 /**
46303diff --git a/drivers/scsi/mpt2sas/mpt2sas_scsih.c b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
46304index 7f0af4f..193ac3e 100644
46305--- a/drivers/scsi/mpt2sas/mpt2sas_scsih.c
46306+++ b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
46307@@ -1557,7 +1557,7 @@ _scsih_get_resync(struct device *dev)
46308 {
46309 struct scsi_device *sdev = to_scsi_device(dev);
46310 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
46311- static struct _raid_device *raid_device;
46312+ struct _raid_device *raid_device;
46313 unsigned long flags;
46314 Mpi2RaidVolPage0_t vol_pg0;
46315 Mpi2ConfigReply_t mpi_reply;
46316@@ -1609,7 +1609,7 @@ _scsih_get_state(struct device *dev)
46317 {
46318 struct scsi_device *sdev = to_scsi_device(dev);
46319 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
46320- static struct _raid_device *raid_device;
46321+ struct _raid_device *raid_device;
46322 unsigned long flags;
46323 Mpi2RaidVolPage0_t vol_pg0;
46324 Mpi2ConfigReply_t mpi_reply;
46325@@ -6637,7 +6637,7 @@ _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER *ioc,
46326 struct fw_event_work *fw_event)
46327 {
46328 Mpi2EventDataIrOperationStatus_t *event_data = fw_event->event_data;
46329- static struct _raid_device *raid_device;
46330+ struct _raid_device *raid_device;
46331 unsigned long flags;
46332 u16 handle;
46333
46334@@ -7108,7 +7108,7 @@ _scsih_scan_for_devices_after_reset(struct MPT2SAS_ADAPTER *ioc)
46335 u64 sas_address;
46336 struct _sas_device *sas_device;
46337 struct _sas_node *expander_device;
46338- static struct _raid_device *raid_device;
46339+ struct _raid_device *raid_device;
46340 u8 retry_count;
46341 unsigned long flags;
46342
46343diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
46344index 1eb7b028..b2a6080 100644
46345--- a/drivers/scsi/pmcraid.c
46346+++ b/drivers/scsi/pmcraid.c
46347@@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
46348 res->scsi_dev = scsi_dev;
46349 scsi_dev->hostdata = res;
46350 res->change_detected = 0;
46351- atomic_set(&res->read_failures, 0);
46352- atomic_set(&res->write_failures, 0);
46353+ atomic_set_unchecked(&res->read_failures, 0);
46354+ atomic_set_unchecked(&res->write_failures, 0);
46355 rc = 0;
46356 }
46357 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
46358@@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
46359
46360 /* If this was a SCSI read/write command keep count of errors */
46361 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
46362- atomic_inc(&res->read_failures);
46363+ atomic_inc_unchecked(&res->read_failures);
46364 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
46365- atomic_inc(&res->write_failures);
46366+ atomic_inc_unchecked(&res->write_failures);
46367
46368 if (!RES_IS_GSCSI(res->cfg_entry) &&
46369 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
46370@@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
46371 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
46372 * hrrq_id assigned here in queuecommand
46373 */
46374- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
46375+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
46376 pinstance->num_hrrq;
46377 cmd->cmd_done = pmcraid_io_done;
46378
46379@@ -3846,7 +3846,7 @@ static long pmcraid_ioctl_passthrough(
46380 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
46381 * hrrq_id assigned here in queuecommand
46382 */
46383- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
46384+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
46385 pinstance->num_hrrq;
46386
46387 if (request_size) {
46388@@ -4483,7 +4483,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
46389
46390 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
46391 /* add resources only after host is added into system */
46392- if (!atomic_read(&pinstance->expose_resources))
46393+ if (!atomic_read_unchecked(&pinstance->expose_resources))
46394 return;
46395
46396 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
46397@@ -5310,8 +5310,8 @@ static int pmcraid_init_instance(struct pci_dev *pdev, struct Scsi_Host *host,
46398 init_waitqueue_head(&pinstance->reset_wait_q);
46399
46400 atomic_set(&pinstance->outstanding_cmds, 0);
46401- atomic_set(&pinstance->last_message_id, 0);
46402- atomic_set(&pinstance->expose_resources, 0);
46403+ atomic_set_unchecked(&pinstance->last_message_id, 0);
46404+ atomic_set_unchecked(&pinstance->expose_resources, 0);
46405
46406 INIT_LIST_HEAD(&pinstance->free_res_q);
46407 INIT_LIST_HEAD(&pinstance->used_res_q);
46408@@ -6024,7 +6024,7 @@ static int pmcraid_probe(struct pci_dev *pdev,
46409 /* Schedule worker thread to handle CCN and take care of adding and
46410 * removing devices to OS
46411 */
46412- atomic_set(&pinstance->expose_resources, 1);
46413+ atomic_set_unchecked(&pinstance->expose_resources, 1);
46414 schedule_work(&pinstance->worker_q);
46415 return rc;
46416
46417diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
46418index e1d150f..6c6df44 100644
46419--- a/drivers/scsi/pmcraid.h
46420+++ b/drivers/scsi/pmcraid.h
46421@@ -748,7 +748,7 @@ struct pmcraid_instance {
46422 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
46423
46424 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
46425- atomic_t last_message_id;
46426+ atomic_unchecked_t last_message_id;
46427
46428 /* configuration table */
46429 struct pmcraid_config_table *cfg_table;
46430@@ -777,7 +777,7 @@ struct pmcraid_instance {
46431 atomic_t outstanding_cmds;
46432
46433 /* should add/delete resources to mid-layer now ?*/
46434- atomic_t expose_resources;
46435+ atomic_unchecked_t expose_resources;
46436
46437
46438
46439@@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
46440 struct pmcraid_config_table_entry_ext cfg_entry_ext;
46441 };
46442 struct scsi_device *scsi_dev; /* Link scsi_device structure */
46443- atomic_t read_failures; /* count of failed READ commands */
46444- atomic_t write_failures; /* count of failed WRITE commands */
46445+ atomic_unchecked_t read_failures; /* count of failed READ commands */
46446+ atomic_unchecked_t write_failures; /* count of failed WRITE commands */
46447
46448 /* To indicate add/delete/modify during CCN */
46449 u8 change_detected;
46450diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
46451index 5f174b8..98d32b0 100644
46452--- a/drivers/scsi/qla2xxx/qla_attr.c
46453+++ b/drivers/scsi/qla2xxx/qla_attr.c
46454@@ -2040,7 +2040,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
46455 return 0;
46456 }
46457
46458-struct fc_function_template qla2xxx_transport_functions = {
46459+fc_function_template_no_const qla2xxx_transport_functions = {
46460
46461 .show_host_node_name = 1,
46462 .show_host_port_name = 1,
46463@@ -2088,7 +2088,7 @@ struct fc_function_template qla2xxx_transport_functions = {
46464 .bsg_timeout = qla24xx_bsg_timeout,
46465 };
46466
46467-struct fc_function_template qla2xxx_transport_vport_functions = {
46468+fc_function_template_no_const qla2xxx_transport_vport_functions = {
46469
46470 .show_host_node_name = 1,
46471 .show_host_port_name = 1,
46472diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
46473index 4446bf5..9a3574d 100644
46474--- a/drivers/scsi/qla2xxx/qla_gbl.h
46475+++ b/drivers/scsi/qla2xxx/qla_gbl.h
46476@@ -538,8 +538,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
46477 struct device_attribute;
46478 extern struct device_attribute *qla2x00_host_attrs[];
46479 struct fc_function_template;
46480-extern struct fc_function_template qla2xxx_transport_functions;
46481-extern struct fc_function_template qla2xxx_transport_vport_functions;
46482+extern fc_function_template_no_const qla2xxx_transport_functions;
46483+extern fc_function_template_no_const qla2xxx_transport_vport_functions;
46484 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
46485 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
46486 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
46487diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
46488index 9f01bbb..5e1dcee 100644
46489--- a/drivers/scsi/qla2xxx/qla_os.c
46490+++ b/drivers/scsi/qla2xxx/qla_os.c
46491@@ -1572,8 +1572,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
46492 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
46493 /* Ok, a 64bit DMA mask is applicable. */
46494 ha->flags.enable_64bit_addressing = 1;
46495- ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
46496- ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
46497+ pax_open_kernel();
46498+ *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
46499+ *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
46500+ pax_close_kernel();
46501 return;
46502 }
46503 }
46504diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
46505index 41327d4..feb03d479 100644
46506--- a/drivers/scsi/qla4xxx/ql4_def.h
46507+++ b/drivers/scsi/qla4xxx/ql4_def.h
46508@@ -296,7 +296,7 @@ struct ddb_entry {
46509 * (4000 only) */
46510 atomic_t relogin_timer; /* Max Time to wait for
46511 * relogin to complete */
46512- atomic_t relogin_retry_count; /* Num of times relogin has been
46513+ atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
46514 * retried */
46515 uint32_t default_time2wait; /* Default Min time between
46516 * relogins (+aens) */
46517diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
46518index f8a0a26..ec03cee 100644
46519--- a/drivers/scsi/qla4xxx/ql4_os.c
46520+++ b/drivers/scsi/qla4xxx/ql4_os.c
46521@@ -3066,12 +3066,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
46522 */
46523 if (!iscsi_is_session_online(cls_sess)) {
46524 /* Reset retry relogin timer */
46525- atomic_inc(&ddb_entry->relogin_retry_count);
46526+ atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
46527 DEBUG2(ql4_printk(KERN_INFO, ha,
46528 "%s: index[%d] relogin timed out-retrying"
46529 " relogin (%d), retry (%d)\n", __func__,
46530 ddb_entry->fw_ddb_index,
46531- atomic_read(&ddb_entry->relogin_retry_count),
46532+ atomic_read_unchecked(&ddb_entry->relogin_retry_count),
46533 ddb_entry->default_time2wait + 4));
46534 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
46535 atomic_set(&ddb_entry->retry_relogin_timer,
46536@@ -5209,7 +5209,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
46537
46538 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
46539 atomic_set(&ddb_entry->relogin_timer, 0);
46540- atomic_set(&ddb_entry->relogin_retry_count, 0);
46541+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
46542 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
46543 ddb_entry->default_relogin_timeout =
46544 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
46545diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
46546index eaa808e..95f8841 100644
46547--- a/drivers/scsi/scsi.c
46548+++ b/drivers/scsi/scsi.c
46549@@ -661,7 +661,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
46550 unsigned long timeout;
46551 int rtn = 0;
46552
46553- atomic_inc(&cmd->device->iorequest_cnt);
46554+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
46555
46556 /* check if the device is still usable */
46557 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
46558diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
46559index d1549b7..2f60767 100644
46560--- a/drivers/scsi/scsi_lib.c
46561+++ b/drivers/scsi/scsi_lib.c
46562@@ -1474,7 +1474,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
46563 shost = sdev->host;
46564 scsi_init_cmd_errh(cmd);
46565 cmd->result = DID_NO_CONNECT << 16;
46566- atomic_inc(&cmd->device->iorequest_cnt);
46567+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
46568
46569 /*
46570 * SCSI request completion path will do scsi_device_unbusy(),
46571@@ -1500,9 +1500,9 @@ static void scsi_softirq_done(struct request *rq)
46572
46573 INIT_LIST_HEAD(&cmd->eh_entry);
46574
46575- atomic_inc(&cmd->device->iodone_cnt);
46576+ atomic_inc_unchecked(&cmd->device->iodone_cnt);
46577 if (cmd->result)
46578- atomic_inc(&cmd->device->ioerr_cnt);
46579+ atomic_inc_unchecked(&cmd->device->ioerr_cnt);
46580
46581 disposition = scsi_decide_disposition(cmd);
46582 if (disposition != SUCCESS &&
46583diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
46584index 40c6394..62356c2 100644
46585--- a/drivers/scsi/scsi_sysfs.c
46586+++ b/drivers/scsi/scsi_sysfs.c
46587@@ -687,7 +687,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
46588 char *buf) \
46589 { \
46590 struct scsi_device *sdev = to_scsi_device(dev); \
46591- unsigned long long count = atomic_read(&sdev->field); \
46592+ unsigned long long count = atomic_read_unchecked(&sdev->field); \
46593 return snprintf(buf, 20, "0x%llx\n", count); \
46594 } \
46595 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
46596diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
46597index 84a1fdf..693b0d6 100644
46598--- a/drivers/scsi/scsi_tgt_lib.c
46599+++ b/drivers/scsi/scsi_tgt_lib.c
46600@@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
46601 int err;
46602
46603 dprintk("%lx %u\n", uaddr, len);
46604- err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
46605+ err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
46606 if (err) {
46607 /*
46608 * TODO: need to fixup sg_tablesize, max_segment_size,
46609diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
46610index 4628fd5..a94a1c2 100644
46611--- a/drivers/scsi/scsi_transport_fc.c
46612+++ b/drivers/scsi/scsi_transport_fc.c
46613@@ -497,7 +497,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
46614 * Netlink Infrastructure
46615 */
46616
46617-static atomic_t fc_event_seq;
46618+static atomic_unchecked_t fc_event_seq;
46619
46620 /**
46621 * fc_get_event_number - Obtain the next sequential FC event number
46622@@ -510,7 +510,7 @@ static atomic_t fc_event_seq;
46623 u32
46624 fc_get_event_number(void)
46625 {
46626- return atomic_add_return(1, &fc_event_seq);
46627+ return atomic_add_return_unchecked(1, &fc_event_seq);
46628 }
46629 EXPORT_SYMBOL(fc_get_event_number);
46630
46631@@ -654,7 +654,7 @@ static __init int fc_transport_init(void)
46632 {
46633 int error;
46634
46635- atomic_set(&fc_event_seq, 0);
46636+ atomic_set_unchecked(&fc_event_seq, 0);
46637
46638 error = transport_class_register(&fc_host_class);
46639 if (error)
46640@@ -844,7 +844,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
46641 char *cp;
46642
46643 *val = simple_strtoul(buf, &cp, 0);
46644- if ((*cp && (*cp != '\n')) || (*val < 0))
46645+ if (*cp && (*cp != '\n'))
46646 return -EINVAL;
46647 /*
46648 * Check for overflow; dev_loss_tmo is u32
46649diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
46650index e4a989f..293090c 100644
46651--- a/drivers/scsi/scsi_transport_iscsi.c
46652+++ b/drivers/scsi/scsi_transport_iscsi.c
46653@@ -79,7 +79,7 @@ struct iscsi_internal {
46654 struct transport_container session_cont;
46655 };
46656
46657-static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
46658+static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
46659 static struct workqueue_struct *iscsi_eh_timer_workq;
46660
46661 static DEFINE_IDA(iscsi_sess_ida);
46662@@ -1737,7 +1737,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
46663 int err;
46664
46665 ihost = shost->shost_data;
46666- session->sid = atomic_add_return(1, &iscsi_session_nr);
46667+ session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
46668
46669 if (target_id == ISCSI_MAX_TARGET) {
46670 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
46671@@ -4077,7 +4077,7 @@ static __init int iscsi_transport_init(void)
46672 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
46673 ISCSI_TRANSPORT_VERSION);
46674
46675- atomic_set(&iscsi_session_nr, 0);
46676+ atomic_set_unchecked(&iscsi_session_nr, 0);
46677
46678 err = class_register(&iscsi_transport_class);
46679 if (err)
46680diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
46681index f379c7f..e8fc69c 100644
46682--- a/drivers/scsi/scsi_transport_srp.c
46683+++ b/drivers/scsi/scsi_transport_srp.c
46684@@ -33,7 +33,7 @@
46685 #include "scsi_transport_srp_internal.h"
46686
46687 struct srp_host_attrs {
46688- atomic_t next_port_id;
46689+ atomic_unchecked_t next_port_id;
46690 };
46691 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
46692
46693@@ -61,7 +61,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
46694 struct Scsi_Host *shost = dev_to_shost(dev);
46695 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
46696
46697- atomic_set(&srp_host->next_port_id, 0);
46698+ atomic_set_unchecked(&srp_host->next_port_id, 0);
46699 return 0;
46700 }
46701
46702@@ -210,7 +210,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
46703 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
46704 rport->roles = ids->roles;
46705
46706- id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
46707+ id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
46708 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
46709
46710 transport_setup_device(&rport->dev);
46711diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
46712index 5693f6d7..b0bf05a 100644
46713--- a/drivers/scsi/sd.c
46714+++ b/drivers/scsi/sd.c
46715@@ -2934,7 +2934,7 @@ static int sd_probe(struct device *dev)
46716 sdkp->disk = gd;
46717 sdkp->index = index;
46718 atomic_set(&sdkp->openers, 0);
46719- atomic_set(&sdkp->device->ioerr_cnt, 0);
46720+ atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
46721
46722 if (!sdp->request_queue->rq_timeout) {
46723 if (sdp->type != TYPE_MOD)
46724diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
46725index df5e961..df6b97f 100644
46726--- a/drivers/scsi/sg.c
46727+++ b/drivers/scsi/sg.c
46728@@ -1102,7 +1102,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
46729 sdp->disk->disk_name,
46730 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
46731 NULL,
46732- (char *)arg);
46733+ (char __user *)arg);
46734 case BLKTRACESTART:
46735 return blk_trace_startstop(sdp->device->request_queue, 1);
46736 case BLKTRACESTOP:
46737diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
46738index 9e039c6..ae9e800 100644
46739--- a/drivers/spi/spi.c
46740+++ b/drivers/spi/spi.c
46741@@ -1762,7 +1762,7 @@ int spi_bus_unlock(struct spi_master *master)
46742 EXPORT_SYMBOL_GPL(spi_bus_unlock);
46743
46744 /* portable code must never pass more than 32 bytes */
46745-#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
46746+#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
46747
46748 static u8 *buf;
46749
46750diff --git a/drivers/staging/android/timed_output.c b/drivers/staging/android/timed_output.c
46751index 2c61783..4d49e4e 100644
46752--- a/drivers/staging/android/timed_output.c
46753+++ b/drivers/staging/android/timed_output.c
46754@@ -25,7 +25,7 @@
46755 #include "timed_output.h"
46756
46757 static struct class *timed_output_class;
46758-static atomic_t device_count;
46759+static atomic_unchecked_t device_count;
46760
46761 static ssize_t enable_show(struct device *dev, struct device_attribute *attr,
46762 char *buf)
46763@@ -63,7 +63,7 @@ static int create_timed_output_class(void)
46764 timed_output_class = class_create(THIS_MODULE, "timed_output");
46765 if (IS_ERR(timed_output_class))
46766 return PTR_ERR(timed_output_class);
46767- atomic_set(&device_count, 0);
46768+ atomic_set_unchecked(&device_count, 0);
46769 timed_output_class->dev_groups = timed_output_groups;
46770 }
46771
46772@@ -81,7 +81,7 @@ int timed_output_dev_register(struct timed_output_dev *tdev)
46773 if (ret < 0)
46774 return ret;
46775
46776- tdev->index = atomic_inc_return(&device_count);
46777+ tdev->index = atomic_inc_return_unchecked(&device_count);
46778 tdev->dev = device_create(timed_output_class, NULL,
46779 MKDEV(0, tdev->index), NULL, "%s", tdev->name);
46780 if (IS_ERR(tdev->dev))
46781diff --git a/drivers/staging/gdm724x/gdm_tty.c b/drivers/staging/gdm724x/gdm_tty.c
46782index 0247a20..cb9595c 100644
46783--- a/drivers/staging/gdm724x/gdm_tty.c
46784+++ b/drivers/staging/gdm724x/gdm_tty.c
46785@@ -45,7 +45,7 @@
46786 #define gdm_tty_send_control(n, r, v, d, l) (\
46787 n->tty_dev->send_control(n->tty_dev->priv_dev, r, v, d, l))
46788
46789-#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && gdm->port.count)
46790+#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && atomic_read(&gdm->port.count))
46791
46792 static struct tty_driver *gdm_driver[TTY_MAX_COUNT];
46793 static struct gdm *gdm_table[TTY_MAX_COUNT][GDM_TTY_MINOR];
46794diff --git a/drivers/staging/lustre/lnet/selftest/brw_test.c b/drivers/staging/lustre/lnet/selftest/brw_test.c
46795index ef5064e..fce01db 100644
46796--- a/drivers/staging/lustre/lnet/selftest/brw_test.c
46797+++ b/drivers/staging/lustre/lnet/selftest/brw_test.c
46798@@ -478,13 +478,11 @@ brw_server_handle(struct srpc_server_rpc *rpc)
46799 return 0;
46800 }
46801
46802-sfw_test_client_ops_t brw_test_client;
46803-void brw_init_test_client(void)
46804-{
46805- brw_test_client.tso_init = brw_client_init;
46806- brw_test_client.tso_fini = brw_client_fini;
46807- brw_test_client.tso_prep_rpc = brw_client_prep_rpc;
46808- brw_test_client.tso_done_rpc = brw_client_done_rpc;
46809+sfw_test_client_ops_t brw_test_client = {
46810+ .tso_init = brw_client_init,
46811+ .tso_fini = brw_client_fini,
46812+ .tso_prep_rpc = brw_client_prep_rpc,
46813+ .tso_done_rpc = brw_client_done_rpc,
46814 };
46815
46816 srpc_service_t brw_test_service;
46817diff --git a/drivers/staging/lustre/lnet/selftest/framework.c b/drivers/staging/lustre/lnet/selftest/framework.c
46818index 483c785..e1a2a7b 100644
46819--- a/drivers/staging/lustre/lnet/selftest/framework.c
46820+++ b/drivers/staging/lustre/lnet/selftest/framework.c
46821@@ -1635,12 +1635,10 @@ static srpc_service_t sfw_services[] =
46822
46823 extern sfw_test_client_ops_t ping_test_client;
46824 extern srpc_service_t ping_test_service;
46825-extern void ping_init_test_client(void);
46826 extern void ping_init_test_service(void);
46827
46828 extern sfw_test_client_ops_t brw_test_client;
46829 extern srpc_service_t brw_test_service;
46830-extern void brw_init_test_client(void);
46831 extern void brw_init_test_service(void);
46832
46833
46834@@ -1684,12 +1682,10 @@ sfw_startup (void)
46835 INIT_LIST_HEAD(&sfw_data.fw_zombie_rpcs);
46836 INIT_LIST_HEAD(&sfw_data.fw_zombie_sessions);
46837
46838- brw_init_test_client();
46839 brw_init_test_service();
46840 rc = sfw_register_test(&brw_test_service, &brw_test_client);
46841 LASSERT (rc == 0);
46842
46843- ping_init_test_client();
46844 ping_init_test_service();
46845 rc = sfw_register_test(&ping_test_service, &ping_test_client);
46846 LASSERT (rc == 0);
46847diff --git a/drivers/staging/lustre/lnet/selftest/ping_test.c b/drivers/staging/lustre/lnet/selftest/ping_test.c
46848index f0f9194..b589047 100644
46849--- a/drivers/staging/lustre/lnet/selftest/ping_test.c
46850+++ b/drivers/staging/lustre/lnet/selftest/ping_test.c
46851@@ -210,14 +210,12 @@ ping_server_handle(struct srpc_server_rpc *rpc)
46852 return 0;
46853 }
46854
46855-sfw_test_client_ops_t ping_test_client;
46856-void ping_init_test_client(void)
46857-{
46858- ping_test_client.tso_init = ping_client_init;
46859- ping_test_client.tso_fini = ping_client_fini;
46860- ping_test_client.tso_prep_rpc = ping_client_prep_rpc;
46861- ping_test_client.tso_done_rpc = ping_client_done_rpc;
46862-}
46863+sfw_test_client_ops_t ping_test_client = {
46864+ .tso_init = ping_client_init,
46865+ .tso_fini = ping_client_fini,
46866+ .tso_prep_rpc = ping_client_prep_rpc,
46867+ .tso_done_rpc = ping_client_done_rpc,
46868+};
46869
46870 srpc_service_t ping_test_service;
46871 void ping_init_test_service(void)
46872diff --git a/drivers/staging/lustre/lustre/include/lustre_dlm.h b/drivers/staging/lustre/lustre/include/lustre_dlm.h
46873index 7020d9c..0d3b580 100644
46874--- a/drivers/staging/lustre/lustre/include/lustre_dlm.h
46875+++ b/drivers/staging/lustre/lustre/include/lustre_dlm.h
46876@@ -1141,7 +1141,7 @@ struct ldlm_callback_suite {
46877 ldlm_completion_callback lcs_completion;
46878 ldlm_blocking_callback lcs_blocking;
46879 ldlm_glimpse_callback lcs_glimpse;
46880-};
46881+} __no_const;
46882
46883 /* ldlm_lockd.c */
46884 int ldlm_del_waiting_lock(struct ldlm_lock *lock);
46885diff --git a/drivers/staging/lustre/lustre/include/obd.h b/drivers/staging/lustre/lustre/include/obd.h
46886index a612255..9a9e2dd 100644
46887--- a/drivers/staging/lustre/lustre/include/obd.h
46888+++ b/drivers/staging/lustre/lustre/include/obd.h
46889@@ -1417,7 +1417,7 @@ struct md_ops {
46890 * lprocfs_alloc_md_stats() in obdclass/lprocfs_status.c. Also, add a
46891 * wrapper function in include/linux/obd_class.h.
46892 */
46893-};
46894+} __no_const;
46895
46896 struct lsm_operations {
46897 void (*lsm_free)(struct lov_stripe_md *);
46898diff --git a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
46899index fc6c977..df1f956 100644
46900--- a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
46901+++ b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
46902@@ -219,7 +219,7 @@ DECLARE_PROC_HANDLER(proc_debug_mb)
46903 int LL_PROC_PROTO(proc_console_max_delay_cs)
46904 {
46905 int rc, max_delay_cs;
46906- ctl_table_t dummy = *table;
46907+ ctl_table_no_const dummy = *table;
46908 cfs_duration_t d;
46909
46910 dummy.data = &max_delay_cs;
46911@@ -250,7 +250,7 @@ int LL_PROC_PROTO(proc_console_max_delay_cs)
46912 int LL_PROC_PROTO(proc_console_min_delay_cs)
46913 {
46914 int rc, min_delay_cs;
46915- ctl_table_t dummy = *table;
46916+ ctl_table_no_const dummy = *table;
46917 cfs_duration_t d;
46918
46919 dummy.data = &min_delay_cs;
46920@@ -281,7 +281,7 @@ int LL_PROC_PROTO(proc_console_min_delay_cs)
46921 int LL_PROC_PROTO(proc_console_backoff)
46922 {
46923 int rc, backoff;
46924- ctl_table_t dummy = *table;
46925+ ctl_table_no_const dummy = *table;
46926
46927 dummy.data = &backoff;
46928 dummy.proc_handler = &proc_dointvec;
46929diff --git a/drivers/staging/media/solo6x10/solo6x10-core.c b/drivers/staging/media/solo6x10/solo6x10-core.c
46930index 3675020..e80d92c 100644
46931--- a/drivers/staging/media/solo6x10/solo6x10-core.c
46932+++ b/drivers/staging/media/solo6x10/solo6x10-core.c
46933@@ -434,7 +434,7 @@ static void solo_device_release(struct device *dev)
46934
46935 static int solo_sysfs_init(struct solo_dev *solo_dev)
46936 {
46937- struct bin_attribute *sdram_attr = &solo_dev->sdram_attr;
46938+ bin_attribute_no_const *sdram_attr = &solo_dev->sdram_attr;
46939 struct device *dev = &solo_dev->dev;
46940 const char *driver;
46941 int i;
46942diff --git a/drivers/staging/media/solo6x10/solo6x10-p2m.c b/drivers/staging/media/solo6x10/solo6x10-p2m.c
46943index 3335941..2b26186 100644
46944--- a/drivers/staging/media/solo6x10/solo6x10-p2m.c
46945+++ b/drivers/staging/media/solo6x10/solo6x10-p2m.c
46946@@ -77,7 +77,7 @@ int solo_p2m_dma_desc(struct solo_dev *solo_dev,
46947
46948 /* Get next ID. According to Softlogic, 6110 has problems on !=0 P2M */
46949 if (solo_dev->type != SOLO_DEV_6110 && multi_p2m) {
46950- p2m_id = atomic_inc_return(&solo_dev->p2m_count) % SOLO_NR_P2M;
46951+ p2m_id = atomic_inc_return_unchecked(&solo_dev->p2m_count) % SOLO_NR_P2M;
46952 if (p2m_id < 0)
46953 p2m_id = -p2m_id;
46954 }
46955diff --git a/drivers/staging/media/solo6x10/solo6x10.h b/drivers/staging/media/solo6x10/solo6x10.h
46956index 6f91d2e..3f011d2 100644
46957--- a/drivers/staging/media/solo6x10/solo6x10.h
46958+++ b/drivers/staging/media/solo6x10/solo6x10.h
46959@@ -238,7 +238,7 @@ struct solo_dev {
46960
46961 /* P2M DMA Engine */
46962 struct solo_p2m_dev p2m_dev[SOLO_NR_P2M];
46963- atomic_t p2m_count;
46964+ atomic_unchecked_t p2m_count;
46965 int p2m_jiffies;
46966 unsigned int p2m_timeouts;
46967
46968diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
46969index e14a1bb..9cb9bbe 100644
46970--- a/drivers/staging/octeon/ethernet-rx.c
46971+++ b/drivers/staging/octeon/ethernet-rx.c
46972@@ -419,11 +419,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
46973 /* Increment RX stats for virtual ports */
46974 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
46975 #ifdef CONFIG_64BIT
46976- atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
46977- atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
46978+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
46979+ atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
46980 #else
46981- atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
46982- atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
46983+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
46984+ atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
46985 #endif
46986 }
46987 netif_receive_skb(skb);
46988@@ -434,9 +434,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
46989 dev->name);
46990 */
46991 #ifdef CONFIG_64BIT
46992- atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
46993+ atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
46994 #else
46995- atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
46996+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
46997 #endif
46998 dev_kfree_skb_irq(skb);
46999 }
47000diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
47001index c3a90e7..023619a 100644
47002--- a/drivers/staging/octeon/ethernet.c
47003+++ b/drivers/staging/octeon/ethernet.c
47004@@ -252,11 +252,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
47005 * since the RX tasklet also increments it.
47006 */
47007 #ifdef CONFIG_64BIT
47008- atomic64_add(rx_status.dropped_packets,
47009- (atomic64_t *)&priv->stats.rx_dropped);
47010+ atomic64_add_unchecked(rx_status.dropped_packets,
47011+ (atomic64_unchecked_t *)&priv->stats.rx_dropped);
47012 #else
47013- atomic_add(rx_status.dropped_packets,
47014- (atomic_t *)&priv->stats.rx_dropped);
47015+ atomic_add_unchecked(rx_status.dropped_packets,
47016+ (atomic_unchecked_t *)&priv->stats.rx_dropped);
47017 #endif
47018 }
47019
47020diff --git a/drivers/staging/rtl8188eu/include/hal_intf.h b/drivers/staging/rtl8188eu/include/hal_intf.h
47021index 439c3c9..2d74293 100644
47022--- a/drivers/staging/rtl8188eu/include/hal_intf.h
47023+++ b/drivers/staging/rtl8188eu/include/hal_intf.h
47024@@ -271,7 +271,7 @@ struct hal_ops {
47025 s32 (*c2h_handler)(struct adapter *padapter,
47026 struct c2h_evt_hdr *c2h_evt);
47027 c2h_id_filter c2h_id_filter_ccx;
47028-};
47029+} __no_const;
47030
47031 enum rt_eeprom_type {
47032 EEPROM_93C46,
47033diff --git a/drivers/staging/rtl8188eu/include/rtw_io.h b/drivers/staging/rtl8188eu/include/rtw_io.h
47034index eb6f0e5..e6a0958 100644
47035--- a/drivers/staging/rtl8188eu/include/rtw_io.h
47036+++ b/drivers/staging/rtl8188eu/include/rtw_io.h
47037@@ -126,7 +126,7 @@ struct _io_ops {
47038 u32 (*_write_scsi)(struct intf_hdl *pintfhdl,u32 cnt, u8 *pmem);
47039 void (*_read_port_cancel)(struct intf_hdl *pintfhdl);
47040 void (*_write_port_cancel)(struct intf_hdl *pintfhdl);
47041-};
47042+} __no_const;
47043
47044 struct io_req {
47045 struct list_head list;
47046diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
47047index dc23395..cf7e9b1 100644
47048--- a/drivers/staging/rtl8712/rtl871x_io.h
47049+++ b/drivers/staging/rtl8712/rtl871x_io.h
47050@@ -108,7 +108,7 @@ struct _io_ops {
47051 u8 *pmem);
47052 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
47053 u8 *pmem);
47054-};
47055+} __no_const;
47056
47057 struct io_req {
47058 struct list_head list;
47059diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
47060index 1f5088b..0e59820 100644
47061--- a/drivers/staging/sbe-2t3e3/netdev.c
47062+++ b/drivers/staging/sbe-2t3e3/netdev.c
47063@@ -51,7 +51,7 @@ static int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
47064 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
47065
47066 if (rlen)
47067- if (copy_to_user(data, &resp, rlen))
47068+ if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
47069 return -EFAULT;
47070
47071 return 0;
47072diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
47073index a863a98..d272795 100644
47074--- a/drivers/staging/usbip/vhci.h
47075+++ b/drivers/staging/usbip/vhci.h
47076@@ -83,7 +83,7 @@ struct vhci_hcd {
47077 unsigned resuming:1;
47078 unsigned long re_timeout;
47079
47080- atomic_t seqnum;
47081+ atomic_unchecked_t seqnum;
47082
47083 /*
47084 * NOTE:
47085diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
47086index d7974cb..d78076b 100644
47087--- a/drivers/staging/usbip/vhci_hcd.c
47088+++ b/drivers/staging/usbip/vhci_hcd.c
47089@@ -441,7 +441,7 @@ static void vhci_tx_urb(struct urb *urb)
47090
47091 spin_lock(&vdev->priv_lock);
47092
47093- priv->seqnum = atomic_inc_return(&the_controller->seqnum);
47094+ priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
47095 if (priv->seqnum == 0xffff)
47096 dev_info(&urb->dev->dev, "seqnum max\n");
47097
47098@@ -687,7 +687,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
47099 return -ENOMEM;
47100 }
47101
47102- unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
47103+ unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
47104 if (unlink->seqnum == 0xffff)
47105 pr_info("seqnum max\n");
47106
47107@@ -891,7 +891,7 @@ static int vhci_start(struct usb_hcd *hcd)
47108 vdev->rhport = rhport;
47109 }
47110
47111- atomic_set(&vhci->seqnum, 0);
47112+ atomic_set_unchecked(&vhci->seqnum, 0);
47113 spin_lock_init(&vhci->lock);
47114
47115 hcd->power_budget = 0; /* no limit */
47116diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
47117index d07fcb5..358e1e1 100644
47118--- a/drivers/staging/usbip/vhci_rx.c
47119+++ b/drivers/staging/usbip/vhci_rx.c
47120@@ -80,7 +80,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
47121 if (!urb) {
47122 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
47123 pr_info("max seqnum %d\n",
47124- atomic_read(&the_controller->seqnum));
47125+ atomic_read_unchecked(&the_controller->seqnum));
47126 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
47127 return;
47128 }
47129diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
47130index 8acff44..bdb2fca 100644
47131--- a/drivers/staging/vt6655/hostap.c
47132+++ b/drivers/staging/vt6655/hostap.c
47133@@ -69,14 +69,13 @@ static int msglevel = MSG_LEVEL_INFO;
47134 *
47135 */
47136
47137+static net_device_ops_no_const apdev_netdev_ops;
47138+
47139 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
47140 {
47141 PSDevice apdev_priv;
47142 struct net_device *dev = pDevice->dev;
47143 int ret;
47144- const struct net_device_ops apdev_netdev_ops = {
47145- .ndo_start_xmit = pDevice->tx_80211,
47146- };
47147
47148 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
47149
47150@@ -88,6 +87,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
47151 *apdev_priv = *pDevice;
47152 eth_hw_addr_inherit(pDevice->apdev, dev);
47153
47154+ /* only half broken now */
47155+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
47156 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
47157
47158 pDevice->apdev->type = ARPHRD_IEEE80211;
47159diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
47160index c699a30..b90a5fd 100644
47161--- a/drivers/staging/vt6656/hostap.c
47162+++ b/drivers/staging/vt6656/hostap.c
47163@@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
47164 *
47165 */
47166
47167+static net_device_ops_no_const apdev_netdev_ops;
47168+
47169 static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
47170 {
47171 struct vnt_private *apdev_priv;
47172 struct net_device *dev = pDevice->dev;
47173 int ret;
47174- const struct net_device_ops apdev_netdev_ops = {
47175- .ndo_start_xmit = pDevice->tx_80211,
47176- };
47177
47178 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
47179
47180@@ -79,6 +78,8 @@ static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
47181 *apdev_priv = *pDevice;
47182 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
47183
47184+ /* only half broken now */
47185+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
47186 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
47187
47188 pDevice->apdev->type = ARPHRD_IEEE80211;
47189diff --git a/drivers/target/sbp/sbp_target.c b/drivers/target/sbp/sbp_target.c
47190index e51b09a..5ebac31 100644
47191--- a/drivers/target/sbp/sbp_target.c
47192+++ b/drivers/target/sbp/sbp_target.c
47193@@ -62,7 +62,7 @@ static const u32 sbp_unit_directory_template[] = {
47194
47195 #define SESSION_MAINTENANCE_INTERVAL HZ
47196
47197-static atomic_t login_id = ATOMIC_INIT(0);
47198+static atomic_unchecked_t login_id = ATOMIC_INIT(0);
47199
47200 static void session_maintenance_work(struct work_struct *);
47201 static int sbp_run_transaction(struct fw_card *, int, int, int, int,
47202@@ -444,7 +444,7 @@ static void sbp_management_request_login(
47203 login->lun = se_lun;
47204 login->status_fifo_addr = sbp2_pointer_to_addr(&req->orb.status_fifo);
47205 login->exclusive = LOGIN_ORB_EXCLUSIVE(be32_to_cpu(req->orb.misc));
47206- login->login_id = atomic_inc_return(&login_id);
47207+ login->login_id = atomic_inc_return_unchecked(&login_id);
47208
47209 login->tgt_agt = sbp_target_agent_register(login);
47210 if (IS_ERR(login->tgt_agt)) {
47211diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
47212index d90dbb0..6cbe585 100644
47213--- a/drivers/target/target_core_device.c
47214+++ b/drivers/target/target_core_device.c
47215@@ -1431,7 +1431,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
47216 spin_lock_init(&dev->se_tmr_lock);
47217 spin_lock_init(&dev->qf_cmd_lock);
47218 sema_init(&dev->caw_sem, 1);
47219- atomic_set(&dev->dev_ordered_id, 0);
47220+ atomic_set_unchecked(&dev->dev_ordered_id, 0);
47221 INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
47222 spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
47223 INIT_LIST_HEAD(&dev->t10_pr.registration_list);
47224diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
47225index 81e945e..e40c92f 100644
47226--- a/drivers/target/target_core_transport.c
47227+++ b/drivers/target/target_core_transport.c
47228@@ -1137,7 +1137,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
47229 * Used to determine when ORDERED commands should go from
47230 * Dormant to Active status.
47231 */
47232- cmd->se_ordered_id = atomic_inc_return(&dev->dev_ordered_id);
47233+ cmd->se_ordered_id = atomic_inc_return_unchecked(&dev->dev_ordered_id);
47234 smp_mb__after_atomic_inc();
47235 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
47236 cmd->se_ordered_id, cmd->sam_task_attr,
47237diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
47238index 33f83fe..d80f8e1 100644
47239--- a/drivers/tty/cyclades.c
47240+++ b/drivers/tty/cyclades.c
47241@@ -1570,10 +1570,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
47242 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
47243 info->port.count);
47244 #endif
47245- info->port.count++;
47246+ atomic_inc(&info->port.count);
47247 #ifdef CY_DEBUG_COUNT
47248 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
47249- current->pid, info->port.count);
47250+ current->pid, atomic_read(&info->port.count));
47251 #endif
47252
47253 /*
47254@@ -3972,7 +3972,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
47255 for (j = 0; j < cy_card[i].nports; j++) {
47256 info = &cy_card[i].ports[j];
47257
47258- if (info->port.count) {
47259+ if (atomic_read(&info->port.count)) {
47260 /* XXX is the ldisc num worth this? */
47261 struct tty_struct *tty;
47262 struct tty_ldisc *ld;
47263diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
47264index 9eba119..5070303 100644
47265--- a/drivers/tty/hvc/hvc_console.c
47266+++ b/drivers/tty/hvc/hvc_console.c
47267@@ -338,7 +338,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
47268
47269 spin_lock_irqsave(&hp->port.lock, flags);
47270 /* Check and then increment for fast path open. */
47271- if (hp->port.count++ > 0) {
47272+ if (atomic_inc_return(&hp->port.count) > 1) {
47273 spin_unlock_irqrestore(&hp->port.lock, flags);
47274 hvc_kick();
47275 return 0;
47276@@ -393,7 +393,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
47277
47278 spin_lock_irqsave(&hp->port.lock, flags);
47279
47280- if (--hp->port.count == 0) {
47281+ if (atomic_dec_return(&hp->port.count) == 0) {
47282 spin_unlock_irqrestore(&hp->port.lock, flags);
47283 /* We are done with the tty pointer now. */
47284 tty_port_tty_set(&hp->port, NULL);
47285@@ -415,9 +415,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
47286 */
47287 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
47288 } else {
47289- if (hp->port.count < 0)
47290+ if (atomic_read(&hp->port.count) < 0)
47291 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
47292- hp->vtermno, hp->port.count);
47293+ hp->vtermno, atomic_read(&hp->port.count));
47294 spin_unlock_irqrestore(&hp->port.lock, flags);
47295 }
47296 }
47297@@ -447,12 +447,12 @@ static void hvc_hangup(struct tty_struct *tty)
47298 * open->hangup case this can be called after the final close so prevent
47299 * that from happening for now.
47300 */
47301- if (hp->port.count <= 0) {
47302+ if (atomic_read(&hp->port.count) <= 0) {
47303 spin_unlock_irqrestore(&hp->port.lock, flags);
47304 return;
47305 }
47306
47307- hp->port.count = 0;
47308+ atomic_set(&hp->port.count, 0);
47309 spin_unlock_irqrestore(&hp->port.lock, flags);
47310 tty_port_tty_set(&hp->port, NULL);
47311
47312@@ -500,7 +500,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
47313 return -EPIPE;
47314
47315 /* FIXME what's this (unprotected) check for? */
47316- if (hp->port.count <= 0)
47317+ if (atomic_read(&hp->port.count) <= 0)
47318 return -EIO;
47319
47320 spin_lock_irqsave(&hp->lock, flags);
47321diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
47322index 81e939e..95ead10 100644
47323--- a/drivers/tty/hvc/hvcs.c
47324+++ b/drivers/tty/hvc/hvcs.c
47325@@ -83,6 +83,7 @@
47326 #include <asm/hvcserver.h>
47327 #include <asm/uaccess.h>
47328 #include <asm/vio.h>
47329+#include <asm/local.h>
47330
47331 /*
47332 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
47333@@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
47334
47335 spin_lock_irqsave(&hvcsd->lock, flags);
47336
47337- if (hvcsd->port.count > 0) {
47338+ if (atomic_read(&hvcsd->port.count) > 0) {
47339 spin_unlock_irqrestore(&hvcsd->lock, flags);
47340 printk(KERN_INFO "HVCS: vterm state unchanged. "
47341 "The hvcs device node is still in use.\n");
47342@@ -1127,7 +1128,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
47343 }
47344 }
47345
47346- hvcsd->port.count = 0;
47347+ atomic_set(&hvcsd->port.count, 0);
47348 hvcsd->port.tty = tty;
47349 tty->driver_data = hvcsd;
47350
47351@@ -1180,7 +1181,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
47352 unsigned long flags;
47353
47354 spin_lock_irqsave(&hvcsd->lock, flags);
47355- hvcsd->port.count++;
47356+ atomic_inc(&hvcsd->port.count);
47357 hvcsd->todo_mask |= HVCS_SCHED_READ;
47358 spin_unlock_irqrestore(&hvcsd->lock, flags);
47359
47360@@ -1216,7 +1217,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
47361 hvcsd = tty->driver_data;
47362
47363 spin_lock_irqsave(&hvcsd->lock, flags);
47364- if (--hvcsd->port.count == 0) {
47365+ if (atomic_dec_and_test(&hvcsd->port.count)) {
47366
47367 vio_disable_interrupts(hvcsd->vdev);
47368
47369@@ -1241,10 +1242,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
47370
47371 free_irq(irq, hvcsd);
47372 return;
47373- } else if (hvcsd->port.count < 0) {
47374+ } else if (atomic_read(&hvcsd->port.count) < 0) {
47375 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
47376 " is missmanaged.\n",
47377- hvcsd->vdev->unit_address, hvcsd->port.count);
47378+ hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
47379 }
47380
47381 spin_unlock_irqrestore(&hvcsd->lock, flags);
47382@@ -1266,7 +1267,7 @@ static void hvcs_hangup(struct tty_struct * tty)
47383
47384 spin_lock_irqsave(&hvcsd->lock, flags);
47385 /* Preserve this so that we know how many kref refs to put */
47386- temp_open_count = hvcsd->port.count;
47387+ temp_open_count = atomic_read(&hvcsd->port.count);
47388
47389 /*
47390 * Don't kref put inside the spinlock because the destruction
47391@@ -1281,7 +1282,7 @@ static void hvcs_hangup(struct tty_struct * tty)
47392 tty->driver_data = NULL;
47393 hvcsd->port.tty = NULL;
47394
47395- hvcsd->port.count = 0;
47396+ atomic_set(&hvcsd->port.count, 0);
47397
47398 /* This will drop any buffered data on the floor which is OK in a hangup
47399 * scenario. */
47400@@ -1352,7 +1353,7 @@ static int hvcs_write(struct tty_struct *tty,
47401 * the middle of a write operation? This is a crummy place to do this
47402 * but we want to keep it all in the spinlock.
47403 */
47404- if (hvcsd->port.count <= 0) {
47405+ if (atomic_read(&hvcsd->port.count) <= 0) {
47406 spin_unlock_irqrestore(&hvcsd->lock, flags);
47407 return -ENODEV;
47408 }
47409@@ -1426,7 +1427,7 @@ static int hvcs_write_room(struct tty_struct *tty)
47410 {
47411 struct hvcs_struct *hvcsd = tty->driver_data;
47412
47413- if (!hvcsd || hvcsd->port.count <= 0)
47414+ if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
47415 return 0;
47416
47417 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
47418diff --git a/drivers/tty/hvc/hvsi.c b/drivers/tty/hvc/hvsi.c
47419index 4190199..48f2920 100644
47420--- a/drivers/tty/hvc/hvsi.c
47421+++ b/drivers/tty/hvc/hvsi.c
47422@@ -85,7 +85,7 @@ struct hvsi_struct {
47423 int n_outbuf;
47424 uint32_t vtermno;
47425 uint32_t virq;
47426- atomic_t seqno; /* HVSI packet sequence number */
47427+ atomic_unchecked_t seqno; /* HVSI packet sequence number */
47428 uint16_t mctrl;
47429 uint8_t state; /* HVSI protocol state */
47430 uint8_t flags;
47431@@ -295,7 +295,7 @@ static int hvsi_version_respond(struct hvsi_struct *hp, uint16_t query_seqno)
47432
47433 packet.hdr.type = VS_QUERY_RESPONSE_PACKET_HEADER;
47434 packet.hdr.len = sizeof(struct hvsi_query_response);
47435- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
47436+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
47437 packet.verb = VSV_SEND_VERSION_NUMBER;
47438 packet.u.version = HVSI_VERSION;
47439 packet.query_seqno = query_seqno+1;
47440@@ -555,7 +555,7 @@ static int hvsi_query(struct hvsi_struct *hp, uint16_t verb)
47441
47442 packet.hdr.type = VS_QUERY_PACKET_HEADER;
47443 packet.hdr.len = sizeof(struct hvsi_query);
47444- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
47445+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
47446 packet.verb = verb;
47447
47448 pr_debug("%s: sending %i bytes\n", __func__, packet.hdr.len);
47449@@ -597,7 +597,7 @@ static int hvsi_set_mctrl(struct hvsi_struct *hp, uint16_t mctrl)
47450 int wrote;
47451
47452 packet.hdr.type = VS_CONTROL_PACKET_HEADER,
47453- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
47454+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
47455 packet.hdr.len = sizeof(struct hvsi_control);
47456 packet.verb = VSV_SET_MODEM_CTL;
47457 packet.mask = HVSI_TSDTR;
47458@@ -680,7 +680,7 @@ static int hvsi_put_chars(struct hvsi_struct *hp, const char *buf, int count)
47459 BUG_ON(count > HVSI_MAX_OUTGOING_DATA);
47460
47461 packet.hdr.type = VS_DATA_PACKET_HEADER;
47462- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
47463+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
47464 packet.hdr.len = count + sizeof(struct hvsi_header);
47465 memcpy(&packet.data, buf, count);
47466
47467@@ -697,7 +697,7 @@ static void hvsi_close_protocol(struct hvsi_struct *hp)
47468 struct hvsi_control packet __ALIGNED__;
47469
47470 packet.hdr.type = VS_CONTROL_PACKET_HEADER;
47471- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
47472+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
47473 packet.hdr.len = 6;
47474 packet.verb = VSV_CLOSE_PROTOCOL;
47475
47476diff --git a/drivers/tty/hvc/hvsi_lib.c b/drivers/tty/hvc/hvsi_lib.c
47477index ac27671..0f627ee 100644
47478--- a/drivers/tty/hvc/hvsi_lib.c
47479+++ b/drivers/tty/hvc/hvsi_lib.c
47480@@ -9,7 +9,7 @@
47481
47482 static int hvsi_send_packet(struct hvsi_priv *pv, struct hvsi_header *packet)
47483 {
47484- packet->seqno = atomic_inc_return(&pv->seqno);
47485+ packet->seqno = atomic_inc_return_unchecked(&pv->seqno);
47486
47487 /* Assumes that always succeeds, works in practice */
47488 return pv->put_chars(pv->termno, (char *)packet, packet->len);
47489@@ -21,7 +21,7 @@ static void hvsi_start_handshake(struct hvsi_priv *pv)
47490
47491 /* Reset state */
47492 pv->established = 0;
47493- atomic_set(&pv->seqno, 0);
47494+ atomic_set_unchecked(&pv->seqno, 0);
47495
47496 pr_devel("HVSI@%x: Handshaking started\n", pv->termno);
47497
47498@@ -265,7 +265,7 @@ int hvsilib_read_mctrl(struct hvsi_priv *pv)
47499 pv->mctrl_update = 0;
47500 q.hdr.type = VS_QUERY_PACKET_HEADER;
47501 q.hdr.len = sizeof(struct hvsi_query);
47502- q.hdr.seqno = atomic_inc_return(&pv->seqno);
47503+ q.hdr.seqno = atomic_inc_return_unchecked(&pv->seqno);
47504 q.verb = VSV_SEND_MODEM_CTL_STATUS;
47505 rc = hvsi_send_packet(pv, &q.hdr);
47506 if (rc <= 0) {
47507diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
47508index 8fd72ff..34a0bed 100644
47509--- a/drivers/tty/ipwireless/tty.c
47510+++ b/drivers/tty/ipwireless/tty.c
47511@@ -29,6 +29,7 @@
47512 #include <linux/tty_driver.h>
47513 #include <linux/tty_flip.h>
47514 #include <linux/uaccess.h>
47515+#include <asm/local.h>
47516
47517 #include "tty.h"
47518 #include "network.h"
47519@@ -99,10 +100,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
47520 mutex_unlock(&tty->ipw_tty_mutex);
47521 return -ENODEV;
47522 }
47523- if (tty->port.count == 0)
47524+ if (atomic_read(&tty->port.count) == 0)
47525 tty->tx_bytes_queued = 0;
47526
47527- tty->port.count++;
47528+ atomic_inc(&tty->port.count);
47529
47530 tty->port.tty = linux_tty;
47531 linux_tty->driver_data = tty;
47532@@ -118,9 +119,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
47533
47534 static void do_ipw_close(struct ipw_tty *tty)
47535 {
47536- tty->port.count--;
47537-
47538- if (tty->port.count == 0) {
47539+ if (atomic_dec_return(&tty->port.count) == 0) {
47540 struct tty_struct *linux_tty = tty->port.tty;
47541
47542 if (linux_tty != NULL) {
47543@@ -141,7 +140,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
47544 return;
47545
47546 mutex_lock(&tty->ipw_tty_mutex);
47547- if (tty->port.count == 0) {
47548+ if (atomic_read(&tty->port.count) == 0) {
47549 mutex_unlock(&tty->ipw_tty_mutex);
47550 return;
47551 }
47552@@ -164,7 +163,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
47553
47554 mutex_lock(&tty->ipw_tty_mutex);
47555
47556- if (!tty->port.count) {
47557+ if (!atomic_read(&tty->port.count)) {
47558 mutex_unlock(&tty->ipw_tty_mutex);
47559 return;
47560 }
47561@@ -206,7 +205,7 @@ static int ipw_write(struct tty_struct *linux_tty,
47562 return -ENODEV;
47563
47564 mutex_lock(&tty->ipw_tty_mutex);
47565- if (!tty->port.count) {
47566+ if (!atomic_read(&tty->port.count)) {
47567 mutex_unlock(&tty->ipw_tty_mutex);
47568 return -EINVAL;
47569 }
47570@@ -246,7 +245,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
47571 if (!tty)
47572 return -ENODEV;
47573
47574- if (!tty->port.count)
47575+ if (!atomic_read(&tty->port.count))
47576 return -EINVAL;
47577
47578 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
47579@@ -288,7 +287,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
47580 if (!tty)
47581 return 0;
47582
47583- if (!tty->port.count)
47584+ if (!atomic_read(&tty->port.count))
47585 return 0;
47586
47587 return tty->tx_bytes_queued;
47588@@ -369,7 +368,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
47589 if (!tty)
47590 return -ENODEV;
47591
47592- if (!tty->port.count)
47593+ if (!atomic_read(&tty->port.count))
47594 return -EINVAL;
47595
47596 return get_control_lines(tty);
47597@@ -385,7 +384,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
47598 if (!tty)
47599 return -ENODEV;
47600
47601- if (!tty->port.count)
47602+ if (!atomic_read(&tty->port.count))
47603 return -EINVAL;
47604
47605 return set_control_lines(tty, set, clear);
47606@@ -399,7 +398,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
47607 if (!tty)
47608 return -ENODEV;
47609
47610- if (!tty->port.count)
47611+ if (!atomic_read(&tty->port.count))
47612 return -EINVAL;
47613
47614 /* FIXME: Exactly how is the tty object locked here .. */
47615@@ -555,7 +554,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
47616 * are gone */
47617 mutex_lock(&ttyj->ipw_tty_mutex);
47618 }
47619- while (ttyj->port.count)
47620+ while (atomic_read(&ttyj->port.count))
47621 do_ipw_close(ttyj);
47622 ipwireless_disassociate_network_ttys(network,
47623 ttyj->channel_idx);
47624diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
47625index 1deaca4..c8582d4 100644
47626--- a/drivers/tty/moxa.c
47627+++ b/drivers/tty/moxa.c
47628@@ -1189,7 +1189,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
47629 }
47630
47631 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
47632- ch->port.count++;
47633+ atomic_inc(&ch->port.count);
47634 tty->driver_data = ch;
47635 tty_port_tty_set(&ch->port, tty);
47636 mutex_lock(&ch->port.mutex);
47637diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
47638index c0f76da..d974c32 100644
47639--- a/drivers/tty/n_gsm.c
47640+++ b/drivers/tty/n_gsm.c
47641@@ -1632,7 +1632,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
47642 spin_lock_init(&dlci->lock);
47643 mutex_init(&dlci->mutex);
47644 dlci->fifo = &dlci->_fifo;
47645- if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
47646+ if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
47647 kfree(dlci);
47648 return NULL;
47649 }
47650@@ -2935,7 +2935,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
47651 struct gsm_dlci *dlci = tty->driver_data;
47652 struct tty_port *port = &dlci->port;
47653
47654- port->count++;
47655+ atomic_inc(&port->count);
47656 dlci_get(dlci);
47657 dlci_get(dlci->gsm->dlci[0]);
47658 mux_get(dlci->gsm);
47659diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
47660index 7a744b6..6aa4aa9 100644
47661--- a/drivers/tty/n_tty.c
47662+++ b/drivers/tty/n_tty.c
47663@@ -2498,6 +2498,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
47664 {
47665 *ops = tty_ldisc_N_TTY;
47666 ops->owner = NULL;
47667- ops->refcount = ops->flags = 0;
47668+ atomic_set(&ops->refcount, 0);
47669+ ops->flags = 0;
47670 }
47671 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
47672diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
47673index 25c9bc7..24077b7 100644
47674--- a/drivers/tty/pty.c
47675+++ b/drivers/tty/pty.c
47676@@ -790,8 +790,10 @@ static void __init unix98_pty_init(void)
47677 panic("Couldn't register Unix98 pts driver");
47678
47679 /* Now create the /dev/ptmx special device */
47680+ pax_open_kernel();
47681 tty_default_fops(&ptmx_fops);
47682- ptmx_fops.open = ptmx_open;
47683+ *(void **)&ptmx_fops.open = ptmx_open;
47684+ pax_close_kernel();
47685
47686 cdev_init(&ptmx_cdev, &ptmx_fops);
47687 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
47688diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
47689index 354564e..fe50d9a 100644
47690--- a/drivers/tty/rocket.c
47691+++ b/drivers/tty/rocket.c
47692@@ -914,7 +914,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
47693 tty->driver_data = info;
47694 tty_port_tty_set(port, tty);
47695
47696- if (port->count++ == 0) {
47697+ if (atomic_inc_return(&port->count) == 1) {
47698 atomic_inc(&rp_num_ports_open);
47699
47700 #ifdef ROCKET_DEBUG_OPEN
47701@@ -923,7 +923,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
47702 #endif
47703 }
47704 #ifdef ROCKET_DEBUG_OPEN
47705- printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
47706+ printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
47707 #endif
47708
47709 /*
47710@@ -1515,7 +1515,7 @@ static void rp_hangup(struct tty_struct *tty)
47711 spin_unlock_irqrestore(&info->port.lock, flags);
47712 return;
47713 }
47714- if (info->port.count)
47715+ if (atomic_read(&info->port.count))
47716 atomic_dec(&rp_num_ports_open);
47717 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
47718 spin_unlock_irqrestore(&info->port.lock, flags);
47719diff --git a/drivers/tty/serial/ioc4_serial.c b/drivers/tty/serial/ioc4_serial.c
47720index 1274499..f541382 100644
47721--- a/drivers/tty/serial/ioc4_serial.c
47722+++ b/drivers/tty/serial/ioc4_serial.c
47723@@ -437,7 +437,7 @@ struct ioc4_soft {
47724 } is_intr_info[MAX_IOC4_INTR_ENTS];
47725
47726 /* Number of entries active in the above array */
47727- atomic_t is_num_intrs;
47728+ atomic_unchecked_t is_num_intrs;
47729 } is_intr_type[IOC4_NUM_INTR_TYPES];
47730
47731 /* is_ir_lock must be held while
47732@@ -974,7 +974,7 @@ intr_connect(struct ioc4_soft *soft, int type,
47733 BUG_ON(!((type == IOC4_SIO_INTR_TYPE)
47734 || (type == IOC4_OTHER_INTR_TYPE)));
47735
47736- i = atomic_inc_return(&soft-> is_intr_type[type].is_num_intrs) - 1;
47737+ i = atomic_inc_return_unchecked(&soft-> is_intr_type[type].is_num_intrs) - 1;
47738 BUG_ON(!(i < MAX_IOC4_INTR_ENTS || (printk("i %d\n", i), 0)));
47739
47740 /* Save off the lower level interrupt handler */
47741@@ -1001,7 +1001,7 @@ static irqreturn_t ioc4_intr(int irq, void *arg)
47742
47743 soft = arg;
47744 for (intr_type = 0; intr_type < IOC4_NUM_INTR_TYPES; intr_type++) {
47745- num_intrs = (int)atomic_read(
47746+ num_intrs = (int)atomic_read_unchecked(
47747 &soft->is_intr_type[intr_type].is_num_intrs);
47748
47749 this_mir = this_ir = pending_intrs(soft, intr_type);
47750diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
47751index a260cde..6b2b5ce 100644
47752--- a/drivers/tty/serial/kgdboc.c
47753+++ b/drivers/tty/serial/kgdboc.c
47754@@ -24,8 +24,9 @@
47755 #define MAX_CONFIG_LEN 40
47756
47757 static struct kgdb_io kgdboc_io_ops;
47758+static struct kgdb_io kgdboc_io_ops_console;
47759
47760-/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
47761+/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
47762 static int configured = -1;
47763
47764 static char config[MAX_CONFIG_LEN];
47765@@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
47766 kgdboc_unregister_kbd();
47767 if (configured == 1)
47768 kgdb_unregister_io_module(&kgdboc_io_ops);
47769+ else if (configured == 2)
47770+ kgdb_unregister_io_module(&kgdboc_io_ops_console);
47771 }
47772
47773 static int configure_kgdboc(void)
47774@@ -160,13 +163,13 @@ static int configure_kgdboc(void)
47775 int err;
47776 char *cptr = config;
47777 struct console *cons;
47778+ int is_console = 0;
47779
47780 err = kgdboc_option_setup(config);
47781 if (err || !strlen(config) || isspace(config[0]))
47782 goto noconfig;
47783
47784 err = -ENODEV;
47785- kgdboc_io_ops.is_console = 0;
47786 kgdb_tty_driver = NULL;
47787
47788 kgdboc_use_kms = 0;
47789@@ -187,7 +190,7 @@ static int configure_kgdboc(void)
47790 int idx;
47791 if (cons->device && cons->device(cons, &idx) == p &&
47792 idx == tty_line) {
47793- kgdboc_io_ops.is_console = 1;
47794+ is_console = 1;
47795 break;
47796 }
47797 cons = cons->next;
47798@@ -197,7 +200,13 @@ static int configure_kgdboc(void)
47799 kgdb_tty_line = tty_line;
47800
47801 do_register:
47802- err = kgdb_register_io_module(&kgdboc_io_ops);
47803+ if (is_console) {
47804+ err = kgdb_register_io_module(&kgdboc_io_ops_console);
47805+ configured = 2;
47806+ } else {
47807+ err = kgdb_register_io_module(&kgdboc_io_ops);
47808+ configured = 1;
47809+ }
47810 if (err)
47811 goto noconfig;
47812
47813@@ -205,8 +214,6 @@ do_register:
47814 if (err)
47815 goto nmi_con_failed;
47816
47817- configured = 1;
47818-
47819 return 0;
47820
47821 nmi_con_failed:
47822@@ -223,7 +230,7 @@ noconfig:
47823 static int __init init_kgdboc(void)
47824 {
47825 /* Already configured? */
47826- if (configured == 1)
47827+ if (configured >= 1)
47828 return 0;
47829
47830 return configure_kgdboc();
47831@@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
47832 if (config[len - 1] == '\n')
47833 config[len - 1] = '\0';
47834
47835- if (configured == 1)
47836+ if (configured >= 1)
47837 cleanup_kgdboc();
47838
47839 /* Go and configure with the new params. */
47840@@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
47841 .post_exception = kgdboc_post_exp_handler,
47842 };
47843
47844+static struct kgdb_io kgdboc_io_ops_console = {
47845+ .name = "kgdboc",
47846+ .read_char = kgdboc_get_char,
47847+ .write_char = kgdboc_put_char,
47848+ .pre_exception = kgdboc_pre_exp_handler,
47849+ .post_exception = kgdboc_post_exp_handler,
47850+ .is_console = 1
47851+};
47852+
47853 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
47854 /* This is only available if kgdboc is a built in for early debugging */
47855 static int __init kgdboc_early_init(char *opt)
47856diff --git a/drivers/tty/serial/msm_serial.c b/drivers/tty/serial/msm_serial.c
47857index b5d779c..3622cfe 100644
47858--- a/drivers/tty/serial/msm_serial.c
47859+++ b/drivers/tty/serial/msm_serial.c
47860@@ -897,7 +897,7 @@ static struct uart_driver msm_uart_driver = {
47861 .cons = MSM_CONSOLE,
47862 };
47863
47864-static atomic_t msm_uart_next_id = ATOMIC_INIT(0);
47865+static atomic_unchecked_t msm_uart_next_id = ATOMIC_INIT(0);
47866
47867 static const struct of_device_id msm_uartdm_table[] = {
47868 { .compatible = "qcom,msm-uartdm" },
47869@@ -912,7 +912,7 @@ static int __init msm_serial_probe(struct platform_device *pdev)
47870 int irq;
47871
47872 if (pdev->id == -1)
47873- pdev->id = atomic_inc_return(&msm_uart_next_id) - 1;
47874+ pdev->id = atomic_inc_return_unchecked(&msm_uart_next_id) - 1;
47875
47876 if (unlikely(pdev->id < 0 || pdev->id >= UART_NR))
47877 return -ENXIO;
47878diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
47879index f3dfa19..342f2ff 100644
47880--- a/drivers/tty/serial/samsung.c
47881+++ b/drivers/tty/serial/samsung.c
47882@@ -456,11 +456,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
47883 }
47884 }
47885
47886+static int s3c64xx_serial_startup(struct uart_port *port);
47887 static int s3c24xx_serial_startup(struct uart_port *port)
47888 {
47889 struct s3c24xx_uart_port *ourport = to_ourport(port);
47890 int ret;
47891
47892+ /* Startup sequence is different for s3c64xx and higher SoC's */
47893+ if (s3c24xx_serial_has_interrupt_mask(port))
47894+ return s3c64xx_serial_startup(port);
47895+
47896 dbg("s3c24xx_serial_startup: port=%p (%08lx,%p)\n",
47897 port->mapbase, port->membase);
47898
47899@@ -1127,10 +1132,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
47900 /* setup info for port */
47901 port->dev = &platdev->dev;
47902
47903- /* Startup sequence is different for s3c64xx and higher SoC's */
47904- if (s3c24xx_serial_has_interrupt_mask(port))
47905- s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
47906-
47907 port->uartclk = 1;
47908
47909 if (cfg->uart_flags & UPF_CONS_FLOW) {
47910diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
47911index 0f02351..07c59c5 100644
47912--- a/drivers/tty/serial/serial_core.c
47913+++ b/drivers/tty/serial/serial_core.c
47914@@ -1448,7 +1448,7 @@ static void uart_hangup(struct tty_struct *tty)
47915 uart_flush_buffer(tty);
47916 uart_shutdown(tty, state);
47917 spin_lock_irqsave(&port->lock, flags);
47918- port->count = 0;
47919+ atomic_set(&port->count, 0);
47920 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
47921 spin_unlock_irqrestore(&port->lock, flags);
47922 tty_port_tty_set(port, NULL);
47923@@ -1544,7 +1544,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
47924 goto end;
47925 }
47926
47927- port->count++;
47928+ atomic_inc(&port->count);
47929 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
47930 retval = -ENXIO;
47931 goto err_dec_count;
47932@@ -1572,7 +1572,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
47933 /*
47934 * Make sure the device is in D0 state.
47935 */
47936- if (port->count == 1)
47937+ if (atomic_read(&port->count) == 1)
47938 uart_change_pm(state, UART_PM_STATE_ON);
47939
47940 /*
47941@@ -1590,7 +1590,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
47942 end:
47943 return retval;
47944 err_dec_count:
47945- port->count--;
47946+ atomic_inc(&port->count);
47947 mutex_unlock(&port->mutex);
47948 goto end;
47949 }
47950diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
47951index e1ce141..6d4ed80 100644
47952--- a/drivers/tty/synclink.c
47953+++ b/drivers/tty/synclink.c
47954@@ -3090,7 +3090,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
47955
47956 if (debug_level >= DEBUG_LEVEL_INFO)
47957 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
47958- __FILE__,__LINE__, info->device_name, info->port.count);
47959+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
47960
47961 if (tty_port_close_start(&info->port, tty, filp) == 0)
47962 goto cleanup;
47963@@ -3108,7 +3108,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
47964 cleanup:
47965 if (debug_level >= DEBUG_LEVEL_INFO)
47966 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
47967- tty->driver->name, info->port.count);
47968+ tty->driver->name, atomic_read(&info->port.count));
47969
47970 } /* end of mgsl_close() */
47971
47972@@ -3207,8 +3207,8 @@ static void mgsl_hangup(struct tty_struct *tty)
47973
47974 mgsl_flush_buffer(tty);
47975 shutdown(info);
47976-
47977- info->port.count = 0;
47978+
47979+ atomic_set(&info->port.count, 0);
47980 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
47981 info->port.tty = NULL;
47982
47983@@ -3297,12 +3297,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
47984
47985 if (debug_level >= DEBUG_LEVEL_INFO)
47986 printk("%s(%d):block_til_ready before block on %s count=%d\n",
47987- __FILE__,__LINE__, tty->driver->name, port->count );
47988+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
47989
47990 spin_lock_irqsave(&info->irq_spinlock, flags);
47991 if (!tty_hung_up_p(filp)) {
47992 extra_count = true;
47993- port->count--;
47994+ atomic_dec(&port->count);
47995 }
47996 spin_unlock_irqrestore(&info->irq_spinlock, flags);
47997 port->blocked_open++;
47998@@ -3331,7 +3331,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
47999
48000 if (debug_level >= DEBUG_LEVEL_INFO)
48001 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
48002- __FILE__,__LINE__, tty->driver->name, port->count );
48003+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
48004
48005 tty_unlock(tty);
48006 schedule();
48007@@ -3343,12 +3343,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
48008
48009 /* FIXME: Racy on hangup during close wait */
48010 if (extra_count)
48011- port->count++;
48012+ atomic_inc(&port->count);
48013 port->blocked_open--;
48014
48015 if (debug_level >= DEBUG_LEVEL_INFO)
48016 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
48017- __FILE__,__LINE__, tty->driver->name, port->count );
48018+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
48019
48020 if (!retval)
48021 port->flags |= ASYNC_NORMAL_ACTIVE;
48022@@ -3400,7 +3400,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
48023
48024 if (debug_level >= DEBUG_LEVEL_INFO)
48025 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
48026- __FILE__,__LINE__,tty->driver->name, info->port.count);
48027+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
48028
48029 /* If port is closing, signal caller to try again */
48030 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
48031@@ -3419,10 +3419,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
48032 spin_unlock_irqrestore(&info->netlock, flags);
48033 goto cleanup;
48034 }
48035- info->port.count++;
48036+ atomic_inc(&info->port.count);
48037 spin_unlock_irqrestore(&info->netlock, flags);
48038
48039- if (info->port.count == 1) {
48040+ if (atomic_read(&info->port.count) == 1) {
48041 /* 1st open on this device, init hardware */
48042 retval = startup(info);
48043 if (retval < 0)
48044@@ -3446,8 +3446,8 @@ cleanup:
48045 if (retval) {
48046 if (tty->count == 1)
48047 info->port.tty = NULL; /* tty layer will release tty struct */
48048- if(info->port.count)
48049- info->port.count--;
48050+ if (atomic_read(&info->port.count))
48051+ atomic_dec(&info->port.count);
48052 }
48053
48054 return retval;
48055@@ -7665,7 +7665,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
48056 unsigned short new_crctype;
48057
48058 /* return error if TTY interface open */
48059- if (info->port.count)
48060+ if (atomic_read(&info->port.count))
48061 return -EBUSY;
48062
48063 switch (encoding)
48064@@ -7760,7 +7760,7 @@ static int hdlcdev_open(struct net_device *dev)
48065
48066 /* arbitrate between network and tty opens */
48067 spin_lock_irqsave(&info->netlock, flags);
48068- if (info->port.count != 0 || info->netcount != 0) {
48069+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
48070 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
48071 spin_unlock_irqrestore(&info->netlock, flags);
48072 return -EBUSY;
48073@@ -7846,7 +7846,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
48074 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
48075
48076 /* return error if TTY interface open */
48077- if (info->port.count)
48078+ if (atomic_read(&info->port.count))
48079 return -EBUSY;
48080
48081 if (cmd != SIOCWANDEV)
48082diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
48083index 1abf946..1ee34fc 100644
48084--- a/drivers/tty/synclink_gt.c
48085+++ b/drivers/tty/synclink_gt.c
48086@@ -670,7 +670,7 @@ static int open(struct tty_struct *tty, struct file *filp)
48087 tty->driver_data = info;
48088 info->port.tty = tty;
48089
48090- DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
48091+ DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
48092
48093 /* If port is closing, signal caller to try again */
48094 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
48095@@ -691,10 +691,10 @@ static int open(struct tty_struct *tty, struct file *filp)
48096 mutex_unlock(&info->port.mutex);
48097 goto cleanup;
48098 }
48099- info->port.count++;
48100+ atomic_inc(&info->port.count);
48101 spin_unlock_irqrestore(&info->netlock, flags);
48102
48103- if (info->port.count == 1) {
48104+ if (atomic_read(&info->port.count) == 1) {
48105 /* 1st open on this device, init hardware */
48106 retval = startup(info);
48107 if (retval < 0) {
48108@@ -715,8 +715,8 @@ cleanup:
48109 if (retval) {
48110 if (tty->count == 1)
48111 info->port.tty = NULL; /* tty layer will release tty struct */
48112- if(info->port.count)
48113- info->port.count--;
48114+ if(atomic_read(&info->port.count))
48115+ atomic_dec(&info->port.count);
48116 }
48117
48118 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
48119@@ -729,7 +729,7 @@ static void close(struct tty_struct *tty, struct file *filp)
48120
48121 if (sanity_check(info, tty->name, "close"))
48122 return;
48123- DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
48124+ DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
48125
48126 if (tty_port_close_start(&info->port, tty, filp) == 0)
48127 goto cleanup;
48128@@ -746,7 +746,7 @@ static void close(struct tty_struct *tty, struct file *filp)
48129 tty_port_close_end(&info->port, tty);
48130 info->port.tty = NULL;
48131 cleanup:
48132- DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
48133+ DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
48134 }
48135
48136 static void hangup(struct tty_struct *tty)
48137@@ -764,7 +764,7 @@ static void hangup(struct tty_struct *tty)
48138 shutdown(info);
48139
48140 spin_lock_irqsave(&info->port.lock, flags);
48141- info->port.count = 0;
48142+ atomic_set(&info->port.count, 0);
48143 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
48144 info->port.tty = NULL;
48145 spin_unlock_irqrestore(&info->port.lock, flags);
48146@@ -1449,7 +1449,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
48147 unsigned short new_crctype;
48148
48149 /* return error if TTY interface open */
48150- if (info->port.count)
48151+ if (atomic_read(&info->port.count))
48152 return -EBUSY;
48153
48154 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
48155@@ -1544,7 +1544,7 @@ static int hdlcdev_open(struct net_device *dev)
48156
48157 /* arbitrate between network and tty opens */
48158 spin_lock_irqsave(&info->netlock, flags);
48159- if (info->port.count != 0 || info->netcount != 0) {
48160+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
48161 DBGINFO(("%s hdlc_open busy\n", dev->name));
48162 spin_unlock_irqrestore(&info->netlock, flags);
48163 return -EBUSY;
48164@@ -1629,7 +1629,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
48165 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
48166
48167 /* return error if TTY interface open */
48168- if (info->port.count)
48169+ if (atomic_read(&info->port.count))
48170 return -EBUSY;
48171
48172 if (cmd != SIOCWANDEV)
48173@@ -2413,7 +2413,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
48174 if (port == NULL)
48175 continue;
48176 spin_lock(&port->lock);
48177- if ((port->port.count || port->netcount) &&
48178+ if ((atomic_read(&port->port.count) || port->netcount) &&
48179 port->pending_bh && !port->bh_running &&
48180 !port->bh_requested) {
48181 DBGISR(("%s bh queued\n", port->device_name));
48182@@ -3302,7 +3302,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
48183 spin_lock_irqsave(&info->lock, flags);
48184 if (!tty_hung_up_p(filp)) {
48185 extra_count = true;
48186- port->count--;
48187+ atomic_dec(&port->count);
48188 }
48189 spin_unlock_irqrestore(&info->lock, flags);
48190 port->blocked_open++;
48191@@ -3339,7 +3339,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
48192 remove_wait_queue(&port->open_wait, &wait);
48193
48194 if (extra_count)
48195- port->count++;
48196+ atomic_inc(&port->count);
48197 port->blocked_open--;
48198
48199 if (!retval)
48200diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
48201index dc6e969..5dc8786 100644
48202--- a/drivers/tty/synclinkmp.c
48203+++ b/drivers/tty/synclinkmp.c
48204@@ -750,7 +750,7 @@ static int open(struct tty_struct *tty, struct file *filp)
48205
48206 if (debug_level >= DEBUG_LEVEL_INFO)
48207 printk("%s(%d):%s open(), old ref count = %d\n",
48208- __FILE__,__LINE__,tty->driver->name, info->port.count);
48209+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
48210
48211 /* If port is closing, signal caller to try again */
48212 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
48213@@ -769,10 +769,10 @@ static int open(struct tty_struct *tty, struct file *filp)
48214 spin_unlock_irqrestore(&info->netlock, flags);
48215 goto cleanup;
48216 }
48217- info->port.count++;
48218+ atomic_inc(&info->port.count);
48219 spin_unlock_irqrestore(&info->netlock, flags);
48220
48221- if (info->port.count == 1) {
48222+ if (atomic_read(&info->port.count) == 1) {
48223 /* 1st open on this device, init hardware */
48224 retval = startup(info);
48225 if (retval < 0)
48226@@ -796,8 +796,8 @@ cleanup:
48227 if (retval) {
48228 if (tty->count == 1)
48229 info->port.tty = NULL; /* tty layer will release tty struct */
48230- if(info->port.count)
48231- info->port.count--;
48232+ if(atomic_read(&info->port.count))
48233+ atomic_dec(&info->port.count);
48234 }
48235
48236 return retval;
48237@@ -815,7 +815,7 @@ static void close(struct tty_struct *tty, struct file *filp)
48238
48239 if (debug_level >= DEBUG_LEVEL_INFO)
48240 printk("%s(%d):%s close() entry, count=%d\n",
48241- __FILE__,__LINE__, info->device_name, info->port.count);
48242+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
48243
48244 if (tty_port_close_start(&info->port, tty, filp) == 0)
48245 goto cleanup;
48246@@ -834,7 +834,7 @@ static void close(struct tty_struct *tty, struct file *filp)
48247 cleanup:
48248 if (debug_level >= DEBUG_LEVEL_INFO)
48249 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
48250- tty->driver->name, info->port.count);
48251+ tty->driver->name, atomic_read(&info->port.count));
48252 }
48253
48254 /* Called by tty_hangup() when a hangup is signaled.
48255@@ -857,7 +857,7 @@ static void hangup(struct tty_struct *tty)
48256 shutdown(info);
48257
48258 spin_lock_irqsave(&info->port.lock, flags);
48259- info->port.count = 0;
48260+ atomic_set(&info->port.count, 0);
48261 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
48262 info->port.tty = NULL;
48263 spin_unlock_irqrestore(&info->port.lock, flags);
48264@@ -1565,7 +1565,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
48265 unsigned short new_crctype;
48266
48267 /* return error if TTY interface open */
48268- if (info->port.count)
48269+ if (atomic_read(&info->port.count))
48270 return -EBUSY;
48271
48272 switch (encoding)
48273@@ -1660,7 +1660,7 @@ static int hdlcdev_open(struct net_device *dev)
48274
48275 /* arbitrate between network and tty opens */
48276 spin_lock_irqsave(&info->netlock, flags);
48277- if (info->port.count != 0 || info->netcount != 0) {
48278+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
48279 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
48280 spin_unlock_irqrestore(&info->netlock, flags);
48281 return -EBUSY;
48282@@ -1746,7 +1746,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
48283 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
48284
48285 /* return error if TTY interface open */
48286- if (info->port.count)
48287+ if (atomic_read(&info->port.count))
48288 return -EBUSY;
48289
48290 if (cmd != SIOCWANDEV)
48291@@ -2620,7 +2620,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
48292 * do not request bottom half processing if the
48293 * device is not open in a normal mode.
48294 */
48295- if ( port && (port->port.count || port->netcount) &&
48296+ if ( port && (atomic_read(&port->port.count) || port->netcount) &&
48297 port->pending_bh && !port->bh_running &&
48298 !port->bh_requested ) {
48299 if ( debug_level >= DEBUG_LEVEL_ISR )
48300@@ -3318,12 +3318,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
48301
48302 if (debug_level >= DEBUG_LEVEL_INFO)
48303 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
48304- __FILE__,__LINE__, tty->driver->name, port->count );
48305+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
48306
48307 spin_lock_irqsave(&info->lock, flags);
48308 if (!tty_hung_up_p(filp)) {
48309 extra_count = true;
48310- port->count--;
48311+ atomic_dec(&port->count);
48312 }
48313 spin_unlock_irqrestore(&info->lock, flags);
48314 port->blocked_open++;
48315@@ -3352,7 +3352,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
48316
48317 if (debug_level >= DEBUG_LEVEL_INFO)
48318 printk("%s(%d):%s block_til_ready() count=%d\n",
48319- __FILE__,__LINE__, tty->driver->name, port->count );
48320+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
48321
48322 tty_unlock(tty);
48323 schedule();
48324@@ -3363,12 +3363,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
48325 remove_wait_queue(&port->open_wait, &wait);
48326
48327 if (extra_count)
48328- port->count++;
48329+ atomic_inc(&port->count);
48330 port->blocked_open--;
48331
48332 if (debug_level >= DEBUG_LEVEL_INFO)
48333 printk("%s(%d):%s block_til_ready() after, count=%d\n",
48334- __FILE__,__LINE__, tty->driver->name, port->count );
48335+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
48336
48337 if (!retval)
48338 port->flags |= ASYNC_NORMAL_ACTIVE;
48339diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
48340index 40a9fe9..a3f10cc 100644
48341--- a/drivers/tty/sysrq.c
48342+++ b/drivers/tty/sysrq.c
48343@@ -1075,7 +1075,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
48344 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
48345 size_t count, loff_t *ppos)
48346 {
48347- if (count) {
48348+ if (count && capable(CAP_SYS_ADMIN)) {
48349 char c;
48350
48351 if (get_user(c, buf))
48352diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
48353index 3a1a01a..b12cda2 100644
48354--- a/drivers/tty/tty_io.c
48355+++ b/drivers/tty/tty_io.c
48356@@ -3473,7 +3473,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
48357
48358 void tty_default_fops(struct file_operations *fops)
48359 {
48360- *fops = tty_fops;
48361+ memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
48362 }
48363
48364 /*
48365diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
48366index 6458e11..6cfc218 100644
48367--- a/drivers/tty/tty_ldisc.c
48368+++ b/drivers/tty/tty_ldisc.c
48369@@ -72,7 +72,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
48370 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
48371 tty_ldiscs[disc] = new_ldisc;
48372 new_ldisc->num = disc;
48373- new_ldisc->refcount = 0;
48374+ atomic_set(&new_ldisc->refcount, 0);
48375 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
48376
48377 return ret;
48378@@ -100,7 +100,7 @@ int tty_unregister_ldisc(int disc)
48379 return -EINVAL;
48380
48381 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
48382- if (tty_ldiscs[disc]->refcount)
48383+ if (atomic_read(&tty_ldiscs[disc]->refcount))
48384 ret = -EBUSY;
48385 else
48386 tty_ldiscs[disc] = NULL;
48387@@ -121,7 +121,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
48388 if (ldops) {
48389 ret = ERR_PTR(-EAGAIN);
48390 if (try_module_get(ldops->owner)) {
48391- ldops->refcount++;
48392+ atomic_inc(&ldops->refcount);
48393 ret = ldops;
48394 }
48395 }
48396@@ -134,7 +134,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
48397 unsigned long flags;
48398
48399 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
48400- ldops->refcount--;
48401+ atomic_dec(&ldops->refcount);
48402 module_put(ldops->owner);
48403 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
48404 }
48405diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
48406index f597e88..b7f68ed 100644
48407--- a/drivers/tty/tty_port.c
48408+++ b/drivers/tty/tty_port.c
48409@@ -232,7 +232,7 @@ void tty_port_hangup(struct tty_port *port)
48410 unsigned long flags;
48411
48412 spin_lock_irqsave(&port->lock, flags);
48413- port->count = 0;
48414+ atomic_set(&port->count, 0);
48415 port->flags &= ~ASYNC_NORMAL_ACTIVE;
48416 tty = port->tty;
48417 if (tty)
48418@@ -390,7 +390,7 @@ int tty_port_block_til_ready(struct tty_port *port,
48419 /* The port lock protects the port counts */
48420 spin_lock_irqsave(&port->lock, flags);
48421 if (!tty_hung_up_p(filp))
48422- port->count--;
48423+ atomic_dec(&port->count);
48424 port->blocked_open++;
48425 spin_unlock_irqrestore(&port->lock, flags);
48426
48427@@ -432,7 +432,7 @@ int tty_port_block_til_ready(struct tty_port *port,
48428 we must not mess that up further */
48429 spin_lock_irqsave(&port->lock, flags);
48430 if (!tty_hung_up_p(filp))
48431- port->count++;
48432+ atomic_inc(&port->count);
48433 port->blocked_open--;
48434 if (retval == 0)
48435 port->flags |= ASYNC_NORMAL_ACTIVE;
48436@@ -466,19 +466,19 @@ int tty_port_close_start(struct tty_port *port,
48437 return 0;
48438 }
48439
48440- if (tty->count == 1 && port->count != 1) {
48441+ if (tty->count == 1 && atomic_read(&port->count) != 1) {
48442 printk(KERN_WARNING
48443 "tty_port_close_start: tty->count = 1 port count = %d.\n",
48444- port->count);
48445- port->count = 1;
48446+ atomic_read(&port->count));
48447+ atomic_set(&port->count, 1);
48448 }
48449- if (--port->count < 0) {
48450+ if (atomic_dec_return(&port->count) < 0) {
48451 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
48452- port->count);
48453- port->count = 0;
48454+ atomic_read(&port->count));
48455+ atomic_set(&port->count, 0);
48456 }
48457
48458- if (port->count) {
48459+ if (atomic_read(&port->count)) {
48460 spin_unlock_irqrestore(&port->lock, flags);
48461 if (port->ops->drop)
48462 port->ops->drop(port);
48463@@ -564,7 +564,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
48464 {
48465 spin_lock_irq(&port->lock);
48466 if (!tty_hung_up_p(filp))
48467- ++port->count;
48468+ atomic_inc(&port->count);
48469 spin_unlock_irq(&port->lock);
48470 tty_port_tty_set(port, tty);
48471
48472diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
48473index d0e3a44..5f8b754 100644
48474--- a/drivers/tty/vt/keyboard.c
48475+++ b/drivers/tty/vt/keyboard.c
48476@@ -641,6 +641,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
48477 kbd->kbdmode == VC_OFF) &&
48478 value != KVAL(K_SAK))
48479 return; /* SAK is allowed even in raw mode */
48480+
48481+#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
48482+ {
48483+ void *func = fn_handler[value];
48484+ if (func == fn_show_state || func == fn_show_ptregs ||
48485+ func == fn_show_mem)
48486+ return;
48487+ }
48488+#endif
48489+
48490 fn_handler[value](vc);
48491 }
48492
48493@@ -1776,9 +1786,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
48494 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
48495 return -EFAULT;
48496
48497- if (!capable(CAP_SYS_TTY_CONFIG))
48498- perm = 0;
48499-
48500 switch (cmd) {
48501 case KDGKBENT:
48502 /* Ensure another thread doesn't free it under us */
48503@@ -1793,6 +1800,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
48504 spin_unlock_irqrestore(&kbd_event_lock, flags);
48505 return put_user(val, &user_kbe->kb_value);
48506 case KDSKBENT:
48507+ if (!capable(CAP_SYS_TTY_CONFIG))
48508+ perm = 0;
48509+
48510 if (!perm)
48511 return -EPERM;
48512 if (!i && v == K_NOSUCHMAP) {
48513@@ -1883,9 +1893,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
48514 int i, j, k;
48515 int ret;
48516
48517- if (!capable(CAP_SYS_TTY_CONFIG))
48518- perm = 0;
48519-
48520 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
48521 if (!kbs) {
48522 ret = -ENOMEM;
48523@@ -1919,6 +1926,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
48524 kfree(kbs);
48525 return ((p && *p) ? -EOVERFLOW : 0);
48526 case KDSKBSENT:
48527+ if (!capable(CAP_SYS_TTY_CONFIG))
48528+ perm = 0;
48529+
48530 if (!perm) {
48531 ret = -EPERM;
48532 goto reterr;
48533diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
48534index 0e808cf..26c24ab 100644
48535--- a/drivers/uio/uio.c
48536+++ b/drivers/uio/uio.c
48537@@ -25,6 +25,7 @@
48538 #include <linux/kobject.h>
48539 #include <linux/cdev.h>
48540 #include <linux/uio_driver.h>
48541+#include <asm/local.h>
48542
48543 #define UIO_MAX_DEVICES (1U << MINORBITS)
48544
48545@@ -32,7 +33,7 @@ struct uio_device {
48546 struct module *owner;
48547 struct device *dev;
48548 int minor;
48549- atomic_t event;
48550+ atomic_unchecked_t event;
48551 struct fasync_struct *async_queue;
48552 wait_queue_head_t wait;
48553 struct uio_info *info;
48554@@ -243,7 +244,7 @@ static ssize_t event_show(struct device *dev,
48555 struct device_attribute *attr, char *buf)
48556 {
48557 struct uio_device *idev = dev_get_drvdata(dev);
48558- return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
48559+ return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
48560 }
48561 static DEVICE_ATTR_RO(event);
48562
48563@@ -401,7 +402,7 @@ void uio_event_notify(struct uio_info *info)
48564 {
48565 struct uio_device *idev = info->uio_dev;
48566
48567- atomic_inc(&idev->event);
48568+ atomic_inc_unchecked(&idev->event);
48569 wake_up_interruptible(&idev->wait);
48570 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
48571 }
48572@@ -454,7 +455,7 @@ static int uio_open(struct inode *inode, struct file *filep)
48573 }
48574
48575 listener->dev = idev;
48576- listener->event_count = atomic_read(&idev->event);
48577+ listener->event_count = atomic_read_unchecked(&idev->event);
48578 filep->private_data = listener;
48579
48580 if (idev->info->open) {
48581@@ -505,7 +506,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
48582 return -EIO;
48583
48584 poll_wait(filep, &idev->wait, wait);
48585- if (listener->event_count != atomic_read(&idev->event))
48586+ if (listener->event_count != atomic_read_unchecked(&idev->event))
48587 return POLLIN | POLLRDNORM;
48588 return 0;
48589 }
48590@@ -530,7 +531,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
48591 do {
48592 set_current_state(TASK_INTERRUPTIBLE);
48593
48594- event_count = atomic_read(&idev->event);
48595+ event_count = atomic_read_unchecked(&idev->event);
48596 if (event_count != listener->event_count) {
48597 if (copy_to_user(buf, &event_count, count))
48598 retval = -EFAULT;
48599@@ -587,9 +588,13 @@ static ssize_t uio_write(struct file *filep, const char __user *buf,
48600 static int uio_find_mem_index(struct vm_area_struct *vma)
48601 {
48602 struct uio_device *idev = vma->vm_private_data;
48603+ unsigned long size;
48604
48605 if (vma->vm_pgoff < MAX_UIO_MAPS) {
48606- if (idev->info->mem[vma->vm_pgoff].size == 0)
48607+ size = idev->info->mem[vma->vm_pgoff].size;
48608+ if (size == 0)
48609+ return -1;
48610+ if (vma->vm_end - vma->vm_start > size)
48611 return -1;
48612 return (int)vma->vm_pgoff;
48613 }
48614@@ -818,7 +823,7 @@ int __uio_register_device(struct module *owner,
48615 idev->owner = owner;
48616 idev->info = info;
48617 init_waitqueue_head(&idev->wait);
48618- atomic_set(&idev->event, 0);
48619+ atomic_set_unchecked(&idev->event, 0);
48620
48621 ret = uio_get_minor(idev);
48622 if (ret)
48623diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
48624index 8a7eb77..c00402f 100644
48625--- a/drivers/usb/atm/cxacru.c
48626+++ b/drivers/usb/atm/cxacru.c
48627@@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
48628 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
48629 if (ret < 2)
48630 return -EINVAL;
48631- if (index < 0 || index > 0x7f)
48632+ if (index > 0x7f)
48633 return -EINVAL;
48634 pos += tmp;
48635
48636diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
48637index 25a7bfc..57f3cf5 100644
48638--- a/drivers/usb/atm/usbatm.c
48639+++ b/drivers/usb/atm/usbatm.c
48640@@ -331,7 +331,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
48641 if (printk_ratelimit())
48642 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
48643 __func__, vpi, vci);
48644- atomic_inc(&vcc->stats->rx_err);
48645+ atomic_inc_unchecked(&vcc->stats->rx_err);
48646 return;
48647 }
48648
48649@@ -358,7 +358,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
48650 if (length > ATM_MAX_AAL5_PDU) {
48651 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
48652 __func__, length, vcc);
48653- atomic_inc(&vcc->stats->rx_err);
48654+ atomic_inc_unchecked(&vcc->stats->rx_err);
48655 goto out;
48656 }
48657
48658@@ -367,14 +367,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
48659 if (sarb->len < pdu_length) {
48660 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
48661 __func__, pdu_length, sarb->len, vcc);
48662- atomic_inc(&vcc->stats->rx_err);
48663+ atomic_inc_unchecked(&vcc->stats->rx_err);
48664 goto out;
48665 }
48666
48667 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
48668 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
48669 __func__, vcc);
48670- atomic_inc(&vcc->stats->rx_err);
48671+ atomic_inc_unchecked(&vcc->stats->rx_err);
48672 goto out;
48673 }
48674
48675@@ -386,7 +386,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
48676 if (printk_ratelimit())
48677 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
48678 __func__, length);
48679- atomic_inc(&vcc->stats->rx_drop);
48680+ atomic_inc_unchecked(&vcc->stats->rx_drop);
48681 goto out;
48682 }
48683
48684@@ -414,7 +414,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
48685
48686 vcc->push(vcc, skb);
48687
48688- atomic_inc(&vcc->stats->rx);
48689+ atomic_inc_unchecked(&vcc->stats->rx);
48690 out:
48691 skb_trim(sarb, 0);
48692 }
48693@@ -612,7 +612,7 @@ static void usbatm_tx_process(unsigned long data)
48694 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
48695
48696 usbatm_pop(vcc, skb);
48697- atomic_inc(&vcc->stats->tx);
48698+ atomic_inc_unchecked(&vcc->stats->tx);
48699
48700 skb = skb_dequeue(&instance->sndqueue);
48701 }
48702@@ -756,11 +756,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
48703 if (!left--)
48704 return sprintf(page,
48705 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
48706- atomic_read(&atm_dev->stats.aal5.tx),
48707- atomic_read(&atm_dev->stats.aal5.tx_err),
48708- atomic_read(&atm_dev->stats.aal5.rx),
48709- atomic_read(&atm_dev->stats.aal5.rx_err),
48710- atomic_read(&atm_dev->stats.aal5.rx_drop));
48711+ atomic_read_unchecked(&atm_dev->stats.aal5.tx),
48712+ atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
48713+ atomic_read_unchecked(&atm_dev->stats.aal5.rx),
48714+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
48715+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
48716
48717 if (!left--) {
48718 if (instance->disconnected)
48719diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
48720index 2a3bbdf..91d72cf 100644
48721--- a/drivers/usb/core/devices.c
48722+++ b/drivers/usb/core/devices.c
48723@@ -126,7 +126,7 @@ static const char format_endpt[] =
48724 * time it gets called.
48725 */
48726 static struct device_connect_event {
48727- atomic_t count;
48728+ atomic_unchecked_t count;
48729 wait_queue_head_t wait;
48730 } device_event = {
48731 .count = ATOMIC_INIT(1),
48732@@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
48733
48734 void usbfs_conn_disc_event(void)
48735 {
48736- atomic_add(2, &device_event.count);
48737+ atomic_add_unchecked(2, &device_event.count);
48738 wake_up(&device_event.wait);
48739 }
48740
48741@@ -652,7 +652,7 @@ static unsigned int usb_device_poll(struct file *file,
48742
48743 poll_wait(file, &device_event.wait, wait);
48744
48745- event_count = atomic_read(&device_event.count);
48746+ event_count = atomic_read_unchecked(&device_event.count);
48747 if (file->f_version != event_count) {
48748 file->f_version = event_count;
48749 return POLLIN | POLLRDNORM;
48750diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
48751index f20a044..d1059aa 100644
48752--- a/drivers/usb/core/hcd.c
48753+++ b/drivers/usb/core/hcd.c
48754@@ -1552,7 +1552,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
48755 */
48756 usb_get_urb(urb);
48757 atomic_inc(&urb->use_count);
48758- atomic_inc(&urb->dev->urbnum);
48759+ atomic_inc_unchecked(&urb->dev->urbnum);
48760 usbmon_urb_submit(&hcd->self, urb);
48761
48762 /* NOTE requirements on root-hub callers (usbfs and the hub
48763@@ -1579,7 +1579,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
48764 urb->hcpriv = NULL;
48765 INIT_LIST_HEAD(&urb->urb_list);
48766 atomic_dec(&urb->use_count);
48767- atomic_dec(&urb->dev->urbnum);
48768+ atomic_dec_unchecked(&urb->dev->urbnum);
48769 if (atomic_read(&urb->reject))
48770 wake_up(&usb_kill_urb_queue);
48771 usb_put_urb(urb);
48772diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
48773index 879651c..87e0131 100644
48774--- a/drivers/usb/core/hub.c
48775+++ b/drivers/usb/core/hub.c
48776@@ -27,6 +27,7 @@
48777 #include <linux/freezer.h>
48778 #include <linux/random.h>
48779 #include <linux/pm_qos.h>
48780+#include <linux/grsecurity.h>
48781
48782 #include <asm/uaccess.h>
48783 #include <asm/byteorder.h>
48784@@ -4435,6 +4436,10 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1,
48785 goto done;
48786 return;
48787 }
48788+
48789+ if (gr_handle_new_usb())
48790+ goto done;
48791+
48792 if (hub_is_superspeed(hub->hdev))
48793 unit_load = 150;
48794 else
48795diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
48796index 82927e1..4993dbf 100644
48797--- a/drivers/usb/core/message.c
48798+++ b/drivers/usb/core/message.c
48799@@ -129,7 +129,7 @@ static int usb_internal_control_msg(struct usb_device *usb_dev,
48800 * Return: If successful, the number of bytes transferred. Otherwise, a negative
48801 * error number.
48802 */
48803-int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
48804+int __intentional_overflow(-1) usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
48805 __u8 requesttype, __u16 value, __u16 index, void *data,
48806 __u16 size, int timeout)
48807 {
48808@@ -181,7 +181,7 @@ EXPORT_SYMBOL_GPL(usb_control_msg);
48809 * If successful, 0. Otherwise a negative error number. The number of actual
48810 * bytes transferred will be stored in the @actual_length paramater.
48811 */
48812-int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
48813+int __intentional_overflow(-1) usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
48814 void *data, int len, int *actual_length, int timeout)
48815 {
48816 return usb_bulk_msg(usb_dev, pipe, data, len, actual_length, timeout);
48817@@ -221,7 +221,7 @@ EXPORT_SYMBOL_GPL(usb_interrupt_msg);
48818 * bytes transferred will be stored in the @actual_length paramater.
48819 *
48820 */
48821-int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
48822+int __intentional_overflow(-1) usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
48823 void *data, int len, int *actual_length, int timeout)
48824 {
48825 struct urb *urb;
48826diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
48827index 6d2c8ed..3a794ca 100644
48828--- a/drivers/usb/core/sysfs.c
48829+++ b/drivers/usb/core/sysfs.c
48830@@ -236,7 +236,7 @@ static ssize_t urbnum_show(struct device *dev, struct device_attribute *attr,
48831 struct usb_device *udev;
48832
48833 udev = to_usb_device(dev);
48834- return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
48835+ return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
48836 }
48837 static DEVICE_ATTR_RO(urbnum);
48838
48839diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
48840index 0a6ee2e..6f8d7e8 100644
48841--- a/drivers/usb/core/usb.c
48842+++ b/drivers/usb/core/usb.c
48843@@ -433,7 +433,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
48844 set_dev_node(&dev->dev, dev_to_node(bus->controller));
48845 dev->state = USB_STATE_ATTACHED;
48846 dev->lpm_disable_count = 1;
48847- atomic_set(&dev->urbnum, 0);
48848+ atomic_set_unchecked(&dev->urbnum, 0);
48849
48850 INIT_LIST_HEAD(&dev->ep0.urb_list);
48851 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
48852diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
48853index 5452c0f..34c9145 100644
48854--- a/drivers/usb/dwc3/gadget.c
48855+++ b/drivers/usb/dwc3/gadget.c
48856@@ -532,8 +532,6 @@ static int __dwc3_gadget_ep_enable(struct dwc3_ep *dep,
48857 if (!usb_endpoint_xfer_isoc(desc))
48858 return 0;
48859
48860- memset(&trb_link, 0, sizeof(trb_link));
48861-
48862 /* Link TRB for ISOC. The HWO bit is never reset */
48863 trb_st_hw = &dep->trb_pool[0];
48864
48865diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
48866index 5e29dde..eca992f 100644
48867--- a/drivers/usb/early/ehci-dbgp.c
48868+++ b/drivers/usb/early/ehci-dbgp.c
48869@@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
48870
48871 #ifdef CONFIG_KGDB
48872 static struct kgdb_io kgdbdbgp_io_ops;
48873-#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
48874+static struct kgdb_io kgdbdbgp_io_ops_console;
48875+#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
48876 #else
48877 #define dbgp_kgdb_mode (0)
48878 #endif
48879@@ -1047,6 +1048,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
48880 .write_char = kgdbdbgp_write_char,
48881 };
48882
48883+static struct kgdb_io kgdbdbgp_io_ops_console = {
48884+ .name = "kgdbdbgp",
48885+ .read_char = kgdbdbgp_read_char,
48886+ .write_char = kgdbdbgp_write_char,
48887+ .is_console = 1
48888+};
48889+
48890 static int kgdbdbgp_wait_time;
48891
48892 static int __init kgdbdbgp_parse_config(char *str)
48893@@ -1062,8 +1070,10 @@ static int __init kgdbdbgp_parse_config(char *str)
48894 ptr++;
48895 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
48896 }
48897- kgdb_register_io_module(&kgdbdbgp_io_ops);
48898- kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
48899+ if (early_dbgp_console.index != -1)
48900+ kgdb_register_io_module(&kgdbdbgp_io_ops_console);
48901+ else
48902+ kgdb_register_io_module(&kgdbdbgp_io_ops);
48903
48904 return 0;
48905 }
48906diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
48907index b369292..9f3ba40 100644
48908--- a/drivers/usb/gadget/u_serial.c
48909+++ b/drivers/usb/gadget/u_serial.c
48910@@ -733,9 +733,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
48911 spin_lock_irq(&port->port_lock);
48912
48913 /* already open? Great. */
48914- if (port->port.count) {
48915+ if (atomic_read(&port->port.count)) {
48916 status = 0;
48917- port->port.count++;
48918+ atomic_inc(&port->port.count);
48919
48920 /* currently opening/closing? wait ... */
48921 } else if (port->openclose) {
48922@@ -794,7 +794,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
48923 tty->driver_data = port;
48924 port->port.tty = tty;
48925
48926- port->port.count = 1;
48927+ atomic_set(&port->port.count, 1);
48928 port->openclose = false;
48929
48930 /* if connected, start the I/O stream */
48931@@ -836,11 +836,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
48932
48933 spin_lock_irq(&port->port_lock);
48934
48935- if (port->port.count != 1) {
48936- if (port->port.count == 0)
48937+ if (atomic_read(&port->port.count) != 1) {
48938+ if (atomic_read(&port->port.count) == 0)
48939 WARN_ON(1);
48940 else
48941- --port->port.count;
48942+ atomic_dec(&port->port.count);
48943 goto exit;
48944 }
48945
48946@@ -850,7 +850,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
48947 * and sleep if necessary
48948 */
48949 port->openclose = true;
48950- port->port.count = 0;
48951+ atomic_set(&port->port.count, 0);
48952
48953 gser = port->port_usb;
48954 if (gser && gser->disconnect)
48955@@ -1066,7 +1066,7 @@ static int gs_closed(struct gs_port *port)
48956 int cond;
48957
48958 spin_lock_irq(&port->port_lock);
48959- cond = (port->port.count == 0) && !port->openclose;
48960+ cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
48961 spin_unlock_irq(&port->port_lock);
48962 return cond;
48963 }
48964@@ -1209,7 +1209,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
48965 /* if it's already open, start I/O ... and notify the serial
48966 * protocol about open/close status (connect/disconnect).
48967 */
48968- if (port->port.count) {
48969+ if (atomic_read(&port->port.count)) {
48970 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
48971 gs_start_io(port);
48972 if (gser->connect)
48973@@ -1256,7 +1256,7 @@ void gserial_disconnect(struct gserial *gser)
48974
48975 port->port_usb = NULL;
48976 gser->ioport = NULL;
48977- if (port->port.count > 0 || port->openclose) {
48978+ if (atomic_read(&port->port.count) > 0 || port->openclose) {
48979 wake_up_interruptible(&port->drain_wait);
48980 if (port->port.tty)
48981 tty_hangup(port->port.tty);
48982@@ -1272,7 +1272,7 @@ void gserial_disconnect(struct gserial *gser)
48983
48984 /* finally, free any unused/unusable I/O buffers */
48985 spin_lock_irqsave(&port->port_lock, flags);
48986- if (port->port.count == 0 && !port->openclose)
48987+ if (atomic_read(&port->port.count) == 0 && !port->openclose)
48988 gs_buf_free(&port->port_write_buf);
48989 gs_free_requests(gser->out, &port->read_pool, NULL);
48990 gs_free_requests(gser->out, &port->read_queue, NULL);
48991diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c
48992index 835fc08..f8b22bf 100644
48993--- a/drivers/usb/host/ehci-hub.c
48994+++ b/drivers/usb/host/ehci-hub.c
48995@@ -762,7 +762,7 @@ static struct urb *request_single_step_set_feature_urb(
48996 urb->transfer_flags = URB_DIR_IN;
48997 usb_get_urb(urb);
48998 atomic_inc(&urb->use_count);
48999- atomic_inc(&urb->dev->urbnum);
49000+ atomic_inc_unchecked(&urb->dev->urbnum);
49001 urb->setup_dma = dma_map_single(
49002 hcd->self.controller,
49003 urb->setup_packet,
49004@@ -829,7 +829,7 @@ static int ehset_single_step_set_feature(struct usb_hcd *hcd, int port)
49005 urb->status = -EINPROGRESS;
49006 usb_get_urb(urb);
49007 atomic_inc(&urb->use_count);
49008- atomic_inc(&urb->dev->urbnum);
49009+ atomic_inc_unchecked(&urb->dev->urbnum);
49010 retval = submit_single_step_set_feature(hcd, urb, 0);
49011 if (!retval && !wait_for_completion_timeout(&done,
49012 msecs_to_jiffies(2000))) {
49013diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c
49014index ba6a5d6..f88f7f3 100644
49015--- a/drivers/usb/misc/appledisplay.c
49016+++ b/drivers/usb/misc/appledisplay.c
49017@@ -83,7 +83,7 @@ struct appledisplay {
49018 spinlock_t lock;
49019 };
49020
49021-static atomic_t count_displays = ATOMIC_INIT(0);
49022+static atomic_unchecked_t count_displays = ATOMIC_INIT(0);
49023 static struct workqueue_struct *wq;
49024
49025 static void appledisplay_complete(struct urb *urb)
49026@@ -281,7 +281,7 @@ static int appledisplay_probe(struct usb_interface *iface,
49027
49028 /* Register backlight device */
49029 snprintf(bl_name, sizeof(bl_name), "appledisplay%d",
49030- atomic_inc_return(&count_displays) - 1);
49031+ atomic_inc_return_unchecked(&count_displays) - 1);
49032 memset(&props, 0, sizeof(struct backlight_properties));
49033 props.type = BACKLIGHT_RAW;
49034 props.max_brightness = 0xff;
49035diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
49036index c69bb50..215ef37 100644
49037--- a/drivers/usb/serial/console.c
49038+++ b/drivers/usb/serial/console.c
49039@@ -124,7 +124,7 @@ static int usb_console_setup(struct console *co, char *options)
49040
49041 info->port = port;
49042
49043- ++port->port.count;
49044+ atomic_inc(&port->port.count);
49045 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
49046 if (serial->type->set_termios) {
49047 /*
49048@@ -170,7 +170,7 @@ static int usb_console_setup(struct console *co, char *options)
49049 }
49050 /* Now that any required fake tty operations are completed restore
49051 * the tty port count */
49052- --port->port.count;
49053+ atomic_dec(&port->port.count);
49054 /* The console is special in terms of closing the device so
49055 * indicate this port is now acting as a system console. */
49056 port->port.console = 1;
49057@@ -183,7 +183,7 @@ static int usb_console_setup(struct console *co, char *options)
49058 free_tty:
49059 kfree(tty);
49060 reset_open_count:
49061- port->port.count = 0;
49062+ atomic_set(&port->port.count, 0);
49063 usb_autopm_put_interface(serial->interface);
49064 error_get_interface:
49065 usb_serial_put(serial);
49066@@ -194,7 +194,7 @@ static int usb_console_setup(struct console *co, char *options)
49067 static void usb_console_write(struct console *co,
49068 const char *buf, unsigned count)
49069 {
49070- static struct usbcons_info *info = &usbcons_info;
49071+ struct usbcons_info *info = &usbcons_info;
49072 struct usb_serial_port *port = info->port;
49073 struct usb_serial *serial;
49074 int retval = -ENODEV;
49075diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
49076index 75f70f0..d467e1a 100644
49077--- a/drivers/usb/storage/usb.h
49078+++ b/drivers/usb/storage/usb.h
49079@@ -63,7 +63,7 @@ struct us_unusual_dev {
49080 __u8 useProtocol;
49081 __u8 useTransport;
49082 int (*initFunction)(struct us_data *);
49083-};
49084+} __do_const;
49085
49086
49087 /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
49088diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
49089index cf250c2..ad9d904 100644
49090--- a/drivers/usb/wusbcore/wa-hc.h
49091+++ b/drivers/usb/wusbcore/wa-hc.h
49092@@ -199,7 +199,7 @@ struct wahc {
49093 spinlock_t xfer_list_lock;
49094 struct work_struct xfer_enqueue_work;
49095 struct work_struct xfer_error_work;
49096- atomic_t xfer_id_count;
49097+ atomic_unchecked_t xfer_id_count;
49098 };
49099
49100
49101@@ -255,7 +255,7 @@ static inline void wa_init(struct wahc *wa)
49102 spin_lock_init(&wa->xfer_list_lock);
49103 INIT_WORK(&wa->xfer_enqueue_work, wa_urb_enqueue_run);
49104 INIT_WORK(&wa->xfer_error_work, wa_process_errored_transfers_run);
49105- atomic_set(&wa->xfer_id_count, 1);
49106+ atomic_set_unchecked(&wa->xfer_id_count, 1);
49107 }
49108
49109 /**
49110diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
49111index 6ad02f5..cc52c8b 100644
49112--- a/drivers/usb/wusbcore/wa-xfer.c
49113+++ b/drivers/usb/wusbcore/wa-xfer.c
49114@@ -299,7 +299,7 @@ out:
49115 */
49116 static void wa_xfer_id_init(struct wa_xfer *xfer)
49117 {
49118- xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
49119+ xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
49120 }
49121
49122 /*
49123diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
49124index 1eab4ac..e21efc9 100644
49125--- a/drivers/vfio/vfio.c
49126+++ b/drivers/vfio/vfio.c
49127@@ -488,7 +488,7 @@ static int vfio_group_nb_add_dev(struct vfio_group *group, struct device *dev)
49128 return 0;
49129
49130 /* TODO Prevent device auto probing */
49131- WARN("Device %s added to live group %d!\n", dev_name(dev),
49132+ WARN(1, "Device %s added to live group %d!\n", dev_name(dev),
49133 iommu_group_id(group->iommu_group));
49134
49135 return 0;
49136diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c
49137index 5174eba..86e764a 100644
49138--- a/drivers/vhost/vringh.c
49139+++ b/drivers/vhost/vringh.c
49140@@ -800,7 +800,7 @@ static inline int getu16_kern(u16 *val, const u16 *p)
49141
49142 static inline int putu16_kern(u16 *p, u16 val)
49143 {
49144- ACCESS_ONCE(*p) = val;
49145+ ACCESS_ONCE_RW(*p) = val;
49146 return 0;
49147 }
49148
49149diff --git a/drivers/video/arcfb.c b/drivers/video/arcfb.c
49150index e43401a..dd49b3f 100644
49151--- a/drivers/video/arcfb.c
49152+++ b/drivers/video/arcfb.c
49153@@ -458,7 +458,7 @@ static ssize_t arcfb_write(struct fb_info *info, const char __user *buf,
49154 return -ENOSPC;
49155
49156 err = 0;
49157- if ((count + p) > fbmemlength) {
49158+ if (count > (fbmemlength - p)) {
49159 count = fbmemlength - p;
49160 err = -ENOSPC;
49161 }
49162diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
49163index a4dfe8c..297ddd9 100644
49164--- a/drivers/video/aty/aty128fb.c
49165+++ b/drivers/video/aty/aty128fb.c
49166@@ -149,7 +149,7 @@ enum {
49167 };
49168
49169 /* Must match above enum */
49170-static char * const r128_family[] = {
49171+static const char * const r128_family[] = {
49172 "AGP",
49173 "PCI",
49174 "PRO AGP",
49175diff --git a/drivers/video/aty/atyfb_base.c b/drivers/video/aty/atyfb_base.c
49176index 9b0f12c..024673d 100644
49177--- a/drivers/video/aty/atyfb_base.c
49178+++ b/drivers/video/aty/atyfb_base.c
49179@@ -1326,10 +1326,14 @@ static int atyfb_set_par(struct fb_info *info)
49180 par->accel_flags = var->accel_flags; /* hack */
49181
49182 if (var->accel_flags) {
49183- info->fbops->fb_sync = atyfb_sync;
49184+ pax_open_kernel();
49185+ *(void **)&info->fbops->fb_sync = atyfb_sync;
49186+ pax_close_kernel();
49187 info->flags &= ~FBINFO_HWACCEL_DISABLED;
49188 } else {
49189- info->fbops->fb_sync = NULL;
49190+ pax_open_kernel();
49191+ *(void **)&info->fbops->fb_sync = NULL;
49192+ pax_close_kernel();
49193 info->flags |= FBINFO_HWACCEL_DISABLED;
49194 }
49195
49196diff --git a/drivers/video/aty/mach64_cursor.c b/drivers/video/aty/mach64_cursor.c
49197index 95ec042..e6affdd 100644
49198--- a/drivers/video/aty/mach64_cursor.c
49199+++ b/drivers/video/aty/mach64_cursor.c
49200@@ -7,6 +7,7 @@
49201 #include <linux/string.h>
49202
49203 #include <asm/io.h>
49204+#include <asm/pgtable.h>
49205
49206 #ifdef __sparc__
49207 #include <asm/fbio.h>
49208@@ -208,7 +209,9 @@ int aty_init_cursor(struct fb_info *info)
49209 info->sprite.buf_align = 16; /* and 64 lines tall. */
49210 info->sprite.flags = FB_PIXMAP_IO;
49211
49212- info->fbops->fb_cursor = atyfb_cursor;
49213+ pax_open_kernel();
49214+ *(void **)&info->fbops->fb_cursor = atyfb_cursor;
49215+ pax_close_kernel();
49216
49217 return 0;
49218 }
49219diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
49220index bca6ccc..252107e 100644
49221--- a/drivers/video/backlight/kb3886_bl.c
49222+++ b/drivers/video/backlight/kb3886_bl.c
49223@@ -78,7 +78,7 @@ static struct kb3886bl_machinfo *bl_machinfo;
49224 static unsigned long kb3886bl_flags;
49225 #define KB3886BL_SUSPENDED 0x01
49226
49227-static struct dmi_system_id __initdata kb3886bl_device_table[] = {
49228+static const struct dmi_system_id __initconst kb3886bl_device_table[] = {
49229 {
49230 .ident = "Sahara Touch-iT",
49231 .matches = {
49232diff --git a/drivers/video/fb_defio.c b/drivers/video/fb_defio.c
49233index 900aa4e..6d49418 100644
49234--- a/drivers/video/fb_defio.c
49235+++ b/drivers/video/fb_defio.c
49236@@ -206,7 +206,9 @@ void fb_deferred_io_init(struct fb_info *info)
49237
49238 BUG_ON(!fbdefio);
49239 mutex_init(&fbdefio->lock);
49240- info->fbops->fb_mmap = fb_deferred_io_mmap;
49241+ pax_open_kernel();
49242+ *(void **)&info->fbops->fb_mmap = fb_deferred_io_mmap;
49243+ pax_close_kernel();
49244 INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work);
49245 INIT_LIST_HEAD(&fbdefio->pagelist);
49246 if (fbdefio->delay == 0) /* set a default of 1 s */
49247@@ -237,7 +239,7 @@ void fb_deferred_io_cleanup(struct fb_info *info)
49248 page->mapping = NULL;
49249 }
49250
49251- info->fbops->fb_mmap = NULL;
49252+ *(void **)&info->fbops->fb_mmap = NULL;
49253 mutex_destroy(&fbdefio->lock);
49254 }
49255 EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup);
49256diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
49257index dacaf74..8478a46 100644
49258--- a/drivers/video/fbmem.c
49259+++ b/drivers/video/fbmem.c
49260@@ -433,7 +433,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
49261 image->dx += image->width + 8;
49262 }
49263 } else if (rotate == FB_ROTATE_UD) {
49264- for (x = 0; x < num && image->dx >= 0; x++) {
49265+ for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
49266 info->fbops->fb_imageblit(info, image);
49267 image->dx -= image->width + 8;
49268 }
49269@@ -445,7 +445,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
49270 image->dy += image->height + 8;
49271 }
49272 } else if (rotate == FB_ROTATE_CCW) {
49273- for (x = 0; x < num && image->dy >= 0; x++) {
49274+ for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
49275 info->fbops->fb_imageblit(info, image);
49276 image->dy -= image->height + 8;
49277 }
49278@@ -1175,7 +1175,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
49279 return -EFAULT;
49280 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
49281 return -EINVAL;
49282- if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
49283+ if (con2fb.framebuffer >= FB_MAX)
49284 return -EINVAL;
49285 if (!registered_fb[con2fb.framebuffer])
49286 request_module("fb%d", con2fb.framebuffer);
49287diff --git a/drivers/video/hyperv_fb.c b/drivers/video/hyperv_fb.c
49288index 8d456dc..b4fa44b 100644
49289--- a/drivers/video/hyperv_fb.c
49290+++ b/drivers/video/hyperv_fb.c
49291@@ -233,7 +233,7 @@ static uint screen_fb_size;
49292 static inline int synthvid_send(struct hv_device *hdev,
49293 struct synthvid_msg *msg)
49294 {
49295- static atomic64_t request_id = ATOMIC64_INIT(0);
49296+ static atomic64_unchecked_t request_id = ATOMIC64_INIT(0);
49297 int ret;
49298
49299 msg->pipe_hdr.type = PIPE_MSG_DATA;
49300@@ -241,7 +241,7 @@ static inline int synthvid_send(struct hv_device *hdev,
49301
49302 ret = vmbus_sendpacket(hdev->channel, msg,
49303 msg->vid_hdr.size + sizeof(struct pipe_msg_hdr),
49304- atomic64_inc_return(&request_id),
49305+ atomic64_inc_return_unchecked(&request_id),
49306 VM_PKT_DATA_INBAND, 0);
49307
49308 if (ret)
49309diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
49310index 7672d2e..b56437f 100644
49311--- a/drivers/video/i810/i810_accel.c
49312+++ b/drivers/video/i810/i810_accel.c
49313@@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
49314 }
49315 }
49316 printk("ringbuffer lockup!!!\n");
49317+ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
49318 i810_report_error(mmio);
49319 par->dev_flags |= LOCKUP;
49320 info->pixmap.scan_align = 1;
49321diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
49322index 3c14e43..2630570 100644
49323--- a/drivers/video/logo/logo_linux_clut224.ppm
49324+++ b/drivers/video/logo/logo_linux_clut224.ppm
49325@@ -2,1603 +2,1123 @@ P3
49326 # Standard 224-color Linux logo
49327 80 80
49328 255
49329- 0 0 0 0 0 0 0 0 0 0 0 0
49330- 0 0 0 0 0 0 0 0 0 0 0 0
49331- 0 0 0 0 0 0 0 0 0 0 0 0
49332- 0 0 0 0 0 0 0 0 0 0 0 0
49333- 0 0 0 0 0 0 0 0 0 0 0 0
49334- 0 0 0 0 0 0 0 0 0 0 0 0
49335- 0 0 0 0 0 0 0 0 0 0 0 0
49336- 0 0 0 0 0 0 0 0 0 0 0 0
49337- 0 0 0 0 0 0 0 0 0 0 0 0
49338- 6 6 6 6 6 6 10 10 10 10 10 10
49339- 10 10 10 6 6 6 6 6 6 6 6 6
49340- 0 0 0 0 0 0 0 0 0 0 0 0
49341- 0 0 0 0 0 0 0 0 0 0 0 0
49342- 0 0 0 0 0 0 0 0 0 0 0 0
49343- 0 0 0 0 0 0 0 0 0 0 0 0
49344- 0 0 0 0 0 0 0 0 0 0 0 0
49345- 0 0 0 0 0 0 0 0 0 0 0 0
49346- 0 0 0 0 0 0 0 0 0 0 0 0
49347- 0 0 0 0 0 0 0 0 0 0 0 0
49348- 0 0 0 0 0 0 0 0 0 0 0 0
49349- 0 0 0 0 0 0 0 0 0 0 0 0
49350- 0 0 0 0 0 0 0 0 0 0 0 0
49351- 0 0 0 0 0 0 0 0 0 0 0 0
49352- 0 0 0 0 0 0 0 0 0 0 0 0
49353- 0 0 0 0 0 0 0 0 0 0 0 0
49354- 0 0 0 0 0 0 0 0 0 0 0 0
49355- 0 0 0 0 0 0 0 0 0 0 0 0
49356- 0 0 0 0 0 0 0 0 0 0 0 0
49357- 0 0 0 6 6 6 10 10 10 14 14 14
49358- 22 22 22 26 26 26 30 30 30 34 34 34
49359- 30 30 30 30 30 30 26 26 26 18 18 18
49360- 14 14 14 10 10 10 6 6 6 0 0 0
49361- 0 0 0 0 0 0 0 0 0 0 0 0
49362- 0 0 0 0 0 0 0 0 0 0 0 0
49363- 0 0 0 0 0 0 0 0 0 0 0 0
49364- 0 0 0 0 0 0 0 0 0 0 0 0
49365- 0 0 0 0 0 0 0 0 0 0 0 0
49366- 0 0 0 0 0 0 0 0 0 0 0 0
49367- 0 0 0 0 0 0 0 0 0 0 0 0
49368- 0 0 0 0 0 0 0 0 0 0 0 0
49369- 0 0 0 0 0 0 0 0 0 0 0 0
49370- 0 0 0 0 0 1 0 0 1 0 0 0
49371- 0 0 0 0 0 0 0 0 0 0 0 0
49372- 0 0 0 0 0 0 0 0 0 0 0 0
49373- 0 0 0 0 0 0 0 0 0 0 0 0
49374- 0 0 0 0 0 0 0 0 0 0 0 0
49375- 0 0 0 0 0 0 0 0 0 0 0 0
49376- 0 0 0 0 0 0 0 0 0 0 0 0
49377- 6 6 6 14 14 14 26 26 26 42 42 42
49378- 54 54 54 66 66 66 78 78 78 78 78 78
49379- 78 78 78 74 74 74 66 66 66 54 54 54
49380- 42 42 42 26 26 26 18 18 18 10 10 10
49381- 6 6 6 0 0 0 0 0 0 0 0 0
49382- 0 0 0 0 0 0 0 0 0 0 0 0
49383- 0 0 0 0 0 0 0 0 0 0 0 0
49384- 0 0 0 0 0 0 0 0 0 0 0 0
49385- 0 0 0 0 0 0 0 0 0 0 0 0
49386- 0 0 0 0 0 0 0 0 0 0 0 0
49387- 0 0 0 0 0 0 0 0 0 0 0 0
49388- 0 0 0 0 0 0 0 0 0 0 0 0
49389- 0 0 0 0 0 0 0 0 0 0 0 0
49390- 0 0 1 0 0 0 0 0 0 0 0 0
49391- 0 0 0 0 0 0 0 0 0 0 0 0
49392- 0 0 0 0 0 0 0 0 0 0 0 0
49393- 0 0 0 0 0 0 0 0 0 0 0 0
49394- 0 0 0 0 0 0 0 0 0 0 0 0
49395- 0 0 0 0 0 0 0 0 0 0 0 0
49396- 0 0 0 0 0 0 0 0 0 10 10 10
49397- 22 22 22 42 42 42 66 66 66 86 86 86
49398- 66 66 66 38 38 38 38 38 38 22 22 22
49399- 26 26 26 34 34 34 54 54 54 66 66 66
49400- 86 86 86 70 70 70 46 46 46 26 26 26
49401- 14 14 14 6 6 6 0 0 0 0 0 0
49402- 0 0 0 0 0 0 0 0 0 0 0 0
49403- 0 0 0 0 0 0 0 0 0 0 0 0
49404- 0 0 0 0 0 0 0 0 0 0 0 0
49405- 0 0 0 0 0 0 0 0 0 0 0 0
49406- 0 0 0 0 0 0 0 0 0 0 0 0
49407- 0 0 0 0 0 0 0 0 0 0 0 0
49408- 0 0 0 0 0 0 0 0 0 0 0 0
49409- 0 0 0 0 0 0 0 0 0 0 0 0
49410- 0 0 1 0 0 1 0 0 1 0 0 0
49411- 0 0 0 0 0 0 0 0 0 0 0 0
49412- 0 0 0 0 0 0 0 0 0 0 0 0
49413- 0 0 0 0 0 0 0 0 0 0 0 0
49414- 0 0 0 0 0 0 0 0 0 0 0 0
49415- 0 0 0 0 0 0 0 0 0 0 0 0
49416- 0 0 0 0 0 0 10 10 10 26 26 26
49417- 50 50 50 82 82 82 58 58 58 6 6 6
49418- 2 2 6 2 2 6 2 2 6 2 2 6
49419- 2 2 6 2 2 6 2 2 6 2 2 6
49420- 6 6 6 54 54 54 86 86 86 66 66 66
49421- 38 38 38 18 18 18 6 6 6 0 0 0
49422- 0 0 0 0 0 0 0 0 0 0 0 0
49423- 0 0 0 0 0 0 0 0 0 0 0 0
49424- 0 0 0 0 0 0 0 0 0 0 0 0
49425- 0 0 0 0 0 0 0 0 0 0 0 0
49426- 0 0 0 0 0 0 0 0 0 0 0 0
49427- 0 0 0 0 0 0 0 0 0 0 0 0
49428- 0 0 0 0 0 0 0 0 0 0 0 0
49429- 0 0 0 0 0 0 0 0 0 0 0 0
49430- 0 0 0 0 0 0 0 0 0 0 0 0
49431- 0 0 0 0 0 0 0 0 0 0 0 0
49432- 0 0 0 0 0 0 0 0 0 0 0 0
49433- 0 0 0 0 0 0 0 0 0 0 0 0
49434- 0 0 0 0 0 0 0 0 0 0 0 0
49435- 0 0 0 0 0 0 0 0 0 0 0 0
49436- 0 0 0 6 6 6 22 22 22 50 50 50
49437- 78 78 78 34 34 34 2 2 6 2 2 6
49438- 2 2 6 2 2 6 2 2 6 2 2 6
49439- 2 2 6 2 2 6 2 2 6 2 2 6
49440- 2 2 6 2 2 6 6 6 6 70 70 70
49441- 78 78 78 46 46 46 22 22 22 6 6 6
49442- 0 0 0 0 0 0 0 0 0 0 0 0
49443- 0 0 0 0 0 0 0 0 0 0 0 0
49444- 0 0 0 0 0 0 0 0 0 0 0 0
49445- 0 0 0 0 0 0 0 0 0 0 0 0
49446- 0 0 0 0 0 0 0 0 0 0 0 0
49447- 0 0 0 0 0 0 0 0 0 0 0 0
49448- 0 0 0 0 0 0 0 0 0 0 0 0
49449- 0 0 0 0 0 0 0 0 0 0 0 0
49450- 0 0 1 0 0 1 0 0 1 0 0 0
49451- 0 0 0 0 0 0 0 0 0 0 0 0
49452- 0 0 0 0 0 0 0 0 0 0 0 0
49453- 0 0 0 0 0 0 0 0 0 0 0 0
49454- 0 0 0 0 0 0 0 0 0 0 0 0
49455- 0 0 0 0 0 0 0 0 0 0 0 0
49456- 6 6 6 18 18 18 42 42 42 82 82 82
49457- 26 26 26 2 2 6 2 2 6 2 2 6
49458- 2 2 6 2 2 6 2 2 6 2 2 6
49459- 2 2 6 2 2 6 2 2 6 14 14 14
49460- 46 46 46 34 34 34 6 6 6 2 2 6
49461- 42 42 42 78 78 78 42 42 42 18 18 18
49462- 6 6 6 0 0 0 0 0 0 0 0 0
49463- 0 0 0 0 0 0 0 0 0 0 0 0
49464- 0 0 0 0 0 0 0 0 0 0 0 0
49465- 0 0 0 0 0 0 0 0 0 0 0 0
49466- 0 0 0 0 0 0 0 0 0 0 0 0
49467- 0 0 0 0 0 0 0 0 0 0 0 0
49468- 0 0 0 0 0 0 0 0 0 0 0 0
49469- 0 0 0 0 0 0 0 0 0 0 0 0
49470- 0 0 1 0 0 0 0 0 1 0 0 0
49471- 0 0 0 0 0 0 0 0 0 0 0 0
49472- 0 0 0 0 0 0 0 0 0 0 0 0
49473- 0 0 0 0 0 0 0 0 0 0 0 0
49474- 0 0 0 0 0 0 0 0 0 0 0 0
49475- 0 0 0 0 0 0 0 0 0 0 0 0
49476- 10 10 10 30 30 30 66 66 66 58 58 58
49477- 2 2 6 2 2 6 2 2 6 2 2 6
49478- 2 2 6 2 2 6 2 2 6 2 2 6
49479- 2 2 6 2 2 6 2 2 6 26 26 26
49480- 86 86 86 101 101 101 46 46 46 10 10 10
49481- 2 2 6 58 58 58 70 70 70 34 34 34
49482- 10 10 10 0 0 0 0 0 0 0 0 0
49483- 0 0 0 0 0 0 0 0 0 0 0 0
49484- 0 0 0 0 0 0 0 0 0 0 0 0
49485- 0 0 0 0 0 0 0 0 0 0 0 0
49486- 0 0 0 0 0 0 0 0 0 0 0 0
49487- 0 0 0 0 0 0 0 0 0 0 0 0
49488- 0 0 0 0 0 0 0 0 0 0 0 0
49489- 0 0 0 0 0 0 0 0 0 0 0 0
49490- 0 0 1 0 0 1 0 0 1 0 0 0
49491- 0 0 0 0 0 0 0 0 0 0 0 0
49492- 0 0 0 0 0 0 0 0 0 0 0 0
49493- 0 0 0 0 0 0 0 0 0 0 0 0
49494- 0 0 0 0 0 0 0 0 0 0 0 0
49495- 0 0 0 0 0 0 0 0 0 0 0 0
49496- 14 14 14 42 42 42 86 86 86 10 10 10
49497- 2 2 6 2 2 6 2 2 6 2 2 6
49498- 2 2 6 2 2 6 2 2 6 2 2 6
49499- 2 2 6 2 2 6 2 2 6 30 30 30
49500- 94 94 94 94 94 94 58 58 58 26 26 26
49501- 2 2 6 6 6 6 78 78 78 54 54 54
49502- 22 22 22 6 6 6 0 0 0 0 0 0
49503- 0 0 0 0 0 0 0 0 0 0 0 0
49504- 0 0 0 0 0 0 0 0 0 0 0 0
49505- 0 0 0 0 0 0 0 0 0 0 0 0
49506- 0 0 0 0 0 0 0 0 0 0 0 0
49507- 0 0 0 0 0 0 0 0 0 0 0 0
49508- 0 0 0 0 0 0 0 0 0 0 0 0
49509- 0 0 0 0 0 0 0 0 0 0 0 0
49510- 0 0 0 0 0 0 0 0 0 0 0 0
49511- 0 0 0 0 0 0 0 0 0 0 0 0
49512- 0 0 0 0 0 0 0 0 0 0 0 0
49513- 0 0 0 0 0 0 0 0 0 0 0 0
49514- 0 0 0 0 0 0 0 0 0 0 0 0
49515- 0 0 0 0 0 0 0 0 0 6 6 6
49516- 22 22 22 62 62 62 62 62 62 2 2 6
49517- 2 2 6 2 2 6 2 2 6 2 2 6
49518- 2 2 6 2 2 6 2 2 6 2 2 6
49519- 2 2 6 2 2 6 2 2 6 26 26 26
49520- 54 54 54 38 38 38 18 18 18 10 10 10
49521- 2 2 6 2 2 6 34 34 34 82 82 82
49522- 38 38 38 14 14 14 0 0 0 0 0 0
49523- 0 0 0 0 0 0 0 0 0 0 0 0
49524- 0 0 0 0 0 0 0 0 0 0 0 0
49525- 0 0 0 0 0 0 0 0 0 0 0 0
49526- 0 0 0 0 0 0 0 0 0 0 0 0
49527- 0 0 0 0 0 0 0 0 0 0 0 0
49528- 0 0 0 0 0 0 0 0 0 0 0 0
49529- 0 0 0 0 0 0 0 0 0 0 0 0
49530- 0 0 0 0 0 1 0 0 1 0 0 0
49531- 0 0 0 0 0 0 0 0 0 0 0 0
49532- 0 0 0 0 0 0 0 0 0 0 0 0
49533- 0 0 0 0 0 0 0 0 0 0 0 0
49534- 0 0 0 0 0 0 0 0 0 0 0 0
49535- 0 0 0 0 0 0 0 0 0 6 6 6
49536- 30 30 30 78 78 78 30 30 30 2 2 6
49537- 2 2 6 2 2 6 2 2 6 2 2 6
49538- 2 2 6 2 2 6 2 2 6 2 2 6
49539- 2 2 6 2 2 6 2 2 6 10 10 10
49540- 10 10 10 2 2 6 2 2 6 2 2 6
49541- 2 2 6 2 2 6 2 2 6 78 78 78
49542- 50 50 50 18 18 18 6 6 6 0 0 0
49543- 0 0 0 0 0 0 0 0 0 0 0 0
49544- 0 0 0 0 0 0 0 0 0 0 0 0
49545- 0 0 0 0 0 0 0 0 0 0 0 0
49546- 0 0 0 0 0 0 0 0 0 0 0 0
49547- 0 0 0 0 0 0 0 0 0 0 0 0
49548- 0 0 0 0 0 0 0 0 0 0 0 0
49549- 0 0 0 0 0 0 0 0 0 0 0 0
49550- 0 0 1 0 0 0 0 0 0 0 0 0
49551- 0 0 0 0 0 0 0 0 0 0 0 0
49552- 0 0 0 0 0 0 0 0 0 0 0 0
49553- 0 0 0 0 0 0 0 0 0 0 0 0
49554- 0 0 0 0 0 0 0 0 0 0 0 0
49555- 0 0 0 0 0 0 0 0 0 10 10 10
49556- 38 38 38 86 86 86 14 14 14 2 2 6
49557- 2 2 6 2 2 6 2 2 6 2 2 6
49558- 2 2 6 2 2 6 2 2 6 2 2 6
49559- 2 2 6 2 2 6 2 2 6 2 2 6
49560- 2 2 6 2 2 6 2 2 6 2 2 6
49561- 2 2 6 2 2 6 2 2 6 54 54 54
49562- 66 66 66 26 26 26 6 6 6 0 0 0
49563- 0 0 0 0 0 0 0 0 0 0 0 0
49564- 0 0 0 0 0 0 0 0 0 0 0 0
49565- 0 0 0 0 0 0 0 0 0 0 0 0
49566- 0 0 0 0 0 0 0 0 0 0 0 0
49567- 0 0 0 0 0 0 0 0 0 0 0 0
49568- 0 0 0 0 0 0 0 0 0 0 0 0
49569- 0 0 0 0 0 0 0 0 0 0 0 0
49570- 0 0 0 0 0 1 0 0 1 0 0 0
49571- 0 0 0 0 0 0 0 0 0 0 0 0
49572- 0 0 0 0 0 0 0 0 0 0 0 0
49573- 0 0 0 0 0 0 0 0 0 0 0 0
49574- 0 0 0 0 0 0 0 0 0 0 0 0
49575- 0 0 0 0 0 0 0 0 0 14 14 14
49576- 42 42 42 82 82 82 2 2 6 2 2 6
49577- 2 2 6 6 6 6 10 10 10 2 2 6
49578- 2 2 6 2 2 6 2 2 6 2 2 6
49579- 2 2 6 2 2 6 2 2 6 6 6 6
49580- 14 14 14 10 10 10 2 2 6 2 2 6
49581- 2 2 6 2 2 6 2 2 6 18 18 18
49582- 82 82 82 34 34 34 10 10 10 0 0 0
49583- 0 0 0 0 0 0 0 0 0 0 0 0
49584- 0 0 0 0 0 0 0 0 0 0 0 0
49585- 0 0 0 0 0 0 0 0 0 0 0 0
49586- 0 0 0 0 0 0 0 0 0 0 0 0
49587- 0 0 0 0 0 0 0 0 0 0 0 0
49588- 0 0 0 0 0 0 0 0 0 0 0 0
49589- 0 0 0 0 0 0 0 0 0 0 0 0
49590- 0 0 1 0 0 0 0 0 0 0 0 0
49591- 0 0 0 0 0 0 0 0 0 0 0 0
49592- 0 0 0 0 0 0 0 0 0 0 0 0
49593- 0 0 0 0 0 0 0 0 0 0 0 0
49594- 0 0 0 0 0 0 0 0 0 0 0 0
49595- 0 0 0 0 0 0 0 0 0 14 14 14
49596- 46 46 46 86 86 86 2 2 6 2 2 6
49597- 6 6 6 6 6 6 22 22 22 34 34 34
49598- 6 6 6 2 2 6 2 2 6 2 2 6
49599- 2 2 6 2 2 6 18 18 18 34 34 34
49600- 10 10 10 50 50 50 22 22 22 2 2 6
49601- 2 2 6 2 2 6 2 2 6 10 10 10
49602- 86 86 86 42 42 42 14 14 14 0 0 0
49603- 0 0 0 0 0 0 0 0 0 0 0 0
49604- 0 0 0 0 0 0 0 0 0 0 0 0
49605- 0 0 0 0 0 0 0 0 0 0 0 0
49606- 0 0 0 0 0 0 0 0 0 0 0 0
49607- 0 0 0 0 0 0 0 0 0 0 0 0
49608- 0 0 0 0 0 0 0 0 0 0 0 0
49609- 0 0 0 0 0 0 0 0 0 0 0 0
49610- 0 0 1 0 0 1 0 0 1 0 0 0
49611- 0 0 0 0 0 0 0 0 0 0 0 0
49612- 0 0 0 0 0 0 0 0 0 0 0 0
49613- 0 0 0 0 0 0 0 0 0 0 0 0
49614- 0 0 0 0 0 0 0 0 0 0 0 0
49615- 0 0 0 0 0 0 0 0 0 14 14 14
49616- 46 46 46 86 86 86 2 2 6 2 2 6
49617- 38 38 38 116 116 116 94 94 94 22 22 22
49618- 22 22 22 2 2 6 2 2 6 2 2 6
49619- 14 14 14 86 86 86 138 138 138 162 162 162
49620-154 154 154 38 38 38 26 26 26 6 6 6
49621- 2 2 6 2 2 6 2 2 6 2 2 6
49622- 86 86 86 46 46 46 14 14 14 0 0 0
49623- 0 0 0 0 0 0 0 0 0 0 0 0
49624- 0 0 0 0 0 0 0 0 0 0 0 0
49625- 0 0 0 0 0 0 0 0 0 0 0 0
49626- 0 0 0 0 0 0 0 0 0 0 0 0
49627- 0 0 0 0 0 0 0 0 0 0 0 0
49628- 0 0 0 0 0 0 0 0 0 0 0 0
49629- 0 0 0 0 0 0 0 0 0 0 0 0
49630- 0 0 0 0 0 0 0 0 0 0 0 0
49631- 0 0 0 0 0 0 0 0 0 0 0 0
49632- 0 0 0 0 0 0 0 0 0 0 0 0
49633- 0 0 0 0 0 0 0 0 0 0 0 0
49634- 0 0 0 0 0 0 0 0 0 0 0 0
49635- 0 0 0 0 0 0 0 0 0 14 14 14
49636- 46 46 46 86 86 86 2 2 6 14 14 14
49637-134 134 134 198 198 198 195 195 195 116 116 116
49638- 10 10 10 2 2 6 2 2 6 6 6 6
49639-101 98 89 187 187 187 210 210 210 218 218 218
49640-214 214 214 134 134 134 14 14 14 6 6 6
49641- 2 2 6 2 2 6 2 2 6 2 2 6
49642- 86 86 86 50 50 50 18 18 18 6 6 6
49643- 0 0 0 0 0 0 0 0 0 0 0 0
49644- 0 0 0 0 0 0 0 0 0 0 0 0
49645- 0 0 0 0 0 0 0 0 0 0 0 0
49646- 0 0 0 0 0 0 0 0 0 0 0 0
49647- 0 0 0 0 0 0 0 0 0 0 0 0
49648- 0 0 0 0 0 0 0 0 0 0 0 0
49649- 0 0 0 0 0 0 0 0 1 0 0 0
49650- 0 0 1 0 0 1 0 0 1 0 0 0
49651- 0 0 0 0 0 0 0 0 0 0 0 0
49652- 0 0 0 0 0 0 0 0 0 0 0 0
49653- 0 0 0 0 0 0 0 0 0 0 0 0
49654- 0 0 0 0 0 0 0 0 0 0 0 0
49655- 0 0 0 0 0 0 0 0 0 14 14 14
49656- 46 46 46 86 86 86 2 2 6 54 54 54
49657-218 218 218 195 195 195 226 226 226 246 246 246
49658- 58 58 58 2 2 6 2 2 6 30 30 30
49659-210 210 210 253 253 253 174 174 174 123 123 123
49660-221 221 221 234 234 234 74 74 74 2 2 6
49661- 2 2 6 2 2 6 2 2 6 2 2 6
49662- 70 70 70 58 58 58 22 22 22 6 6 6
49663- 0 0 0 0 0 0 0 0 0 0 0 0
49664- 0 0 0 0 0 0 0 0 0 0 0 0
49665- 0 0 0 0 0 0 0 0 0 0 0 0
49666- 0 0 0 0 0 0 0 0 0 0 0 0
49667- 0 0 0 0 0 0 0 0 0 0 0 0
49668- 0 0 0 0 0 0 0 0 0 0 0 0
49669- 0 0 0 0 0 0 0 0 0 0 0 0
49670- 0 0 0 0 0 0 0 0 0 0 0 0
49671- 0 0 0 0 0 0 0 0 0 0 0 0
49672- 0 0 0 0 0 0 0 0 0 0 0 0
49673- 0 0 0 0 0 0 0 0 0 0 0 0
49674- 0 0 0 0 0 0 0 0 0 0 0 0
49675- 0 0 0 0 0 0 0 0 0 14 14 14
49676- 46 46 46 82 82 82 2 2 6 106 106 106
49677-170 170 170 26 26 26 86 86 86 226 226 226
49678-123 123 123 10 10 10 14 14 14 46 46 46
49679-231 231 231 190 190 190 6 6 6 70 70 70
49680- 90 90 90 238 238 238 158 158 158 2 2 6
49681- 2 2 6 2 2 6 2 2 6 2 2 6
49682- 70 70 70 58 58 58 22 22 22 6 6 6
49683- 0 0 0 0 0 0 0 0 0 0 0 0
49684- 0 0 0 0 0 0 0 0 0 0 0 0
49685- 0 0 0 0 0 0 0 0 0 0 0 0
49686- 0 0 0 0 0 0 0 0 0 0 0 0
49687- 0 0 0 0 0 0 0 0 0 0 0 0
49688- 0 0 0 0 0 0 0 0 0 0 0 0
49689- 0 0 0 0 0 0 0 0 1 0 0 0
49690- 0 0 1 0 0 1 0 0 1 0 0 0
49691- 0 0 0 0 0 0 0 0 0 0 0 0
49692- 0 0 0 0 0 0 0 0 0 0 0 0
49693- 0 0 0 0 0 0 0 0 0 0 0 0
49694- 0 0 0 0 0 0 0 0 0 0 0 0
49695- 0 0 0 0 0 0 0 0 0 14 14 14
49696- 42 42 42 86 86 86 6 6 6 116 116 116
49697-106 106 106 6 6 6 70 70 70 149 149 149
49698-128 128 128 18 18 18 38 38 38 54 54 54
49699-221 221 221 106 106 106 2 2 6 14 14 14
49700- 46 46 46 190 190 190 198 198 198 2 2 6
49701- 2 2 6 2 2 6 2 2 6 2 2 6
49702- 74 74 74 62 62 62 22 22 22 6 6 6
49703- 0 0 0 0 0 0 0 0 0 0 0 0
49704- 0 0 0 0 0 0 0 0 0 0 0 0
49705- 0 0 0 0 0 0 0 0 0 0 0 0
49706- 0 0 0 0 0 0 0 0 0 0 0 0
49707- 0 0 0 0 0 0 0 0 0 0 0 0
49708- 0 0 0 0 0 0 0 0 0 0 0 0
49709- 0 0 0 0 0 0 0 0 1 0 0 0
49710- 0 0 1 0 0 0 0 0 1 0 0 0
49711- 0 0 0 0 0 0 0 0 0 0 0 0
49712- 0 0 0 0 0 0 0 0 0 0 0 0
49713- 0 0 0 0 0 0 0 0 0 0 0 0
49714- 0 0 0 0 0 0 0 0 0 0 0 0
49715- 0 0 0 0 0 0 0 0 0 14 14 14
49716- 42 42 42 94 94 94 14 14 14 101 101 101
49717-128 128 128 2 2 6 18 18 18 116 116 116
49718-118 98 46 121 92 8 121 92 8 98 78 10
49719-162 162 162 106 106 106 2 2 6 2 2 6
49720- 2 2 6 195 195 195 195 195 195 6 6 6
49721- 2 2 6 2 2 6 2 2 6 2 2 6
49722- 74 74 74 62 62 62 22 22 22 6 6 6
49723- 0 0 0 0 0 0 0 0 0 0 0 0
49724- 0 0 0 0 0 0 0 0 0 0 0 0
49725- 0 0 0 0 0 0 0 0 0 0 0 0
49726- 0 0 0 0 0 0 0 0 0 0 0 0
49727- 0 0 0 0 0 0 0 0 0 0 0 0
49728- 0 0 0 0 0 0 0 0 0 0 0 0
49729- 0 0 0 0 0 0 0 0 1 0 0 1
49730- 0 0 1 0 0 0 0 0 1 0 0 0
49731- 0 0 0 0 0 0 0 0 0 0 0 0
49732- 0 0 0 0 0 0 0 0 0 0 0 0
49733- 0 0 0 0 0 0 0 0 0 0 0 0
49734- 0 0 0 0 0 0 0 0 0 0 0 0
49735- 0 0 0 0 0 0 0 0 0 10 10 10
49736- 38 38 38 90 90 90 14 14 14 58 58 58
49737-210 210 210 26 26 26 54 38 6 154 114 10
49738-226 170 11 236 186 11 225 175 15 184 144 12
49739-215 174 15 175 146 61 37 26 9 2 2 6
49740- 70 70 70 246 246 246 138 138 138 2 2 6
49741- 2 2 6 2 2 6 2 2 6 2 2 6
49742- 70 70 70 66 66 66 26 26 26 6 6 6
49743- 0 0 0 0 0 0 0 0 0 0 0 0
49744- 0 0 0 0 0 0 0 0 0 0 0 0
49745- 0 0 0 0 0 0 0 0 0 0 0 0
49746- 0 0 0 0 0 0 0 0 0 0 0 0
49747- 0 0 0 0 0 0 0 0 0 0 0 0
49748- 0 0 0 0 0 0 0 0 0 0 0 0
49749- 0 0 0 0 0 0 0 0 0 0 0 0
49750- 0 0 0 0 0 0 0 0 0 0 0 0
49751- 0 0 0 0 0 0 0 0 0 0 0 0
49752- 0 0 0 0 0 0 0 0 0 0 0 0
49753- 0 0 0 0 0 0 0 0 0 0 0 0
49754- 0 0 0 0 0 0 0 0 0 0 0 0
49755- 0 0 0 0 0 0 0 0 0 10 10 10
49756- 38 38 38 86 86 86 14 14 14 10 10 10
49757-195 195 195 188 164 115 192 133 9 225 175 15
49758-239 182 13 234 190 10 232 195 16 232 200 30
49759-245 207 45 241 208 19 232 195 16 184 144 12
49760-218 194 134 211 206 186 42 42 42 2 2 6
49761- 2 2 6 2 2 6 2 2 6 2 2 6
49762- 50 50 50 74 74 74 30 30 30 6 6 6
49763- 0 0 0 0 0 0 0 0 0 0 0 0
49764- 0 0 0 0 0 0 0 0 0 0 0 0
49765- 0 0 0 0 0 0 0 0 0 0 0 0
49766- 0 0 0 0 0 0 0 0 0 0 0 0
49767- 0 0 0 0 0 0 0 0 0 0 0 0
49768- 0 0 0 0 0 0 0 0 0 0 0 0
49769- 0 0 0 0 0 0 0 0 0 0 0 0
49770- 0 0 0 0 0 0 0 0 0 0 0 0
49771- 0 0 0 0 0 0 0 0 0 0 0 0
49772- 0 0 0 0 0 0 0 0 0 0 0 0
49773- 0 0 0 0 0 0 0 0 0 0 0 0
49774- 0 0 0 0 0 0 0 0 0 0 0 0
49775- 0 0 0 0 0 0 0 0 0 10 10 10
49776- 34 34 34 86 86 86 14 14 14 2 2 6
49777-121 87 25 192 133 9 219 162 10 239 182 13
49778-236 186 11 232 195 16 241 208 19 244 214 54
49779-246 218 60 246 218 38 246 215 20 241 208 19
49780-241 208 19 226 184 13 121 87 25 2 2 6
49781- 2 2 6 2 2 6 2 2 6 2 2 6
49782- 50 50 50 82 82 82 34 34 34 10 10 10
49783- 0 0 0 0 0 0 0 0 0 0 0 0
49784- 0 0 0 0 0 0 0 0 0 0 0 0
49785- 0 0 0 0 0 0 0 0 0 0 0 0
49786- 0 0 0 0 0 0 0 0 0 0 0 0
49787- 0 0 0 0 0 0 0 0 0 0 0 0
49788- 0 0 0 0 0 0 0 0 0 0 0 0
49789- 0 0 0 0 0 0 0 0 0 0 0 0
49790- 0 0 0 0 0 0 0 0 0 0 0 0
49791- 0 0 0 0 0 0 0 0 0 0 0 0
49792- 0 0 0 0 0 0 0 0 0 0 0 0
49793- 0 0 0 0 0 0 0 0 0 0 0 0
49794- 0 0 0 0 0 0 0 0 0 0 0 0
49795- 0 0 0 0 0 0 0 0 0 10 10 10
49796- 34 34 34 82 82 82 30 30 30 61 42 6
49797-180 123 7 206 145 10 230 174 11 239 182 13
49798-234 190 10 238 202 15 241 208 19 246 218 74
49799-246 218 38 246 215 20 246 215 20 246 215 20
49800-226 184 13 215 174 15 184 144 12 6 6 6
49801- 2 2 6 2 2 6 2 2 6 2 2 6
49802- 26 26 26 94 94 94 42 42 42 14 14 14
49803- 0 0 0 0 0 0 0 0 0 0 0 0
49804- 0 0 0 0 0 0 0 0 0 0 0 0
49805- 0 0 0 0 0 0 0 0 0 0 0 0
49806- 0 0 0 0 0 0 0 0 0 0 0 0
49807- 0 0 0 0 0 0 0 0 0 0 0 0
49808- 0 0 0 0 0 0 0 0 0 0 0 0
49809- 0 0 0 0 0 0 0 0 0 0 0 0
49810- 0 0 0 0 0 0 0 0 0 0 0 0
49811- 0 0 0 0 0 0 0 0 0 0 0 0
49812- 0 0 0 0 0 0 0 0 0 0 0 0
49813- 0 0 0 0 0 0 0 0 0 0 0 0
49814- 0 0 0 0 0 0 0 0 0 0 0 0
49815- 0 0 0 0 0 0 0 0 0 10 10 10
49816- 30 30 30 78 78 78 50 50 50 104 69 6
49817-192 133 9 216 158 10 236 178 12 236 186 11
49818-232 195 16 241 208 19 244 214 54 245 215 43
49819-246 215 20 246 215 20 241 208 19 198 155 10
49820-200 144 11 216 158 10 156 118 10 2 2 6
49821- 2 2 6 2 2 6 2 2 6 2 2 6
49822- 6 6 6 90 90 90 54 54 54 18 18 18
49823- 6 6 6 0 0 0 0 0 0 0 0 0
49824- 0 0 0 0 0 0 0 0 0 0 0 0
49825- 0 0 0 0 0 0 0 0 0 0 0 0
49826- 0 0 0 0 0 0 0 0 0 0 0 0
49827- 0 0 0 0 0 0 0 0 0 0 0 0
49828- 0 0 0 0 0 0 0 0 0 0 0 0
49829- 0 0 0 0 0 0 0 0 0 0 0 0
49830- 0 0 0 0 0 0 0 0 0 0 0 0
49831- 0 0 0 0 0 0 0 0 0 0 0 0
49832- 0 0 0 0 0 0 0 0 0 0 0 0
49833- 0 0 0 0 0 0 0 0 0 0 0 0
49834- 0 0 0 0 0 0 0 0 0 0 0 0
49835- 0 0 0 0 0 0 0 0 0 10 10 10
49836- 30 30 30 78 78 78 46 46 46 22 22 22
49837-137 92 6 210 162 10 239 182 13 238 190 10
49838-238 202 15 241 208 19 246 215 20 246 215 20
49839-241 208 19 203 166 17 185 133 11 210 150 10
49840-216 158 10 210 150 10 102 78 10 2 2 6
49841- 6 6 6 54 54 54 14 14 14 2 2 6
49842- 2 2 6 62 62 62 74 74 74 30 30 30
49843- 10 10 10 0 0 0 0 0 0 0 0 0
49844- 0 0 0 0 0 0 0 0 0 0 0 0
49845- 0 0 0 0 0 0 0 0 0 0 0 0
49846- 0 0 0 0 0 0 0 0 0 0 0 0
49847- 0 0 0 0 0 0 0 0 0 0 0 0
49848- 0 0 0 0 0 0 0 0 0 0 0 0
49849- 0 0 0 0 0 0 0 0 0 0 0 0
49850- 0 0 0 0 0 0 0 0 0 0 0 0
49851- 0 0 0 0 0 0 0 0 0 0 0 0
49852- 0 0 0 0 0 0 0 0 0 0 0 0
49853- 0 0 0 0 0 0 0 0 0 0 0 0
49854- 0 0 0 0 0 0 0 0 0 0 0 0
49855- 0 0 0 0 0 0 0 0 0 10 10 10
49856- 34 34 34 78 78 78 50 50 50 6 6 6
49857- 94 70 30 139 102 15 190 146 13 226 184 13
49858-232 200 30 232 195 16 215 174 15 190 146 13
49859-168 122 10 192 133 9 210 150 10 213 154 11
49860-202 150 34 182 157 106 101 98 89 2 2 6
49861- 2 2 6 78 78 78 116 116 116 58 58 58
49862- 2 2 6 22 22 22 90 90 90 46 46 46
49863- 18 18 18 6 6 6 0 0 0 0 0 0
49864- 0 0 0 0 0 0 0 0 0 0 0 0
49865- 0 0 0 0 0 0 0 0 0 0 0 0
49866- 0 0 0 0 0 0 0 0 0 0 0 0
49867- 0 0 0 0 0 0 0 0 0 0 0 0
49868- 0 0 0 0 0 0 0 0 0 0 0 0
49869- 0 0 0 0 0 0 0 0 0 0 0 0
49870- 0 0 0 0 0 0 0 0 0 0 0 0
49871- 0 0 0 0 0 0 0 0 0 0 0 0
49872- 0 0 0 0 0 0 0 0 0 0 0 0
49873- 0 0 0 0 0 0 0 0 0 0 0 0
49874- 0 0 0 0 0 0 0 0 0 0 0 0
49875- 0 0 0 0 0 0 0 0 0 10 10 10
49876- 38 38 38 86 86 86 50 50 50 6 6 6
49877-128 128 128 174 154 114 156 107 11 168 122 10
49878-198 155 10 184 144 12 197 138 11 200 144 11
49879-206 145 10 206 145 10 197 138 11 188 164 115
49880-195 195 195 198 198 198 174 174 174 14 14 14
49881- 2 2 6 22 22 22 116 116 116 116 116 116
49882- 22 22 22 2 2 6 74 74 74 70 70 70
49883- 30 30 30 10 10 10 0 0 0 0 0 0
49884- 0 0 0 0 0 0 0 0 0 0 0 0
49885- 0 0 0 0 0 0 0 0 0 0 0 0
49886- 0 0 0 0 0 0 0 0 0 0 0 0
49887- 0 0 0 0 0 0 0 0 0 0 0 0
49888- 0 0 0 0 0 0 0 0 0 0 0 0
49889- 0 0 0 0 0 0 0 0 0 0 0 0
49890- 0 0 0 0 0 0 0 0 0 0 0 0
49891- 0 0 0 0 0 0 0 0 0 0 0 0
49892- 0 0 0 0 0 0 0 0 0 0 0 0
49893- 0 0 0 0 0 0 0 0 0 0 0 0
49894- 0 0 0 0 0 0 0 0 0 0 0 0
49895- 0 0 0 0 0 0 6 6 6 18 18 18
49896- 50 50 50 101 101 101 26 26 26 10 10 10
49897-138 138 138 190 190 190 174 154 114 156 107 11
49898-197 138 11 200 144 11 197 138 11 192 133 9
49899-180 123 7 190 142 34 190 178 144 187 187 187
49900-202 202 202 221 221 221 214 214 214 66 66 66
49901- 2 2 6 2 2 6 50 50 50 62 62 62
49902- 6 6 6 2 2 6 10 10 10 90 90 90
49903- 50 50 50 18 18 18 6 6 6 0 0 0
49904- 0 0 0 0 0 0 0 0 0 0 0 0
49905- 0 0 0 0 0 0 0 0 0 0 0 0
49906- 0 0 0 0 0 0 0 0 0 0 0 0
49907- 0 0 0 0 0 0 0 0 0 0 0 0
49908- 0 0 0 0 0 0 0 0 0 0 0 0
49909- 0 0 0 0 0 0 0 0 0 0 0 0
49910- 0 0 0 0 0 0 0 0 0 0 0 0
49911- 0 0 0 0 0 0 0 0 0 0 0 0
49912- 0 0 0 0 0 0 0 0 0 0 0 0
49913- 0 0 0 0 0 0 0 0 0 0 0 0
49914- 0 0 0 0 0 0 0 0 0 0 0 0
49915- 0 0 0 0 0 0 10 10 10 34 34 34
49916- 74 74 74 74 74 74 2 2 6 6 6 6
49917-144 144 144 198 198 198 190 190 190 178 166 146
49918-154 121 60 156 107 11 156 107 11 168 124 44
49919-174 154 114 187 187 187 190 190 190 210 210 210
49920-246 246 246 253 253 253 253 253 253 182 182 182
49921- 6 6 6 2 2 6 2 2 6 2 2 6
49922- 2 2 6 2 2 6 2 2 6 62 62 62
49923- 74 74 74 34 34 34 14 14 14 0 0 0
49924- 0 0 0 0 0 0 0 0 0 0 0 0
49925- 0 0 0 0 0 0 0 0 0 0 0 0
49926- 0 0 0 0 0 0 0 0 0 0 0 0
49927- 0 0 0 0 0 0 0 0 0 0 0 0
49928- 0 0 0 0 0 0 0 0 0 0 0 0
49929- 0 0 0 0 0 0 0 0 0 0 0 0
49930- 0 0 0 0 0 0 0 0 0 0 0 0
49931- 0 0 0 0 0 0 0 0 0 0 0 0
49932- 0 0 0 0 0 0 0 0 0 0 0 0
49933- 0 0 0 0 0 0 0 0 0 0 0 0
49934- 0 0 0 0 0 0 0 0 0 0 0 0
49935- 0 0 0 10 10 10 22 22 22 54 54 54
49936- 94 94 94 18 18 18 2 2 6 46 46 46
49937-234 234 234 221 221 221 190 190 190 190 190 190
49938-190 190 190 187 187 187 187 187 187 190 190 190
49939-190 190 190 195 195 195 214 214 214 242 242 242
49940-253 253 253 253 253 253 253 253 253 253 253 253
49941- 82 82 82 2 2 6 2 2 6 2 2 6
49942- 2 2 6 2 2 6 2 2 6 14 14 14
49943- 86 86 86 54 54 54 22 22 22 6 6 6
49944- 0 0 0 0 0 0 0 0 0 0 0 0
49945- 0 0 0 0 0 0 0 0 0 0 0 0
49946- 0 0 0 0 0 0 0 0 0 0 0 0
49947- 0 0 0 0 0 0 0 0 0 0 0 0
49948- 0 0 0 0 0 0 0 0 0 0 0 0
49949- 0 0 0 0 0 0 0 0 0 0 0 0
49950- 0 0 0 0 0 0 0 0 0 0 0 0
49951- 0 0 0 0 0 0 0 0 0 0 0 0
49952- 0 0 0 0 0 0 0 0 0 0 0 0
49953- 0 0 0 0 0 0 0 0 0 0 0 0
49954- 0 0 0 0 0 0 0 0 0 0 0 0
49955- 6 6 6 18 18 18 46 46 46 90 90 90
49956- 46 46 46 18 18 18 6 6 6 182 182 182
49957-253 253 253 246 246 246 206 206 206 190 190 190
49958-190 190 190 190 190 190 190 190 190 190 190 190
49959-206 206 206 231 231 231 250 250 250 253 253 253
49960-253 253 253 253 253 253 253 253 253 253 253 253
49961-202 202 202 14 14 14 2 2 6 2 2 6
49962- 2 2 6 2 2 6 2 2 6 2 2 6
49963- 42 42 42 86 86 86 42 42 42 18 18 18
49964- 6 6 6 0 0 0 0 0 0 0 0 0
49965- 0 0 0 0 0 0 0 0 0 0 0 0
49966- 0 0 0 0 0 0 0 0 0 0 0 0
49967- 0 0 0 0 0 0 0 0 0 0 0 0
49968- 0 0 0 0 0 0 0 0 0 0 0 0
49969- 0 0 0 0 0 0 0 0 0 0 0 0
49970- 0 0 0 0 0 0 0 0 0 0 0 0
49971- 0 0 0 0 0 0 0 0 0 0 0 0
49972- 0 0 0 0 0 0 0 0 0 0 0 0
49973- 0 0 0 0 0 0 0 0 0 0 0 0
49974- 0 0 0 0 0 0 0 0 0 6 6 6
49975- 14 14 14 38 38 38 74 74 74 66 66 66
49976- 2 2 6 6 6 6 90 90 90 250 250 250
49977-253 253 253 253 253 253 238 238 238 198 198 198
49978-190 190 190 190 190 190 195 195 195 221 221 221
49979-246 246 246 253 253 253 253 253 253 253 253 253
49980-253 253 253 253 253 253 253 253 253 253 253 253
49981-253 253 253 82 82 82 2 2 6 2 2 6
49982- 2 2 6 2 2 6 2 2 6 2 2 6
49983- 2 2 6 78 78 78 70 70 70 34 34 34
49984- 14 14 14 6 6 6 0 0 0 0 0 0
49985- 0 0 0 0 0 0 0 0 0 0 0 0
49986- 0 0 0 0 0 0 0 0 0 0 0 0
49987- 0 0 0 0 0 0 0 0 0 0 0 0
49988- 0 0 0 0 0 0 0 0 0 0 0 0
49989- 0 0 0 0 0 0 0 0 0 0 0 0
49990- 0 0 0 0 0 0 0 0 0 0 0 0
49991- 0 0 0 0 0 0 0 0 0 0 0 0
49992- 0 0 0 0 0 0 0 0 0 0 0 0
49993- 0 0 0 0 0 0 0 0 0 0 0 0
49994- 0 0 0 0 0 0 0 0 0 14 14 14
49995- 34 34 34 66 66 66 78 78 78 6 6 6
49996- 2 2 6 18 18 18 218 218 218 253 253 253
49997-253 253 253 253 253 253 253 253 253 246 246 246
49998-226 226 226 231 231 231 246 246 246 253 253 253
49999-253 253 253 253 253 253 253 253 253 253 253 253
50000-253 253 253 253 253 253 253 253 253 253 253 253
50001-253 253 253 178 178 178 2 2 6 2 2 6
50002- 2 2 6 2 2 6 2 2 6 2 2 6
50003- 2 2 6 18 18 18 90 90 90 62 62 62
50004- 30 30 30 10 10 10 0 0 0 0 0 0
50005- 0 0 0 0 0 0 0 0 0 0 0 0
50006- 0 0 0 0 0 0 0 0 0 0 0 0
50007- 0 0 0 0 0 0 0 0 0 0 0 0
50008- 0 0 0 0 0 0 0 0 0 0 0 0
50009- 0 0 0 0 0 0 0 0 0 0 0 0
50010- 0 0 0 0 0 0 0 0 0 0 0 0
50011- 0 0 0 0 0 0 0 0 0 0 0 0
50012- 0 0 0 0 0 0 0 0 0 0 0 0
50013- 0 0 0 0 0 0 0 0 0 0 0 0
50014- 0 0 0 0 0 0 10 10 10 26 26 26
50015- 58 58 58 90 90 90 18 18 18 2 2 6
50016- 2 2 6 110 110 110 253 253 253 253 253 253
50017-253 253 253 253 253 253 253 253 253 253 253 253
50018-250 250 250 253 253 253 253 253 253 253 253 253
50019-253 253 253 253 253 253 253 253 253 253 253 253
50020-253 253 253 253 253 253 253 253 253 253 253 253
50021-253 253 253 231 231 231 18 18 18 2 2 6
50022- 2 2 6 2 2 6 2 2 6 2 2 6
50023- 2 2 6 2 2 6 18 18 18 94 94 94
50024- 54 54 54 26 26 26 10 10 10 0 0 0
50025- 0 0 0 0 0 0 0 0 0 0 0 0
50026- 0 0 0 0 0 0 0 0 0 0 0 0
50027- 0 0 0 0 0 0 0 0 0 0 0 0
50028- 0 0 0 0 0 0 0 0 0 0 0 0
50029- 0 0 0 0 0 0 0 0 0 0 0 0
50030- 0 0 0 0 0 0 0 0 0 0 0 0
50031- 0 0 0 0 0 0 0 0 0 0 0 0
50032- 0 0 0 0 0 0 0 0 0 0 0 0
50033- 0 0 0 0 0 0 0 0 0 0 0 0
50034- 0 0 0 6 6 6 22 22 22 50 50 50
50035- 90 90 90 26 26 26 2 2 6 2 2 6
50036- 14 14 14 195 195 195 250 250 250 253 253 253
50037-253 253 253 253 253 253 253 253 253 253 253 253
50038-253 253 253 253 253 253 253 253 253 253 253 253
50039-253 253 253 253 253 253 253 253 253 253 253 253
50040-253 253 253 253 253 253 253 253 253 253 253 253
50041-250 250 250 242 242 242 54 54 54 2 2 6
50042- 2 2 6 2 2 6 2 2 6 2 2 6
50043- 2 2 6 2 2 6 2 2 6 38 38 38
50044- 86 86 86 50 50 50 22 22 22 6 6 6
50045- 0 0 0 0 0 0 0 0 0 0 0 0
50046- 0 0 0 0 0 0 0 0 0 0 0 0
50047- 0 0 0 0 0 0 0 0 0 0 0 0
50048- 0 0 0 0 0 0 0 0 0 0 0 0
50049- 0 0 0 0 0 0 0 0 0 0 0 0
50050- 0 0 0 0 0 0 0 0 0 0 0 0
50051- 0 0 0 0 0 0 0 0 0 0 0 0
50052- 0 0 0 0 0 0 0 0 0 0 0 0
50053- 0 0 0 0 0 0 0 0 0 0 0 0
50054- 6 6 6 14 14 14 38 38 38 82 82 82
50055- 34 34 34 2 2 6 2 2 6 2 2 6
50056- 42 42 42 195 195 195 246 246 246 253 253 253
50057-253 253 253 253 253 253 253 253 253 250 250 250
50058-242 242 242 242 242 242 250 250 250 253 253 253
50059-253 253 253 253 253 253 253 253 253 253 253 253
50060-253 253 253 250 250 250 246 246 246 238 238 238
50061-226 226 226 231 231 231 101 101 101 6 6 6
50062- 2 2 6 2 2 6 2 2 6 2 2 6
50063- 2 2 6 2 2 6 2 2 6 2 2 6
50064- 38 38 38 82 82 82 42 42 42 14 14 14
50065- 6 6 6 0 0 0 0 0 0 0 0 0
50066- 0 0 0 0 0 0 0 0 0 0 0 0
50067- 0 0 0 0 0 0 0 0 0 0 0 0
50068- 0 0 0 0 0 0 0 0 0 0 0 0
50069- 0 0 0 0 0 0 0 0 0 0 0 0
50070- 0 0 0 0 0 0 0 0 0 0 0 0
50071- 0 0 0 0 0 0 0 0 0 0 0 0
50072- 0 0 0 0 0 0 0 0 0 0 0 0
50073- 0 0 0 0 0 0 0 0 0 0 0 0
50074- 10 10 10 26 26 26 62 62 62 66 66 66
50075- 2 2 6 2 2 6 2 2 6 6 6 6
50076- 70 70 70 170 170 170 206 206 206 234 234 234
50077-246 246 246 250 250 250 250 250 250 238 238 238
50078-226 226 226 231 231 231 238 238 238 250 250 250
50079-250 250 250 250 250 250 246 246 246 231 231 231
50080-214 214 214 206 206 206 202 202 202 202 202 202
50081-198 198 198 202 202 202 182 182 182 18 18 18
50082- 2 2 6 2 2 6 2 2 6 2 2 6
50083- 2 2 6 2 2 6 2 2 6 2 2 6
50084- 2 2 6 62 62 62 66 66 66 30 30 30
50085- 10 10 10 0 0 0 0 0 0 0 0 0
50086- 0 0 0 0 0 0 0 0 0 0 0 0
50087- 0 0 0 0 0 0 0 0 0 0 0 0
50088- 0 0 0 0 0 0 0 0 0 0 0 0
50089- 0 0 0 0 0 0 0 0 0 0 0 0
50090- 0 0 0 0 0 0 0 0 0 0 0 0
50091- 0 0 0 0 0 0 0 0 0 0 0 0
50092- 0 0 0 0 0 0 0 0 0 0 0 0
50093- 0 0 0 0 0 0 0 0 0 0 0 0
50094- 14 14 14 42 42 42 82 82 82 18 18 18
50095- 2 2 6 2 2 6 2 2 6 10 10 10
50096- 94 94 94 182 182 182 218 218 218 242 242 242
50097-250 250 250 253 253 253 253 253 253 250 250 250
50098-234 234 234 253 253 253 253 253 253 253 253 253
50099-253 253 253 253 253 253 253 253 253 246 246 246
50100-238 238 238 226 226 226 210 210 210 202 202 202
50101-195 195 195 195 195 195 210 210 210 158 158 158
50102- 6 6 6 14 14 14 50 50 50 14 14 14
50103- 2 2 6 2 2 6 2 2 6 2 2 6
50104- 2 2 6 6 6 6 86 86 86 46 46 46
50105- 18 18 18 6 6 6 0 0 0 0 0 0
50106- 0 0 0 0 0 0 0 0 0 0 0 0
50107- 0 0 0 0 0 0 0 0 0 0 0 0
50108- 0 0 0 0 0 0 0 0 0 0 0 0
50109- 0 0 0 0 0 0 0 0 0 0 0 0
50110- 0 0 0 0 0 0 0 0 0 0 0 0
50111- 0 0 0 0 0 0 0 0 0 0 0 0
50112- 0 0 0 0 0 0 0 0 0 0 0 0
50113- 0 0 0 0 0 0 0 0 0 6 6 6
50114- 22 22 22 54 54 54 70 70 70 2 2 6
50115- 2 2 6 10 10 10 2 2 6 22 22 22
50116-166 166 166 231 231 231 250 250 250 253 253 253
50117-253 253 253 253 253 253 253 253 253 250 250 250
50118-242 242 242 253 253 253 253 253 253 253 253 253
50119-253 253 253 253 253 253 253 253 253 253 253 253
50120-253 253 253 253 253 253 253 253 253 246 246 246
50121-231 231 231 206 206 206 198 198 198 226 226 226
50122- 94 94 94 2 2 6 6 6 6 38 38 38
50123- 30 30 30 2 2 6 2 2 6 2 2 6
50124- 2 2 6 2 2 6 62 62 62 66 66 66
50125- 26 26 26 10 10 10 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- 0 0 0 0 0 0 0 0 0 0 0 0
50133- 0 0 0 0 0 0 0 0 0 10 10 10
50134- 30 30 30 74 74 74 50 50 50 2 2 6
50135- 26 26 26 26 26 26 2 2 6 106 106 106
50136-238 238 238 253 253 253 253 253 253 253 253 253
50137-253 253 253 253 253 253 253 253 253 253 253 253
50138-253 253 253 253 253 253 253 253 253 253 253 253
50139-253 253 253 253 253 253 253 253 253 253 253 253
50140-253 253 253 253 253 253 253 253 253 253 253 253
50141-253 253 253 246 246 246 218 218 218 202 202 202
50142-210 210 210 14 14 14 2 2 6 2 2 6
50143- 30 30 30 22 22 22 2 2 6 2 2 6
50144- 2 2 6 2 2 6 18 18 18 86 86 86
50145- 42 42 42 14 14 14 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 0 0 0 0 0 0 0 0 0
50152- 0 0 0 0 0 0 0 0 0 0 0 0
50153- 0 0 0 0 0 0 0 0 0 14 14 14
50154- 42 42 42 90 90 90 22 22 22 2 2 6
50155- 42 42 42 2 2 6 18 18 18 218 218 218
50156-253 253 253 253 253 253 253 253 253 253 253 253
50157-253 253 253 253 253 253 253 253 253 253 253 253
50158-253 253 253 253 253 253 253 253 253 253 253 253
50159-253 253 253 253 253 253 253 253 253 253 253 253
50160-253 253 253 253 253 253 253 253 253 253 253 253
50161-253 253 253 253 253 253 250 250 250 221 221 221
50162-218 218 218 101 101 101 2 2 6 14 14 14
50163- 18 18 18 38 38 38 10 10 10 2 2 6
50164- 2 2 6 2 2 6 2 2 6 78 78 78
50165- 58 58 58 22 22 22 6 6 6 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- 0 0 0 0 0 0 0 0 0 0 0 0
50172- 0 0 0 0 0 0 0 0 0 0 0 0
50173- 0 0 0 0 0 0 6 6 6 18 18 18
50174- 54 54 54 82 82 82 2 2 6 26 26 26
50175- 22 22 22 2 2 6 123 123 123 253 253 253
50176-253 253 253 253 253 253 253 253 253 253 253 253
50177-253 253 253 253 253 253 253 253 253 253 253 253
50178-253 253 253 253 253 253 253 253 253 253 253 253
50179-253 253 253 253 253 253 253 253 253 253 253 253
50180-253 253 253 253 253 253 253 253 253 253 253 253
50181-253 253 253 253 253 253 253 253 253 250 250 250
50182-238 238 238 198 198 198 6 6 6 38 38 38
50183- 58 58 58 26 26 26 38 38 38 2 2 6
50184- 2 2 6 2 2 6 2 2 6 46 46 46
50185- 78 78 78 30 30 30 10 10 10 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 0 0 0
50191- 0 0 0 0 0 0 0 0 0 0 0 0
50192- 0 0 0 0 0 0 0 0 0 0 0 0
50193- 0 0 0 0 0 0 10 10 10 30 30 30
50194- 74 74 74 58 58 58 2 2 6 42 42 42
50195- 2 2 6 22 22 22 231 231 231 253 253 253
50196-253 253 253 253 253 253 253 253 253 253 253 253
50197-253 253 253 253 253 253 253 253 253 250 250 250
50198-253 253 253 253 253 253 253 253 253 253 253 253
50199-253 253 253 253 253 253 253 253 253 253 253 253
50200-253 253 253 253 253 253 253 253 253 253 253 253
50201-253 253 253 253 253 253 253 253 253 253 253 253
50202-253 253 253 246 246 246 46 46 46 38 38 38
50203- 42 42 42 14 14 14 38 38 38 14 14 14
50204- 2 2 6 2 2 6 2 2 6 6 6 6
50205- 86 86 86 46 46 46 14 14 14 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 0 0 0 0 0 0
50211- 0 0 0 0 0 0 0 0 0 0 0 0
50212- 0 0 0 0 0 0 0 0 0 0 0 0
50213- 0 0 0 6 6 6 14 14 14 42 42 42
50214- 90 90 90 18 18 18 18 18 18 26 26 26
50215- 2 2 6 116 116 116 253 253 253 253 253 253
50216-253 253 253 253 253 253 253 253 253 253 253 253
50217-253 253 253 253 253 253 250 250 250 238 238 238
50218-253 253 253 253 253 253 253 253 253 253 253 253
50219-253 253 253 253 253 253 253 253 253 253 253 253
50220-253 253 253 253 253 253 253 253 253 253 253 253
50221-253 253 253 253 253 253 253 253 253 253 253 253
50222-253 253 253 253 253 253 94 94 94 6 6 6
50223- 2 2 6 2 2 6 10 10 10 34 34 34
50224- 2 2 6 2 2 6 2 2 6 2 2 6
50225- 74 74 74 58 58 58 22 22 22 6 6 6
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 0 0 0 0 0 0 0 0 0
50231- 0 0 0 0 0 0 0 0 0 0 0 0
50232- 0 0 0 0 0 0 0 0 0 0 0 0
50233- 0 0 0 10 10 10 26 26 26 66 66 66
50234- 82 82 82 2 2 6 38 38 38 6 6 6
50235- 14 14 14 210 210 210 253 253 253 253 253 253
50236-253 253 253 253 253 253 253 253 253 253 253 253
50237-253 253 253 253 253 253 246 246 246 242 242 242
50238-253 253 253 253 253 253 253 253 253 253 253 253
50239-253 253 253 253 253 253 253 253 253 253 253 253
50240-253 253 253 253 253 253 253 253 253 253 253 253
50241-253 253 253 253 253 253 253 253 253 253 253 253
50242-253 253 253 253 253 253 144 144 144 2 2 6
50243- 2 2 6 2 2 6 2 2 6 46 46 46
50244- 2 2 6 2 2 6 2 2 6 2 2 6
50245- 42 42 42 74 74 74 30 30 30 10 10 10
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- 0 0 0 0 0 0 0 0 0 0 0 0
50251- 0 0 0 0 0 0 0 0 0 0 0 0
50252- 0 0 0 0 0 0 0 0 0 0 0 0
50253- 6 6 6 14 14 14 42 42 42 90 90 90
50254- 26 26 26 6 6 6 42 42 42 2 2 6
50255- 74 74 74 250 250 250 253 253 253 253 253 253
50256-253 253 253 253 253 253 253 253 253 253 253 253
50257-253 253 253 253 253 253 242 242 242 242 242 242
50258-253 253 253 253 253 253 253 253 253 253 253 253
50259-253 253 253 253 253 253 253 253 253 253 253 253
50260-253 253 253 253 253 253 253 253 253 253 253 253
50261-253 253 253 253 253 253 253 253 253 253 253 253
50262-253 253 253 253 253 253 182 182 182 2 2 6
50263- 2 2 6 2 2 6 2 2 6 46 46 46
50264- 2 2 6 2 2 6 2 2 6 2 2 6
50265- 10 10 10 86 86 86 38 38 38 10 10 10
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- 0 0 0 0 0 0 0 0 0 0 0 0
50271- 0 0 0 0 0 0 0 0 0 0 0 0
50272- 0 0 0 0 0 0 0 0 0 0 0 0
50273- 10 10 10 26 26 26 66 66 66 82 82 82
50274- 2 2 6 22 22 22 18 18 18 2 2 6
50275-149 149 149 253 253 253 253 253 253 253 253 253
50276-253 253 253 253 253 253 253 253 253 253 253 253
50277-253 253 253 253 253 253 234 234 234 242 242 242
50278-253 253 253 253 253 253 253 253 253 253 253 253
50279-253 253 253 253 253 253 253 253 253 253 253 253
50280-253 253 253 253 253 253 253 253 253 253 253 253
50281-253 253 253 253 253 253 253 253 253 253 253 253
50282-253 253 253 253 253 253 206 206 206 2 2 6
50283- 2 2 6 2 2 6 2 2 6 38 38 38
50284- 2 2 6 2 2 6 2 2 6 2 2 6
50285- 6 6 6 86 86 86 46 46 46 14 14 14
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- 0 0 0 0 0 0 0 0 0 0 0 0
50291- 0 0 0 0 0 0 0 0 0 0 0 0
50292- 0 0 0 0 0 0 0 0 0 6 6 6
50293- 18 18 18 46 46 46 86 86 86 18 18 18
50294- 2 2 6 34 34 34 10 10 10 6 6 6
50295-210 210 210 253 253 253 253 253 253 253 253 253
50296-253 253 253 253 253 253 253 253 253 253 253 253
50297-253 253 253 253 253 253 234 234 234 242 242 242
50298-253 253 253 253 253 253 253 253 253 253 253 253
50299-253 253 253 253 253 253 253 253 253 253 253 253
50300-253 253 253 253 253 253 253 253 253 253 253 253
50301-253 253 253 253 253 253 253 253 253 253 253 253
50302-253 253 253 253 253 253 221 221 221 6 6 6
50303- 2 2 6 2 2 6 6 6 6 30 30 30
50304- 2 2 6 2 2 6 2 2 6 2 2 6
50305- 2 2 6 82 82 82 54 54 54 18 18 18
50306- 6 6 6 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 0 0 0
50310- 0 0 0 0 0 0 0 0 0 0 0 0
50311- 0 0 0 0 0 0 0 0 0 0 0 0
50312- 0 0 0 0 0 0 0 0 0 10 10 10
50313- 26 26 26 66 66 66 62 62 62 2 2 6
50314- 2 2 6 38 38 38 10 10 10 26 26 26
50315-238 238 238 253 253 253 253 253 253 253 253 253
50316-253 253 253 253 253 253 253 253 253 253 253 253
50317-253 253 253 253 253 253 231 231 231 238 238 238
50318-253 253 253 253 253 253 253 253 253 253 253 253
50319-253 253 253 253 253 253 253 253 253 253 253 253
50320-253 253 253 253 253 253 253 253 253 253 253 253
50321-253 253 253 253 253 253 253 253 253 253 253 253
50322-253 253 253 253 253 253 231 231 231 6 6 6
50323- 2 2 6 2 2 6 10 10 10 30 30 30
50324- 2 2 6 2 2 6 2 2 6 2 2 6
50325- 2 2 6 66 66 66 58 58 58 22 22 22
50326- 6 6 6 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 0 0 0
50330- 0 0 0 0 0 0 0 0 0 0 0 0
50331- 0 0 0 0 0 0 0 0 0 0 0 0
50332- 0 0 0 0 0 0 0 0 0 10 10 10
50333- 38 38 38 78 78 78 6 6 6 2 2 6
50334- 2 2 6 46 46 46 14 14 14 42 42 42
50335-246 246 246 253 253 253 253 253 253 253 253 253
50336-253 253 253 253 253 253 253 253 253 253 253 253
50337-253 253 253 253 253 253 231 231 231 242 242 242
50338-253 253 253 253 253 253 253 253 253 253 253 253
50339-253 253 253 253 253 253 253 253 253 253 253 253
50340-253 253 253 253 253 253 253 253 253 253 253 253
50341-253 253 253 253 253 253 253 253 253 253 253 253
50342-253 253 253 253 253 253 234 234 234 10 10 10
50343- 2 2 6 2 2 6 22 22 22 14 14 14
50344- 2 2 6 2 2 6 2 2 6 2 2 6
50345- 2 2 6 66 66 66 62 62 62 22 22 22
50346- 6 6 6 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 0 0 0
50350- 0 0 0 0 0 0 0 0 0 0 0 0
50351- 0 0 0 0 0 0 0 0 0 0 0 0
50352- 0 0 0 0 0 0 6 6 6 18 18 18
50353- 50 50 50 74 74 74 2 2 6 2 2 6
50354- 14 14 14 70 70 70 34 34 34 62 62 62
50355-250 250 250 253 253 253 253 253 253 253 253 253
50356-253 253 253 253 253 253 253 253 253 253 253 253
50357-253 253 253 253 253 253 231 231 231 246 246 246
50358-253 253 253 253 253 253 253 253 253 253 253 253
50359-253 253 253 253 253 253 253 253 253 253 253 253
50360-253 253 253 253 253 253 253 253 253 253 253 253
50361-253 253 253 253 253 253 253 253 253 253 253 253
50362-253 253 253 253 253 253 234 234 234 14 14 14
50363- 2 2 6 2 2 6 30 30 30 2 2 6
50364- 2 2 6 2 2 6 2 2 6 2 2 6
50365- 2 2 6 66 66 66 62 62 62 22 22 22
50366- 6 6 6 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 0 0 0
50370- 0 0 0 0 0 0 0 0 0 0 0 0
50371- 0 0 0 0 0 0 0 0 0 0 0 0
50372- 0 0 0 0 0 0 6 6 6 18 18 18
50373- 54 54 54 62 62 62 2 2 6 2 2 6
50374- 2 2 6 30 30 30 46 46 46 70 70 70
50375-250 250 250 253 253 253 253 253 253 253 253 253
50376-253 253 253 253 253 253 253 253 253 253 253 253
50377-253 253 253 253 253 253 231 231 231 246 246 246
50378-253 253 253 253 253 253 253 253 253 253 253 253
50379-253 253 253 253 253 253 253 253 253 253 253 253
50380-253 253 253 253 253 253 253 253 253 253 253 253
50381-253 253 253 253 253 253 253 253 253 253 253 253
50382-253 253 253 253 253 253 226 226 226 10 10 10
50383- 2 2 6 6 6 6 30 30 30 2 2 6
50384- 2 2 6 2 2 6 2 2 6 2 2 6
50385- 2 2 6 66 66 66 58 58 58 22 22 22
50386- 6 6 6 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 0 0 0
50390- 0 0 0 0 0 0 0 0 0 0 0 0
50391- 0 0 0 0 0 0 0 0 0 0 0 0
50392- 0 0 0 0 0 0 6 6 6 22 22 22
50393- 58 58 58 62 62 62 2 2 6 2 2 6
50394- 2 2 6 2 2 6 30 30 30 78 78 78
50395-250 250 250 253 253 253 253 253 253 253 253 253
50396-253 253 253 253 253 253 253 253 253 253 253 253
50397-253 253 253 253 253 253 231 231 231 246 246 246
50398-253 253 253 253 253 253 253 253 253 253 253 253
50399-253 253 253 253 253 253 253 253 253 253 253 253
50400-253 253 253 253 253 253 253 253 253 253 253 253
50401-253 253 253 253 253 253 253 253 253 253 253 253
50402-253 253 253 253 253 253 206 206 206 2 2 6
50403- 22 22 22 34 34 34 18 14 6 22 22 22
50404- 26 26 26 18 18 18 6 6 6 2 2 6
50405- 2 2 6 82 82 82 54 54 54 18 18 18
50406- 6 6 6 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 0 0 0
50410- 0 0 0 0 0 0 0 0 0 0 0 0
50411- 0 0 0 0 0 0 0 0 0 0 0 0
50412- 0 0 0 0 0 0 6 6 6 26 26 26
50413- 62 62 62 106 106 106 74 54 14 185 133 11
50414-210 162 10 121 92 8 6 6 6 62 62 62
50415-238 238 238 253 253 253 253 253 253 253 253 253
50416-253 253 253 253 253 253 253 253 253 253 253 253
50417-253 253 253 253 253 253 231 231 231 246 246 246
50418-253 253 253 253 253 253 253 253 253 253 253 253
50419-253 253 253 253 253 253 253 253 253 253 253 253
50420-253 253 253 253 253 253 253 253 253 253 253 253
50421-253 253 253 253 253 253 253 253 253 253 253 253
50422-253 253 253 253 253 253 158 158 158 18 18 18
50423- 14 14 14 2 2 6 2 2 6 2 2 6
50424- 6 6 6 18 18 18 66 66 66 38 38 38
50425- 6 6 6 94 94 94 50 50 50 18 18 18
50426- 6 6 6 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 0 0 0
50430- 0 0 0 0 0 0 0 0 0 0 0 0
50431- 0 0 0 0 0 0 0 0 0 6 6 6
50432- 10 10 10 10 10 10 18 18 18 38 38 38
50433- 78 78 78 142 134 106 216 158 10 242 186 14
50434-246 190 14 246 190 14 156 118 10 10 10 10
50435- 90 90 90 238 238 238 253 253 253 253 253 253
50436-253 253 253 253 253 253 253 253 253 253 253 253
50437-253 253 253 253 253 253 231 231 231 250 250 250
50438-253 253 253 253 253 253 253 253 253 253 253 253
50439-253 253 253 253 253 253 253 253 253 253 253 253
50440-253 253 253 253 253 253 253 253 253 253 253 253
50441-253 253 253 253 253 253 253 253 253 246 230 190
50442-238 204 91 238 204 91 181 142 44 37 26 9
50443- 2 2 6 2 2 6 2 2 6 2 2 6
50444- 2 2 6 2 2 6 38 38 38 46 46 46
50445- 26 26 26 106 106 106 54 54 54 18 18 18
50446- 6 6 6 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 0 0 0
50450- 0 0 0 0 0 0 0 0 0 0 0 0
50451- 0 0 0 6 6 6 14 14 14 22 22 22
50452- 30 30 30 38 38 38 50 50 50 70 70 70
50453-106 106 106 190 142 34 226 170 11 242 186 14
50454-246 190 14 246 190 14 246 190 14 154 114 10
50455- 6 6 6 74 74 74 226 226 226 253 253 253
50456-253 253 253 253 253 253 253 253 253 253 253 253
50457-253 253 253 253 253 253 231 231 231 250 250 250
50458-253 253 253 253 253 253 253 253 253 253 253 253
50459-253 253 253 253 253 253 253 253 253 253 253 253
50460-253 253 253 253 253 253 253 253 253 253 253 253
50461-253 253 253 253 253 253 253 253 253 228 184 62
50462-241 196 14 241 208 19 232 195 16 38 30 10
50463- 2 2 6 2 2 6 2 2 6 2 2 6
50464- 2 2 6 6 6 6 30 30 30 26 26 26
50465-203 166 17 154 142 90 66 66 66 26 26 26
50466- 6 6 6 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 0 0 0
50470- 0 0 0 0 0 0 0 0 0 0 0 0
50471- 6 6 6 18 18 18 38 38 38 58 58 58
50472- 78 78 78 86 86 86 101 101 101 123 123 123
50473-175 146 61 210 150 10 234 174 13 246 186 14
50474-246 190 14 246 190 14 246 190 14 238 190 10
50475-102 78 10 2 2 6 46 46 46 198 198 198
50476-253 253 253 253 253 253 253 253 253 253 253 253
50477-253 253 253 253 253 253 234 234 234 242 242 242
50478-253 253 253 253 253 253 253 253 253 253 253 253
50479-253 253 253 253 253 253 253 253 253 253 253 253
50480-253 253 253 253 253 253 253 253 253 253 253 253
50481-253 253 253 253 253 253 253 253 253 224 178 62
50482-242 186 14 241 196 14 210 166 10 22 18 6
50483- 2 2 6 2 2 6 2 2 6 2 2 6
50484- 2 2 6 2 2 6 6 6 6 121 92 8
50485-238 202 15 232 195 16 82 82 82 34 34 34
50486- 10 10 10 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 0 0 0
50490- 0 0 0 0 0 0 0 0 0 0 0 0
50491- 14 14 14 38 38 38 70 70 70 154 122 46
50492-190 142 34 200 144 11 197 138 11 197 138 11
50493-213 154 11 226 170 11 242 186 14 246 190 14
50494-246 190 14 246 190 14 246 190 14 246 190 14
50495-225 175 15 46 32 6 2 2 6 22 22 22
50496-158 158 158 250 250 250 253 253 253 253 253 253
50497-253 253 253 253 253 253 253 253 253 253 253 253
50498-253 253 253 253 253 253 253 253 253 253 253 253
50499-253 253 253 253 253 253 253 253 253 253 253 253
50500-253 253 253 253 253 253 253 253 253 253 253 253
50501-253 253 253 250 250 250 242 242 242 224 178 62
50502-239 182 13 236 186 11 213 154 11 46 32 6
50503- 2 2 6 2 2 6 2 2 6 2 2 6
50504- 2 2 6 2 2 6 61 42 6 225 175 15
50505-238 190 10 236 186 11 112 100 78 42 42 42
50506- 14 14 14 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 0 0 0
50510- 0 0 0 0 0 0 0 0 0 6 6 6
50511- 22 22 22 54 54 54 154 122 46 213 154 11
50512-226 170 11 230 174 11 226 170 11 226 170 11
50513-236 178 12 242 186 14 246 190 14 246 190 14
50514-246 190 14 246 190 14 246 190 14 246 190 14
50515-241 196 14 184 144 12 10 10 10 2 2 6
50516- 6 6 6 116 116 116 242 242 242 253 253 253
50517-253 253 253 253 253 253 253 253 253 253 253 253
50518-253 253 253 253 253 253 253 253 253 253 253 253
50519-253 253 253 253 253 253 253 253 253 253 253 253
50520-253 253 253 253 253 253 253 253 253 253 253 253
50521-253 253 253 231 231 231 198 198 198 214 170 54
50522-236 178 12 236 178 12 210 150 10 137 92 6
50523- 18 14 6 2 2 6 2 2 6 2 2 6
50524- 6 6 6 70 47 6 200 144 11 236 178 12
50525-239 182 13 239 182 13 124 112 88 58 58 58
50526- 22 22 22 6 6 6 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 0 0 0
50530- 0 0 0 0 0 0 0 0 0 10 10 10
50531- 30 30 30 70 70 70 180 133 36 226 170 11
50532-239 182 13 242 186 14 242 186 14 246 186 14
50533-246 190 14 246 190 14 246 190 14 246 190 14
50534-246 190 14 246 190 14 246 190 14 246 190 14
50535-246 190 14 232 195 16 98 70 6 2 2 6
50536- 2 2 6 2 2 6 66 66 66 221 221 221
50537-253 253 253 253 253 253 253 253 253 253 253 253
50538-253 253 253 253 253 253 253 253 253 253 253 253
50539-253 253 253 253 253 253 253 253 253 253 253 253
50540-253 253 253 253 253 253 253 253 253 253 253 253
50541-253 253 253 206 206 206 198 198 198 214 166 58
50542-230 174 11 230 174 11 216 158 10 192 133 9
50543-163 110 8 116 81 8 102 78 10 116 81 8
50544-167 114 7 197 138 11 226 170 11 239 182 13
50545-242 186 14 242 186 14 162 146 94 78 78 78
50546- 34 34 34 14 14 14 6 6 6 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 0 0 0
50550- 0 0 0 0 0 0 0 0 0 6 6 6
50551- 30 30 30 78 78 78 190 142 34 226 170 11
50552-239 182 13 246 190 14 246 190 14 246 190 14
50553-246 190 14 246 190 14 246 190 14 246 190 14
50554-246 190 14 246 190 14 246 190 14 246 190 14
50555-246 190 14 241 196 14 203 166 17 22 18 6
50556- 2 2 6 2 2 6 2 2 6 38 38 38
50557-218 218 218 253 253 253 253 253 253 253 253 253
50558-253 253 253 253 253 253 253 253 253 253 253 253
50559-253 253 253 253 253 253 253 253 253 253 253 253
50560-253 253 253 253 253 253 253 253 253 253 253 253
50561-250 250 250 206 206 206 198 198 198 202 162 69
50562-226 170 11 236 178 12 224 166 10 210 150 10
50563-200 144 11 197 138 11 192 133 9 197 138 11
50564-210 150 10 226 170 11 242 186 14 246 190 14
50565-246 190 14 246 186 14 225 175 15 124 112 88
50566- 62 62 62 30 30 30 14 14 14 6 6 6
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 0 0 0
50570- 0 0 0 0 0 0 0 0 0 10 10 10
50571- 30 30 30 78 78 78 174 135 50 224 166 10
50572-239 182 13 246 190 14 246 190 14 246 190 14
50573-246 190 14 246 190 14 246 190 14 246 190 14
50574-246 190 14 246 190 14 246 190 14 246 190 14
50575-246 190 14 246 190 14 241 196 14 139 102 15
50576- 2 2 6 2 2 6 2 2 6 2 2 6
50577- 78 78 78 250 250 250 253 253 253 253 253 253
50578-253 253 253 253 253 253 253 253 253 253 253 253
50579-253 253 253 253 253 253 253 253 253 253 253 253
50580-253 253 253 253 253 253 253 253 253 253 253 253
50581-250 250 250 214 214 214 198 198 198 190 150 46
50582-219 162 10 236 178 12 234 174 13 224 166 10
50583-216 158 10 213 154 11 213 154 11 216 158 10
50584-226 170 11 239 182 13 246 190 14 246 190 14
50585-246 190 14 246 190 14 242 186 14 206 162 42
50586-101 101 101 58 58 58 30 30 30 14 14 14
50587- 6 6 6 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 0 0 0
50590- 0 0 0 0 0 0 0 0 0 10 10 10
50591- 30 30 30 74 74 74 174 135 50 216 158 10
50592-236 178 12 246 190 14 246 190 14 246 190 14
50593-246 190 14 246 190 14 246 190 14 246 190 14
50594-246 190 14 246 190 14 246 190 14 246 190 14
50595-246 190 14 246 190 14 241 196 14 226 184 13
50596- 61 42 6 2 2 6 2 2 6 2 2 6
50597- 22 22 22 238 238 238 253 253 253 253 253 253
50598-253 253 253 253 253 253 253 253 253 253 253 253
50599-253 253 253 253 253 253 253 253 253 253 253 253
50600-253 253 253 253 253 253 253 253 253 253 253 253
50601-253 253 253 226 226 226 187 187 187 180 133 36
50602-216 158 10 236 178 12 239 182 13 236 178 12
50603-230 174 11 226 170 11 226 170 11 230 174 11
50604-236 178 12 242 186 14 246 190 14 246 190 14
50605-246 190 14 246 190 14 246 186 14 239 182 13
50606-206 162 42 106 106 106 66 66 66 34 34 34
50607- 14 14 14 6 6 6 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 0 0 0
50610- 0 0 0 0 0 0 0 0 0 6 6 6
50611- 26 26 26 70 70 70 163 133 67 213 154 11
50612-236 178 12 246 190 14 246 190 14 246 190 14
50613-246 190 14 246 190 14 246 190 14 246 190 14
50614-246 190 14 246 190 14 246 190 14 246 190 14
50615-246 190 14 246 190 14 246 190 14 241 196 14
50616-190 146 13 18 14 6 2 2 6 2 2 6
50617- 46 46 46 246 246 246 253 253 253 253 253 253
50618-253 253 253 253 253 253 253 253 253 253 253 253
50619-253 253 253 253 253 253 253 253 253 253 253 253
50620-253 253 253 253 253 253 253 253 253 253 253 253
50621-253 253 253 221 221 221 86 86 86 156 107 11
50622-216 158 10 236 178 12 242 186 14 246 186 14
50623-242 186 14 239 182 13 239 182 13 242 186 14
50624-242 186 14 246 186 14 246 190 14 246 190 14
50625-246 190 14 246 190 14 246 190 14 246 190 14
50626-242 186 14 225 175 15 142 122 72 66 66 66
50627- 30 30 30 10 10 10 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 0 0 0
50630- 0 0 0 0 0 0 0 0 0 6 6 6
50631- 26 26 26 70 70 70 163 133 67 210 150 10
50632-236 178 12 246 190 14 246 190 14 246 190 14
50633-246 190 14 246 190 14 246 190 14 246 190 14
50634-246 190 14 246 190 14 246 190 14 246 190 14
50635-246 190 14 246 190 14 246 190 14 246 190 14
50636-232 195 16 121 92 8 34 34 34 106 106 106
50637-221 221 221 253 253 253 253 253 253 253 253 253
50638-253 253 253 253 253 253 253 253 253 253 253 253
50639-253 253 253 253 253 253 253 253 253 253 253 253
50640-253 253 253 253 253 253 253 253 253 253 253 253
50641-242 242 242 82 82 82 18 14 6 163 110 8
50642-216 158 10 236 178 12 242 186 14 246 190 14
50643-246 190 14 246 190 14 246 190 14 246 190 14
50644-246 190 14 246 190 14 246 190 14 246 190 14
50645-246 190 14 246 190 14 246 190 14 246 190 14
50646-246 190 14 246 190 14 242 186 14 163 133 67
50647- 46 46 46 18 18 18 6 6 6 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 0 0 0
50650- 0 0 0 0 0 0 0 0 0 10 10 10
50651- 30 30 30 78 78 78 163 133 67 210 150 10
50652-236 178 12 246 186 14 246 190 14 246 190 14
50653-246 190 14 246 190 14 246 190 14 246 190 14
50654-246 190 14 246 190 14 246 190 14 246 190 14
50655-246 190 14 246 190 14 246 190 14 246 190 14
50656-241 196 14 215 174 15 190 178 144 253 253 253
50657-253 253 253 253 253 253 253 253 253 253 253 253
50658-253 253 253 253 253 253 253 253 253 253 253 253
50659-253 253 253 253 253 253 253 253 253 253 253 253
50660-253 253 253 253 253 253 253 253 253 218 218 218
50661- 58 58 58 2 2 6 22 18 6 167 114 7
50662-216 158 10 236 178 12 246 186 14 246 190 14
50663-246 190 14 246 190 14 246 190 14 246 190 14
50664-246 190 14 246 190 14 246 190 14 246 190 14
50665-246 190 14 246 190 14 246 190 14 246 190 14
50666-246 190 14 246 186 14 242 186 14 190 150 46
50667- 54 54 54 22 22 22 6 6 6 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 0 0 0
50670- 0 0 0 0 0 0 0 0 0 14 14 14
50671- 38 38 38 86 86 86 180 133 36 213 154 11
50672-236 178 12 246 186 14 246 190 14 246 190 14
50673-246 190 14 246 190 14 246 190 14 246 190 14
50674-246 190 14 246 190 14 246 190 14 246 190 14
50675-246 190 14 246 190 14 246 190 14 246 190 14
50676-246 190 14 232 195 16 190 146 13 214 214 214
50677-253 253 253 253 253 253 253 253 253 253 253 253
50678-253 253 253 253 253 253 253 253 253 253 253 253
50679-253 253 253 253 253 253 253 253 253 253 253 253
50680-253 253 253 250 250 250 170 170 170 26 26 26
50681- 2 2 6 2 2 6 37 26 9 163 110 8
50682-219 162 10 239 182 13 246 186 14 246 190 14
50683-246 190 14 246 190 14 246 190 14 246 190 14
50684-246 190 14 246 190 14 246 190 14 246 190 14
50685-246 190 14 246 190 14 246 190 14 246 190 14
50686-246 186 14 236 178 12 224 166 10 142 122 72
50687- 46 46 46 18 18 18 6 6 6 0 0 0
50688- 0 0 0 0 0 0 0 0 0 0 0 0
50689- 0 0 0 0 0 0 0 0 0 0 0 0
50690- 0 0 0 0 0 0 6 6 6 18 18 18
50691- 50 50 50 109 106 95 192 133 9 224 166 10
50692-242 186 14 246 190 14 246 190 14 246 190 14
50693-246 190 14 246 190 14 246 190 14 246 190 14
50694-246 190 14 246 190 14 246 190 14 246 190 14
50695-246 190 14 246 190 14 246 190 14 246 190 14
50696-242 186 14 226 184 13 210 162 10 142 110 46
50697-226 226 226 253 253 253 253 253 253 253 253 253
50698-253 253 253 253 253 253 253 253 253 253 253 253
50699-253 253 253 253 253 253 253 253 253 253 253 253
50700-198 198 198 66 66 66 2 2 6 2 2 6
50701- 2 2 6 2 2 6 50 34 6 156 107 11
50702-219 162 10 239 182 13 246 186 14 246 190 14
50703-246 190 14 246 190 14 246 190 14 246 190 14
50704-246 190 14 246 190 14 246 190 14 246 190 14
50705-246 190 14 246 190 14 246 190 14 242 186 14
50706-234 174 13 213 154 11 154 122 46 66 66 66
50707- 30 30 30 10 10 10 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 0 0 0 0 0 0
50710- 0 0 0 0 0 0 6 6 6 22 22 22
50711- 58 58 58 154 121 60 206 145 10 234 174 13
50712-242 186 14 246 186 14 246 190 14 246 190 14
50713-246 190 14 246 190 14 246 190 14 246 190 14
50714-246 190 14 246 190 14 246 190 14 246 190 14
50715-246 190 14 246 190 14 246 190 14 246 190 14
50716-246 186 14 236 178 12 210 162 10 163 110 8
50717- 61 42 6 138 138 138 218 218 218 250 250 250
50718-253 253 253 253 253 253 253 253 253 250 250 250
50719-242 242 242 210 210 210 144 144 144 66 66 66
50720- 6 6 6 2 2 6 2 2 6 2 2 6
50721- 2 2 6 2 2 6 61 42 6 163 110 8
50722-216 158 10 236 178 12 246 190 14 246 190 14
50723-246 190 14 246 190 14 246 190 14 246 190 14
50724-246 190 14 246 190 14 246 190 14 246 190 14
50725-246 190 14 239 182 13 230 174 11 216 158 10
50726-190 142 34 124 112 88 70 70 70 38 38 38
50727- 18 18 18 6 6 6 0 0 0 0 0 0
50728- 0 0 0 0 0 0 0 0 0 0 0 0
50729- 0 0 0 0 0 0 0 0 0 0 0 0
50730- 0 0 0 0 0 0 6 6 6 22 22 22
50731- 62 62 62 168 124 44 206 145 10 224 166 10
50732-236 178 12 239 182 13 242 186 14 242 186 14
50733-246 186 14 246 190 14 246 190 14 246 190 14
50734-246 190 14 246 190 14 246 190 14 246 190 14
50735-246 190 14 246 190 14 246 190 14 246 190 14
50736-246 190 14 236 178 12 216 158 10 175 118 6
50737- 80 54 7 2 2 6 6 6 6 30 30 30
50738- 54 54 54 62 62 62 50 50 50 38 38 38
50739- 14 14 14 2 2 6 2 2 6 2 2 6
50740- 2 2 6 2 2 6 2 2 6 2 2 6
50741- 2 2 6 6 6 6 80 54 7 167 114 7
50742-213 154 11 236 178 12 246 190 14 246 190 14
50743-246 190 14 246 190 14 246 190 14 246 190 14
50744-246 190 14 242 186 14 239 182 13 239 182 13
50745-230 174 11 210 150 10 174 135 50 124 112 88
50746- 82 82 82 54 54 54 34 34 34 18 18 18
50747- 6 6 6 0 0 0 0 0 0 0 0 0
50748- 0 0 0 0 0 0 0 0 0 0 0 0
50749- 0 0 0 0 0 0 0 0 0 0 0 0
50750- 0 0 0 0 0 0 6 6 6 18 18 18
50751- 50 50 50 158 118 36 192 133 9 200 144 11
50752-216 158 10 219 162 10 224 166 10 226 170 11
50753-230 174 11 236 178 12 239 182 13 239 182 13
50754-242 186 14 246 186 14 246 190 14 246 190 14
50755-246 190 14 246 190 14 246 190 14 246 190 14
50756-246 186 14 230 174 11 210 150 10 163 110 8
50757-104 69 6 10 10 10 2 2 6 2 2 6
50758- 2 2 6 2 2 6 2 2 6 2 2 6
50759- 2 2 6 2 2 6 2 2 6 2 2 6
50760- 2 2 6 2 2 6 2 2 6 2 2 6
50761- 2 2 6 6 6 6 91 60 6 167 114 7
50762-206 145 10 230 174 11 242 186 14 246 190 14
50763-246 190 14 246 190 14 246 186 14 242 186 14
50764-239 182 13 230 174 11 224 166 10 213 154 11
50765-180 133 36 124 112 88 86 86 86 58 58 58
50766- 38 38 38 22 22 22 10 10 10 6 6 6
50767- 0 0 0 0 0 0 0 0 0 0 0 0
50768- 0 0 0 0 0 0 0 0 0 0 0 0
50769- 0 0 0 0 0 0 0 0 0 0 0 0
50770- 0 0 0 0 0 0 0 0 0 14 14 14
50771- 34 34 34 70 70 70 138 110 50 158 118 36
50772-167 114 7 180 123 7 192 133 9 197 138 11
50773-200 144 11 206 145 10 213 154 11 219 162 10
50774-224 166 10 230 174 11 239 182 13 242 186 14
50775-246 186 14 246 186 14 246 186 14 246 186 14
50776-239 182 13 216 158 10 185 133 11 152 99 6
50777-104 69 6 18 14 6 2 2 6 2 2 6
50778- 2 2 6 2 2 6 2 2 6 2 2 6
50779- 2 2 6 2 2 6 2 2 6 2 2 6
50780- 2 2 6 2 2 6 2 2 6 2 2 6
50781- 2 2 6 6 6 6 80 54 7 152 99 6
50782-192 133 9 219 162 10 236 178 12 239 182 13
50783-246 186 14 242 186 14 239 182 13 236 178 12
50784-224 166 10 206 145 10 192 133 9 154 121 60
50785- 94 94 94 62 62 62 42 42 42 22 22 22
50786- 14 14 14 6 6 6 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 0 0 0
50789- 0 0 0 0 0 0 0 0 0 0 0 0
50790- 0 0 0 0 0 0 0 0 0 6 6 6
50791- 18 18 18 34 34 34 58 58 58 78 78 78
50792-101 98 89 124 112 88 142 110 46 156 107 11
50793-163 110 8 167 114 7 175 118 6 180 123 7
50794-185 133 11 197 138 11 210 150 10 219 162 10
50795-226 170 11 236 178 12 236 178 12 234 174 13
50796-219 162 10 197 138 11 163 110 8 130 83 6
50797- 91 60 6 10 10 10 2 2 6 2 2 6
50798- 18 18 18 38 38 38 38 38 38 38 38 38
50799- 38 38 38 38 38 38 38 38 38 38 38 38
50800- 38 38 38 38 38 38 26 26 26 2 2 6
50801- 2 2 6 6 6 6 70 47 6 137 92 6
50802-175 118 6 200 144 11 219 162 10 230 174 11
50803-234 174 13 230 174 11 219 162 10 210 150 10
50804-192 133 9 163 110 8 124 112 88 82 82 82
50805- 50 50 50 30 30 30 14 14 14 6 6 6
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 0 0 0 0 0 0
50809- 0 0 0 0 0 0 0 0 0 0 0 0
50810- 0 0 0 0 0 0 0 0 0 0 0 0
50811- 6 6 6 14 14 14 22 22 22 34 34 34
50812- 42 42 42 58 58 58 74 74 74 86 86 86
50813-101 98 89 122 102 70 130 98 46 121 87 25
50814-137 92 6 152 99 6 163 110 8 180 123 7
50815-185 133 11 197 138 11 206 145 10 200 144 11
50816-180 123 7 156 107 11 130 83 6 104 69 6
50817- 50 34 6 54 54 54 110 110 110 101 98 89
50818- 86 86 86 82 82 82 78 78 78 78 78 78
50819- 78 78 78 78 78 78 78 78 78 78 78 78
50820- 78 78 78 82 82 82 86 86 86 94 94 94
50821-106 106 106 101 101 101 86 66 34 124 80 6
50822-156 107 11 180 123 7 192 133 9 200 144 11
50823-206 145 10 200 144 11 192 133 9 175 118 6
50824-139 102 15 109 106 95 70 70 70 42 42 42
50825- 22 22 22 10 10 10 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 0 0 0 0 0 0 0 0 0
50829- 0 0 0 0 0 0 0 0 0 0 0 0
50830- 0 0 0 0 0 0 0 0 0 0 0 0
50831- 0 0 0 0 0 0 6 6 6 10 10 10
50832- 14 14 14 22 22 22 30 30 30 38 38 38
50833- 50 50 50 62 62 62 74 74 74 90 90 90
50834-101 98 89 112 100 78 121 87 25 124 80 6
50835-137 92 6 152 99 6 152 99 6 152 99 6
50836-138 86 6 124 80 6 98 70 6 86 66 30
50837-101 98 89 82 82 82 58 58 58 46 46 46
50838- 38 38 38 34 34 34 34 34 34 34 34 34
50839- 34 34 34 34 34 34 34 34 34 34 34 34
50840- 34 34 34 34 34 34 38 38 38 42 42 42
50841- 54 54 54 82 82 82 94 86 76 91 60 6
50842-134 86 6 156 107 11 167 114 7 175 118 6
50843-175 118 6 167 114 7 152 99 6 121 87 25
50844-101 98 89 62 62 62 34 34 34 18 18 18
50845- 6 6 6 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- 0 0 0 0 0 0 0 0 0 0 0 0
50849- 0 0 0 0 0 0 0 0 0 0 0 0
50850- 0 0 0 0 0 0 0 0 0 0 0 0
50851- 0 0 0 0 0 0 0 0 0 0 0 0
50852- 0 0 0 6 6 6 6 6 6 10 10 10
50853- 18 18 18 22 22 22 30 30 30 42 42 42
50854- 50 50 50 66 66 66 86 86 86 101 98 89
50855-106 86 58 98 70 6 104 69 6 104 69 6
50856-104 69 6 91 60 6 82 62 34 90 90 90
50857- 62 62 62 38 38 38 22 22 22 14 14 14
50858- 10 10 10 10 10 10 10 10 10 10 10 10
50859- 10 10 10 10 10 10 6 6 6 10 10 10
50860- 10 10 10 10 10 10 10 10 10 14 14 14
50861- 22 22 22 42 42 42 70 70 70 89 81 66
50862- 80 54 7 104 69 6 124 80 6 137 92 6
50863-134 86 6 116 81 8 100 82 52 86 86 86
50864- 58 58 58 30 30 30 14 14 14 6 6 6
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- 0 0 0 0 0 0 0 0 0 0 0 0
50869- 0 0 0 0 0 0 0 0 0 0 0 0
50870- 0 0 0 0 0 0 0 0 0 0 0 0
50871- 0 0 0 0 0 0 0 0 0 0 0 0
50872- 0 0 0 0 0 0 0 0 0 0 0 0
50873- 0 0 0 6 6 6 10 10 10 14 14 14
50874- 18 18 18 26 26 26 38 38 38 54 54 54
50875- 70 70 70 86 86 86 94 86 76 89 81 66
50876- 89 81 66 86 86 86 74 74 74 50 50 50
50877- 30 30 30 14 14 14 6 6 6 0 0 0
50878- 0 0 0 0 0 0 0 0 0 0 0 0
50879- 0 0 0 0 0 0 0 0 0 0 0 0
50880- 0 0 0 0 0 0 0 0 0 0 0 0
50881- 6 6 6 18 18 18 34 34 34 58 58 58
50882- 82 82 82 89 81 66 89 81 66 89 81 66
50883- 94 86 66 94 86 76 74 74 74 50 50 50
50884- 26 26 26 14 14 14 6 6 6 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- 0 0 0 0 0 0 0 0 0 0 0 0
50889- 0 0 0 0 0 0 0 0 0 0 0 0
50890- 0 0 0 0 0 0 0 0 0 0 0 0
50891- 0 0 0 0 0 0 0 0 0 0 0 0
50892- 0 0 0 0 0 0 0 0 0 0 0 0
50893- 0 0 0 0 0 0 0 0 0 0 0 0
50894- 6 6 6 6 6 6 14 14 14 18 18 18
50895- 30 30 30 38 38 38 46 46 46 54 54 54
50896- 50 50 50 42 42 42 30 30 30 18 18 18
50897- 10 10 10 0 0 0 0 0 0 0 0 0
50898- 0 0 0 0 0 0 0 0 0 0 0 0
50899- 0 0 0 0 0 0 0 0 0 0 0 0
50900- 0 0 0 0 0 0 0 0 0 0 0 0
50901- 0 0 0 6 6 6 14 14 14 26 26 26
50902- 38 38 38 50 50 50 58 58 58 58 58 58
50903- 54 54 54 42 42 42 30 30 30 18 18 18
50904- 10 10 10 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 0 0 0
50908- 0 0 0 0 0 0 0 0 0 0 0 0
50909- 0 0 0 0 0 0 0 0 0 0 0 0
50910- 0 0 0 0 0 0 0 0 0 0 0 0
50911- 0 0 0 0 0 0 0 0 0 0 0 0
50912- 0 0 0 0 0 0 0 0 0 0 0 0
50913- 0 0 0 0 0 0 0 0 0 0 0 0
50914- 0 0 0 0 0 0 0 0 0 6 6 6
50915- 6 6 6 10 10 10 14 14 14 18 18 18
50916- 18 18 18 14 14 14 10 10 10 6 6 6
50917- 0 0 0 0 0 0 0 0 0 0 0 0
50918- 0 0 0 0 0 0 0 0 0 0 0 0
50919- 0 0 0 0 0 0 0 0 0 0 0 0
50920- 0 0 0 0 0 0 0 0 0 0 0 0
50921- 0 0 0 0 0 0 0 0 0 6 6 6
50922- 14 14 14 18 18 18 22 22 22 22 22 22
50923- 18 18 18 14 14 14 10 10 10 6 6 6
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 0 0 0
50928- 0 0 0 0 0 0 0 0 0 0 0 0
50929+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50930+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50931+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50932+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50933+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50934+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50935+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50936+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50937+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50938+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50939+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50940+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50941+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50942+4 4 4 4 4 4
50943+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50944+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50945+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50946+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50947+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50948+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50949+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50950+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50951+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50952+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50953+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50954+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50955+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50956+4 4 4 4 4 4
50957+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50958+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50959+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50960+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50961+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50962+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50963+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50964+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50965+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50966+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50967+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50968+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50969+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50970+4 4 4 4 4 4
50971+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50972+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50973+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50974+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50975+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50976+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50977+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50978+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50979+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50980+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50981+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50982+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50983+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50984+4 4 4 4 4 4
50985+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50986+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50987+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50988+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50989+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50990+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50991+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50992+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50993+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50994+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50995+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50996+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50997+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50998+4 4 4 4 4 4
50999+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51000+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51001+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51002+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51003+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51004+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51005+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51006+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51007+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51008+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51009+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51010+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51011+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51012+4 4 4 4 4 4
51013+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51014+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51015+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51016+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51017+4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
51018+0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
51019+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51020+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51021+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51022+4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
51023+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
51024+4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
51025+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51026+4 4 4 4 4 4
51027+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51028+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51029+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51030+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51031+4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
51032+37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
51033+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51034+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51035+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51036+4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
51037+2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
51038+4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
51039+1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51040+4 4 4 4 4 4
51041+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51042+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51043+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51044+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51045+2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
51046+153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
51047+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
51048+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51049+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51050+4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
51051+60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
51052+4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
51053+2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
51054+4 4 4 4 4 4
51055+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51056+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51057+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51058+4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
51059+4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
51060+165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
51061+1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
51062+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51063+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
51064+3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
51065+163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
51066+0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
51067+37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
51068+4 4 4 4 4 4
51069+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51070+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51071+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51072+4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
51073+37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
51074+156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
51075+125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
51076+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
51077+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
51078+0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
51079+174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
51080+0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
51081+64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
51082+4 4 4 4 4 4
51083+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51084+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51085+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
51086+5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
51087+156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
51088+156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
51089+174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
51090+1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
51091+4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
51092+13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
51093+174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
51094+22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
51095+90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
51096+4 4 4 4 4 4
51097+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51098+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51099+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
51100+0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
51101+174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
51102+156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
51103+163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
51104+4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
51105+5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
51106+131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
51107+190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
51108+90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
51109+31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
51110+4 4 4 4 4 4
51111+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51112+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51113+4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
51114+4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
51115+155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
51116+167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
51117+153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
51118+41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
51119+1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
51120+177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
51121+125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
51122+136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
51123+7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
51124+4 4 4 4 4 4
51125+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51126+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51127+4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
51128+125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
51129+156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
51130+137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
51131+156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
51132+167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
51133+0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
51134+166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
51135+6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
51136+90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
51137+1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
51138+4 4 4 4 4 4
51139+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51140+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51141+1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
51142+167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
51143+157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
51144+26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
51145+158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
51146+165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
51147+60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
51148+137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
51149+52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
51150+13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
51151+4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
51152+4 4 4 4 4 4
51153+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51154+4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
51155+0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
51156+158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
51157+167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
51158+4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
51159+174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
51160+155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
51161+137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
51162+16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
51163+136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
51164+2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
51165+4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
51166+4 4 4 4 4 4
51167+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51168+4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
51169+37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
51170+157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
51171+153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
51172+4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
51173+125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
51174+156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
51175+174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
51176+4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
51177+136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
51178+1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
51179+2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
51180+0 0 0 4 4 4
51181+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
51182+4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
51183+158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
51184+153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
51185+37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
51186+4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
51187+4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
51188+154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
51189+174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
51190+32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
51191+28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
51192+50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
51193+0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
51194+2 0 0 0 0 0
51195+4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
51196+0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
51197+174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
51198+165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
51199+4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
51200+4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
51201+4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
51202+174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
51203+60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
51204+136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
51205+22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
51206+136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
51207+26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
51208+37 38 37 0 0 0
51209+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
51210+13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
51211+153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
51212+177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
51213+4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
51214+5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
51215+6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
51216+166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
51217+4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
51218+146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
51219+71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
51220+90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
51221+125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
51222+85 115 134 4 0 0
51223+4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
51224+125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
51225+155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
51226+125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
51227+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
51228+0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
51229+5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
51230+37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
51231+4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
51232+90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
51233+2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
51234+13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
51235+166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
51236+60 73 81 4 0 0
51237+4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
51238+174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
51239+156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
51240+4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
51241+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
51242+10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
51243+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
51244+4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
51245+80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
51246+28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
51247+50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
51248+1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
51249+167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
51250+16 19 21 4 0 0
51251+4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
51252+158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
51253+167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
51254+4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
51255+4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
51256+80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
51257+4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
51258+3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
51259+146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
51260+68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
51261+136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
51262+24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
51263+163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
51264+4 0 0 4 3 3
51265+3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
51266+156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
51267+155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
51268+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
51269+2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
51270+136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
51271+0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
51272+0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
51273+136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
51274+28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
51275+22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
51276+137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
51277+60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
51278+3 2 2 4 4 4
51279+3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
51280+157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
51281+37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
51282+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
51283+0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
51284+101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
51285+14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
51286+22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
51287+136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
51288+17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
51289+2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
51290+166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
51291+13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
51292+4 4 4 4 4 4
51293+1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
51294+163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
51295+4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
51296+4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
51297+40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
51298+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
51299+101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
51300+136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
51301+136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
51302+136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
51303+3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
51304+174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
51305+4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
51306+4 4 4 4 4 4
51307+4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
51308+155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
51309+4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
51310+4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
51311+101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
51312+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
51313+136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
51314+136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
51315+136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
51316+90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
51317+85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
51318+167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
51319+6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
51320+5 5 5 5 5 5
51321+1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
51322+131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
51323+6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
51324+0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
51325+101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
51326+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
51327+101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
51328+136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
51329+101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
51330+7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
51331+174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
51332+24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
51333+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
51334+5 5 5 4 4 4
51335+4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
51336+131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
51337+6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
51338+13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
51339+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
51340+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
51341+101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
51342+136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
51343+136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
51344+2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
51345+174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
51346+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
51347+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51348+4 4 4 4 4 4
51349+1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
51350+137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
51351+4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
51352+64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
51353+90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
51354+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
51355+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
51356+136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
51357+101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
51358+37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
51359+167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
51360+3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
51361+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51362+4 4 4 4 4 4
51363+4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
51364+153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
51365+4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
51366+90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
51367+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
51368+90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
51369+101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
51370+101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
51371+35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
51372+154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
51373+60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
51374+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51375+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51376+4 4 4 4 4 4
51377+1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
51378+153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
51379+4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
51380+64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
51381+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
51382+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
51383+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
51384+136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
51385+13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
51386+174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
51387+6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
51388+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51389+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51390+4 4 4 4 4 4
51391+4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
51392+156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
51393+4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
51394+90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
51395+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
51396+90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
51397+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
51398+101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
51399+2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
51400+174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
51401+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51402+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51403+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51404+4 4 4 4 4 4
51405+3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
51406+158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
51407+4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
51408+37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
51409+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
51410+90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
51411+101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
51412+90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
51413+5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
51414+167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
51415+6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
51416+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51417+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51418+4 4 4 4 4 4
51419+4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
51420+163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
51421+4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
51422+18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
51423+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
51424+90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
51425+101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
51426+13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
51427+3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
51428+174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
51429+4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
51430+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51431+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51432+4 4 4 4 4 4
51433+1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
51434+167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
51435+4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
51436+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
51437+26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
51438+90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
51439+101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
51440+7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
51441+4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
51442+174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
51443+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51444+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51445+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51446+4 4 4 4 4 4
51447+4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
51448+174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
51449+5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
51450+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
51451+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
51452+90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
51453+101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
51454+2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
51455+3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
51456+153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
51457+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51458+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51459+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51460+4 4 4 4 4 4
51461+1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
51462+174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
51463+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
51464+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
51465+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
51466+26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
51467+35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
51468+2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
51469+3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
51470+131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
51471+4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51472+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51473+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51474+4 4 4 4 4 4
51475+3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
51476+174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
51477+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
51478+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
51479+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
51480+26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
51481+7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
51482+4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
51483+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
51484+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51485+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51486+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51487+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51488+4 4 4 4 4 4
51489+1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
51490+174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
51491+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
51492+18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
51493+18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
51494+26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
51495+28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
51496+3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
51497+4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
51498+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51499+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51500+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51501+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51502+4 4 4 4 4 4
51503+4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
51504+174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
51505+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
51506+10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
51507+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
51508+18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
51509+90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
51510+3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
51511+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
51512+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51513+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51514+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51515+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51516+4 4 4 4 4 4
51517+1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
51518+177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
51519+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
51520+10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
51521+26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
51522+6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
51523+10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
51524+2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
51525+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
51526+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51527+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51528+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51529+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51530+4 4 4 4 4 4
51531+4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
51532+177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
51533+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
51534+10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
51535+26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
51536+7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
51537+3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
51538+21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
51539+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
51540+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51541+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51542+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51543+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51544+4 4 4 4 4 4
51545+3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
51546+190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
51547+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
51548+10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
51549+24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
51550+18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
51551+28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
51552+26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
51553+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
51554+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51555+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51556+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51557+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51558+4 4 4 4 4 4
51559+4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
51560+190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
51561+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
51562+10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
51563+0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
51564+26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
51565+37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
51566+90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
51567+4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
51568+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51569+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51570+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51571+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51572+4 4 4 4 4 4
51573+4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
51574+193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
51575+5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
51576+10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
51577+1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
51578+26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
51579+22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
51580+26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
51581+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
51582+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51583+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51584+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51585+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51586+4 4 4 4 4 4
51587+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
51588+190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
51589+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
51590+10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
51591+2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
51592+26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
51593+10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
51594+26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
51595+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
51596+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51597+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51598+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51599+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51600+4 4 4 4 4 4
51601+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
51602+193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
51603+5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
51604+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
51605+13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
51606+10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
51607+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
51608+26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
51609+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
51610+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51611+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51612+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51613+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51614+4 4 4 4 4 4
51615+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
51616+190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
51617+5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
51618+28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
51619+10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
51620+28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
51621+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
51622+26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
51623+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
51624+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51625+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51626+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51627+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51628+4 4 4 4 4 4
51629+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
51630+193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
51631+5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
51632+4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
51633+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
51634+10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
51635+18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
51636+22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
51637+4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
51638+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51639+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51640+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51641+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51642+4 4 4 4 4 4
51643+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
51644+190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
51645+6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
51646+1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
51647+18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
51648+10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
51649+26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
51650+1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
51651+5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
51652+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51653+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51654+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51655+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51656+4 4 4 4 4 4
51657+4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
51658+193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
51659+2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
51660+4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
51661+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
51662+10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
51663+26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
51664+2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
51665+3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
51666+131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51667+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51668+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51669+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51670+4 4 4 4 4 4
51671+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
51672+193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
51673+0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
51674+4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
51675+13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
51676+10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
51677+28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
51678+4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
51679+0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
51680+125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51681+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51682+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51683+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51684+4 4 4 4 4 4
51685+4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
51686+193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
51687+120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
51688+4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
51689+4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
51690+10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
51691+4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
51692+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
51693+24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
51694+125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
51695+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51696+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51697+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51698+4 4 4 4 4 4
51699+4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
51700+174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
51701+220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
51702+3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
51703+4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
51704+10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
51705+1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
51706+5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
51707+137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
51708+125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
51709+0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51710+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51711+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51712+4 4 4 4 4 4
51713+5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
51714+193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
51715+220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
51716+4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
51717+4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
51718+22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
51719+4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51720+1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
51721+166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
51722+125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
51723+4 3 3 5 5 5 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
51727+4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
51728+220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
51729+205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
51730+24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
51731+4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
51732+4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
51733+4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
51734+2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
51735+156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
51736+137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
51737+5 5 5 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
51741+5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
51742+125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
51743+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
51744+193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
51745+5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
51746+1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
51747+5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
51748+60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
51749+153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
51750+125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
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
51755+4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
51756+6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
51757+193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
51758+244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
51759+0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
51760+4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
51761+3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
51762+220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
51763+153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
51764+13 16 17 4 0 0 4 0 0 4 3 3 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
51769+5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
51770+6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
51771+244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
51772+220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
51773+3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
51774+4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
51775+0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
51776+177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
51777+158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
51778+4 0 0 4 0 0 5 5 5 5 5 5 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
51783+5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
51784+6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
51785+177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
51786+220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
51787+125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
51788+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
51789+37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
51790+174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
51791+158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
51792+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
51793+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51794+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51795+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51796+4 4 4 4 4 4
51797+4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
51798+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
51799+26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
51800+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
51801+244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
51802+0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
51803+177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
51804+174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
51805+60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
51806+4 4 4 4 4 4 4 4 4 4 4 4 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
51811+5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
51812+6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
51813+6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
51814+220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
51815+220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
51816+0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
51817+220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
51818+174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
51819+4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
51820+4 4 4 4 4 4 4 4 4 4 4 4 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
51825+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
51826+6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
51827+4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
51828+220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
51829+205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
51830+60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
51831+177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
51832+190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
51833+4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51834+4 4 4 4 4 4 4 4 4 4 4 4 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
51839+4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
51840+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
51841+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
51842+125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
51843+205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
51844+193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
51845+190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
51846+153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
51847+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51848+4 4 4 4 4 4 4 4 4 4 4 4 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
51853+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
51854+6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
51855+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
51856+4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
51857+205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
51858+220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
51859+174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
51860+6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
51861+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51862+4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4
51867+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
51868+5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
51869+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
51870+4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
51871+220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
51872+190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
51873+193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
51874+4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
51875+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51876+4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4
51880+4 4 4 4 4 4
51881+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51882+4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
51883+4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
51884+6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
51885+174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
51886+193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
51887+193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
51888+6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
51889+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51890+4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4
51894+4 4 4 4 4 4
51895+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51896+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
51897+5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
51898+5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
51899+6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
51900+193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
51901+60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
51902+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
51903+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51904+4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4
51908+4 4 4 4 4 4
51909+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51910+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51911+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
51912+5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
51913+4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
51914+193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
51915+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
51916+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
51917+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51918+4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51922+4 4 4 4 4 4
51923+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51924+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51925+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
51926+4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
51927+6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
51928+153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
51929+6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
51930+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51931+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51932+4 4 4 4 4 4 4 4 4 4 4 4 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+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51936+4 4 4 4 4 4
51937+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51938+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51939+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51940+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
51941+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
51942+24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
51943+6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
51944+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51945+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51946+4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4
51949+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51950+4 4 4 4 4 4
51951+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51952+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51953+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51954+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
51955+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
51956+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
51957+4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
51958+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51959+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51960+4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51963+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51964+4 4 4 4 4 4
51965+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51966+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51967+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51968+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
51969+5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
51970+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
51971+6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
51972+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51973+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51974+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51975+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51976+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51977+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51978+4 4 4 4 4 4
51979+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51980+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51981+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51982+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
51983+4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
51984+4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
51985+6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51986+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51987+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51988+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51989+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51990+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51991+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51992+4 4 4 4 4 4
51993+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51994+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51995+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51996+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51997+4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
51998+6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
51999+4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
52000+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52001+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52002+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52003+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52004+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52005+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52006+4 4 4 4 4 4
52007+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52008+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52009+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52010+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52011+4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
52012+4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
52013+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52014+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52015+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52016+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52017+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52018+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52019+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52020+4 4 4 4 4 4
52021+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52022+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52023+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52024+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52025+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
52026+5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
52027+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52028+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52029+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52030+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52031+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52032+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52033+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52034+4 4 4 4 4 4
52035+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52036+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52037+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52038+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52039+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
52040+5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
52041+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52042+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52043+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52044+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52045+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52046+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52047+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
52048+4 4 4 4 4 4
52049diff --git a/drivers/video/mb862xx/mb862xxfb_accel.c b/drivers/video/mb862xx/mb862xxfb_accel.c
52050index fe92eed..106e085 100644
52051--- a/drivers/video/mb862xx/mb862xxfb_accel.c
52052+++ b/drivers/video/mb862xx/mb862xxfb_accel.c
52053@@ -312,14 +312,18 @@ void mb862xxfb_init_accel(struct fb_info *info, int xres)
52054 struct mb862xxfb_par *par = info->par;
52055
52056 if (info->var.bits_per_pixel == 32) {
52057- info->fbops->fb_fillrect = cfb_fillrect;
52058- info->fbops->fb_copyarea = cfb_copyarea;
52059- info->fbops->fb_imageblit = cfb_imageblit;
52060+ pax_open_kernel();
52061+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
52062+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
52063+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
52064+ pax_close_kernel();
52065 } else {
52066 outreg(disp, GC_L0EM, 3);
52067- info->fbops->fb_fillrect = mb86290fb_fillrect;
52068- info->fbops->fb_copyarea = mb86290fb_copyarea;
52069- info->fbops->fb_imageblit = mb86290fb_imageblit;
52070+ pax_open_kernel();
52071+ *(void **)&info->fbops->fb_fillrect = mb86290fb_fillrect;
52072+ *(void **)&info->fbops->fb_copyarea = mb86290fb_copyarea;
52073+ *(void **)&info->fbops->fb_imageblit = mb86290fb_imageblit;
52074+ pax_close_kernel();
52075 }
52076 outreg(draw, GDC_REG_DRAW_BASE, 0);
52077 outreg(draw, GDC_REG_MODE_MISC, 0x8000);
52078diff --git a/drivers/video/nvidia/nvidia.c b/drivers/video/nvidia/nvidia.c
52079index ff22871..b129bed 100644
52080--- a/drivers/video/nvidia/nvidia.c
52081+++ b/drivers/video/nvidia/nvidia.c
52082@@ -669,19 +669,23 @@ static int nvidiafb_set_par(struct fb_info *info)
52083 info->fix.line_length = (info->var.xres_virtual *
52084 info->var.bits_per_pixel) >> 3;
52085 if (info->var.accel_flags) {
52086- info->fbops->fb_imageblit = nvidiafb_imageblit;
52087- info->fbops->fb_fillrect = nvidiafb_fillrect;
52088- info->fbops->fb_copyarea = nvidiafb_copyarea;
52089- info->fbops->fb_sync = nvidiafb_sync;
52090+ pax_open_kernel();
52091+ *(void **)&info->fbops->fb_imageblit = nvidiafb_imageblit;
52092+ *(void **)&info->fbops->fb_fillrect = nvidiafb_fillrect;
52093+ *(void **)&info->fbops->fb_copyarea = nvidiafb_copyarea;
52094+ *(void **)&info->fbops->fb_sync = nvidiafb_sync;
52095+ pax_close_kernel();
52096 info->pixmap.scan_align = 4;
52097 info->flags &= ~FBINFO_HWACCEL_DISABLED;
52098 info->flags |= FBINFO_READS_FAST;
52099 NVResetGraphics(info);
52100 } else {
52101- info->fbops->fb_imageblit = cfb_imageblit;
52102- info->fbops->fb_fillrect = cfb_fillrect;
52103- info->fbops->fb_copyarea = cfb_copyarea;
52104- info->fbops->fb_sync = NULL;
52105+ pax_open_kernel();
52106+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
52107+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
52108+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
52109+ *(void **)&info->fbops->fb_sync = NULL;
52110+ pax_close_kernel();
52111 info->pixmap.scan_align = 1;
52112 info->flags |= FBINFO_HWACCEL_DISABLED;
52113 info->flags &= ~FBINFO_READS_FAST;
52114@@ -1173,8 +1177,11 @@ static int nvidia_set_fbinfo(struct fb_info *info)
52115 info->pixmap.size = 8 * 1024;
52116 info->pixmap.flags = FB_PIXMAP_SYSTEM;
52117
52118- if (!hwcur)
52119- info->fbops->fb_cursor = NULL;
52120+ if (!hwcur) {
52121+ pax_open_kernel();
52122+ *(void **)&info->fbops->fb_cursor = NULL;
52123+ pax_close_kernel();
52124+ }
52125
52126 info->var.accel_flags = (!noaccel);
52127
52128diff --git a/drivers/video/s1d13xxxfb.c b/drivers/video/s1d13xxxfb.c
52129index 05c2dc3..ea1f391 100644
52130--- a/drivers/video/s1d13xxxfb.c
52131+++ b/drivers/video/s1d13xxxfb.c
52132@@ -881,8 +881,10 @@ static int s1d13xxxfb_probe(struct platform_device *pdev)
52133
52134 switch(prod_id) {
52135 case S1D13506_PROD_ID: /* activate acceleration */
52136- s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
52137- s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
52138+ pax_open_kernel();
52139+ *(void **)&s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
52140+ *(void **)&s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
52141+ pax_close_kernel();
52142 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
52143 FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
52144 break;
52145diff --git a/drivers/video/smscufx.c b/drivers/video/smscufx.c
52146index e188ada..aac63c8 100644
52147--- a/drivers/video/smscufx.c
52148+++ b/drivers/video/smscufx.c
52149@@ -1175,7 +1175,9 @@ static int ufx_ops_release(struct fb_info *info, int user)
52150 fb_deferred_io_cleanup(info);
52151 kfree(info->fbdefio);
52152 info->fbdefio = NULL;
52153- info->fbops->fb_mmap = ufx_ops_mmap;
52154+ pax_open_kernel();
52155+ *(void **)&info->fbops->fb_mmap = ufx_ops_mmap;
52156+ pax_close_kernel();
52157 }
52158
52159 pr_debug("released /dev/fb%d user=%d count=%d",
52160diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
52161index d2e5bc3..4cb05d1 100644
52162--- a/drivers/video/udlfb.c
52163+++ b/drivers/video/udlfb.c
52164@@ -623,11 +623,11 @@ static int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
52165 dlfb_urb_completion(urb);
52166
52167 error:
52168- atomic_add(bytes_sent, &dev->bytes_sent);
52169- atomic_add(bytes_identical, &dev->bytes_identical);
52170- atomic_add(width*height*2, &dev->bytes_rendered);
52171+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
52172+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
52173+ atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
52174 end_cycles = get_cycles();
52175- atomic_add(((unsigned int) ((end_cycles - start_cycles)
52176+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
52177 >> 10)), /* Kcycles */
52178 &dev->cpu_kcycles_used);
52179
52180@@ -748,11 +748,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
52181 dlfb_urb_completion(urb);
52182
52183 error:
52184- atomic_add(bytes_sent, &dev->bytes_sent);
52185- atomic_add(bytes_identical, &dev->bytes_identical);
52186- atomic_add(bytes_rendered, &dev->bytes_rendered);
52187+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
52188+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
52189+ atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
52190 end_cycles = get_cycles();
52191- atomic_add(((unsigned int) ((end_cycles - start_cycles)
52192+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
52193 >> 10)), /* Kcycles */
52194 &dev->cpu_kcycles_used);
52195 }
52196@@ -993,7 +993,9 @@ static int dlfb_ops_release(struct fb_info *info, int user)
52197 fb_deferred_io_cleanup(info);
52198 kfree(info->fbdefio);
52199 info->fbdefio = NULL;
52200- info->fbops->fb_mmap = dlfb_ops_mmap;
52201+ pax_open_kernel();
52202+ *(void **)&info->fbops->fb_mmap = dlfb_ops_mmap;
52203+ pax_close_kernel();
52204 }
52205
52206 pr_warn("released /dev/fb%d user=%d count=%d\n",
52207@@ -1376,7 +1378,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
52208 struct fb_info *fb_info = dev_get_drvdata(fbdev);
52209 struct dlfb_data *dev = fb_info->par;
52210 return snprintf(buf, PAGE_SIZE, "%u\n",
52211- atomic_read(&dev->bytes_rendered));
52212+ atomic_read_unchecked(&dev->bytes_rendered));
52213 }
52214
52215 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
52216@@ -1384,7 +1386,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
52217 struct fb_info *fb_info = dev_get_drvdata(fbdev);
52218 struct dlfb_data *dev = fb_info->par;
52219 return snprintf(buf, PAGE_SIZE, "%u\n",
52220- atomic_read(&dev->bytes_identical));
52221+ atomic_read_unchecked(&dev->bytes_identical));
52222 }
52223
52224 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
52225@@ -1392,7 +1394,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
52226 struct fb_info *fb_info = dev_get_drvdata(fbdev);
52227 struct dlfb_data *dev = fb_info->par;
52228 return snprintf(buf, PAGE_SIZE, "%u\n",
52229- atomic_read(&dev->bytes_sent));
52230+ atomic_read_unchecked(&dev->bytes_sent));
52231 }
52232
52233 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
52234@@ -1400,7 +1402,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
52235 struct fb_info *fb_info = dev_get_drvdata(fbdev);
52236 struct dlfb_data *dev = fb_info->par;
52237 return snprintf(buf, PAGE_SIZE, "%u\n",
52238- atomic_read(&dev->cpu_kcycles_used));
52239+ atomic_read_unchecked(&dev->cpu_kcycles_used));
52240 }
52241
52242 static ssize_t edid_show(
52243@@ -1460,10 +1462,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
52244 struct fb_info *fb_info = dev_get_drvdata(fbdev);
52245 struct dlfb_data *dev = fb_info->par;
52246
52247- atomic_set(&dev->bytes_rendered, 0);
52248- atomic_set(&dev->bytes_identical, 0);
52249- atomic_set(&dev->bytes_sent, 0);
52250- atomic_set(&dev->cpu_kcycles_used, 0);
52251+ atomic_set_unchecked(&dev->bytes_rendered, 0);
52252+ atomic_set_unchecked(&dev->bytes_identical, 0);
52253+ atomic_set_unchecked(&dev->bytes_sent, 0);
52254+ atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
52255
52256 return count;
52257 }
52258diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
52259index 7aec6f3..e3b2d55 100644
52260--- a/drivers/video/uvesafb.c
52261+++ b/drivers/video/uvesafb.c
52262@@ -19,6 +19,7 @@
52263 #include <linux/io.h>
52264 #include <linux/mutex.h>
52265 #include <linux/slab.h>
52266+#include <linux/moduleloader.h>
52267 #include <video/edid.h>
52268 #include <video/uvesafb.h>
52269 #ifdef CONFIG_X86
52270@@ -566,10 +567,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
52271 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
52272 par->pmi_setpal = par->ypan = 0;
52273 } else {
52274+
52275+#ifdef CONFIG_PAX_KERNEXEC
52276+#ifdef CONFIG_MODULES
52277+ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
52278+#endif
52279+ if (!par->pmi_code) {
52280+ par->pmi_setpal = par->ypan = 0;
52281+ return 0;
52282+ }
52283+#endif
52284+
52285 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
52286 + task->t.regs.edi);
52287+
52288+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
52289+ pax_open_kernel();
52290+ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
52291+ pax_close_kernel();
52292+
52293+ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
52294+ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
52295+#else
52296 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
52297 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
52298+#endif
52299+
52300 printk(KERN_INFO "uvesafb: protected mode interface info at "
52301 "%04x:%04x\n",
52302 (u16)task->t.regs.es, (u16)task->t.regs.edi);
52303@@ -814,13 +837,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
52304 par->ypan = ypan;
52305
52306 if (par->pmi_setpal || par->ypan) {
52307+#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
52308 if (__supported_pte_mask & _PAGE_NX) {
52309 par->pmi_setpal = par->ypan = 0;
52310 printk(KERN_WARNING "uvesafb: NX protection is active, "
52311 "better not use the PMI.\n");
52312- } else {
52313+ } else
52314+#endif
52315 uvesafb_vbe_getpmi(task, par);
52316- }
52317 }
52318 #else
52319 /* The protected mode interface is not available on non-x86. */
52320@@ -1454,8 +1478,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
52321 info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;
52322
52323 /* Disable blanking if the user requested so. */
52324- if (!blank)
52325- info->fbops->fb_blank = NULL;
52326+ if (!blank) {
52327+ pax_open_kernel();
52328+ *(void **)&info->fbops->fb_blank = NULL;
52329+ pax_close_kernel();
52330+ }
52331
52332 /*
52333 * Find out how much IO memory is required for the mode with
52334@@ -1531,8 +1558,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
52335 info->flags = FBINFO_FLAG_DEFAULT |
52336 (par->ypan ? FBINFO_HWACCEL_YPAN : 0);
52337
52338- if (!par->ypan)
52339- info->fbops->fb_pan_display = NULL;
52340+ if (!par->ypan) {
52341+ pax_open_kernel();
52342+ *(void **)&info->fbops->fb_pan_display = NULL;
52343+ pax_close_kernel();
52344+ }
52345 }
52346
52347 static void uvesafb_init_mtrr(struct fb_info *info)
52348@@ -1796,6 +1826,11 @@ out:
52349 if (par->vbe_modes)
52350 kfree(par->vbe_modes);
52351
52352+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
52353+ if (par->pmi_code)
52354+ module_free_exec(NULL, par->pmi_code);
52355+#endif
52356+
52357 framebuffer_release(info);
52358 return err;
52359 }
52360@@ -1823,6 +1858,12 @@ static int uvesafb_remove(struct platform_device *dev)
52361 kfree(par->vbe_state_orig);
52362 if (par->vbe_state_saved)
52363 kfree(par->vbe_state_saved);
52364+
52365+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
52366+ if (par->pmi_code)
52367+ module_free_exec(NULL, par->pmi_code);
52368+#endif
52369+
52370 }
52371
52372 framebuffer_release(info);
52373diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
52374index bd83233..7d8a5aa 100644
52375--- a/drivers/video/vesafb.c
52376+++ b/drivers/video/vesafb.c
52377@@ -9,6 +9,7 @@
52378 */
52379
52380 #include <linux/module.h>
52381+#include <linux/moduleloader.h>
52382 #include <linux/kernel.h>
52383 #include <linux/errno.h>
52384 #include <linux/string.h>
52385@@ -52,8 +53,8 @@ static int vram_remap; /* Set amount of memory to be used */
52386 static int vram_total; /* Set total amount of memory */
52387 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
52388 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
52389-static void (*pmi_start)(void) __read_mostly;
52390-static void (*pmi_pal) (void) __read_mostly;
52391+static void (*pmi_start)(void) __read_only;
52392+static void (*pmi_pal) (void) __read_only;
52393 static int depth __read_mostly;
52394 static int vga_compat __read_mostly;
52395 /* --------------------------------------------------------------------- */
52396@@ -234,6 +235,7 @@ static int vesafb_probe(struct platform_device *dev)
52397 unsigned int size_remap;
52398 unsigned int size_total;
52399 char *option = NULL;
52400+ void *pmi_code = NULL;
52401
52402 /* ignore error return of fb_get_options */
52403 fb_get_options("vesafb", &option);
52404@@ -280,10 +282,6 @@ static int vesafb_probe(struct platform_device *dev)
52405 size_remap = size_total;
52406 vesafb_fix.smem_len = size_remap;
52407
52408-#ifndef __i386__
52409- screen_info.vesapm_seg = 0;
52410-#endif
52411-
52412 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
52413 printk(KERN_WARNING
52414 "vesafb: cannot reserve video memory at 0x%lx\n",
52415@@ -312,9 +310,21 @@ static int vesafb_probe(struct platform_device *dev)
52416 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
52417 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
52418
52419+#ifdef __i386__
52420+
52421+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
52422+ pmi_code = module_alloc_exec(screen_info.vesapm_size);
52423+ if (!pmi_code)
52424+#elif !defined(CONFIG_PAX_KERNEXEC)
52425+ if (0)
52426+#endif
52427+
52428+#endif
52429+ screen_info.vesapm_seg = 0;
52430+
52431 if (screen_info.vesapm_seg) {
52432- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
52433- screen_info.vesapm_seg,screen_info.vesapm_off);
52434+ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
52435+ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
52436 }
52437
52438 if (screen_info.vesapm_seg < 0xc000)
52439@@ -322,9 +332,25 @@ static int vesafb_probe(struct platform_device *dev)
52440
52441 if (ypan || pmi_setpal) {
52442 unsigned short *pmi_base;
52443+
52444 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
52445- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
52446- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
52447+
52448+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
52449+ pax_open_kernel();
52450+ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
52451+#else
52452+ pmi_code = pmi_base;
52453+#endif
52454+
52455+ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
52456+ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
52457+
52458+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
52459+ pmi_start = ktva_ktla(pmi_start);
52460+ pmi_pal = ktva_ktla(pmi_pal);
52461+ pax_close_kernel();
52462+#endif
52463+
52464 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
52465 if (pmi_base[3]) {
52466 printk(KERN_INFO "vesafb: pmi: ports = ");
52467@@ -477,8 +503,11 @@ static int vesafb_probe(struct platform_device *dev)
52468 info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE |
52469 (ypan ? FBINFO_HWACCEL_YPAN : 0);
52470
52471- if (!ypan)
52472- info->fbops->fb_pan_display = NULL;
52473+ if (!ypan) {
52474+ pax_open_kernel();
52475+ *(void **)&info->fbops->fb_pan_display = NULL;
52476+ pax_close_kernel();
52477+ }
52478
52479 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
52480 err = -ENOMEM;
52481@@ -493,6 +522,11 @@ static int vesafb_probe(struct platform_device *dev)
52482 info->node, info->fix.id);
52483 return 0;
52484 err:
52485+
52486+#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
52487+ module_free_exec(NULL, pmi_code);
52488+#endif
52489+
52490 if (info->screen_base)
52491 iounmap(info->screen_base);
52492 framebuffer_release(info);
52493diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
52494index 88714ae..16c2e11 100644
52495--- a/drivers/video/via/via_clock.h
52496+++ b/drivers/video/via/via_clock.h
52497@@ -56,7 +56,7 @@ struct via_clock {
52498
52499 void (*set_engine_pll_state)(u8 state);
52500 void (*set_engine_pll)(struct via_pll_config config);
52501-};
52502+} __no_const;
52503
52504
52505 static inline u32 get_pll_internal_frequency(u32 ref_freq,
52506diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
52507index fef20db..d28b1ab 100644
52508--- a/drivers/xen/xenfs/xenstored.c
52509+++ b/drivers/xen/xenfs/xenstored.c
52510@@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
52511 static int xsd_kva_open(struct inode *inode, struct file *file)
52512 {
52513 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
52514+#ifdef CONFIG_GRKERNSEC_HIDESYM
52515+ NULL);
52516+#else
52517 xen_store_interface);
52518+#endif
52519+
52520 if (!file->private_data)
52521 return -ENOMEM;
52522 return 0;
52523diff --git a/fs/9p/vfs_addr.c b/fs/9p/vfs_addr.c
52524index 9ff073f..05cef23 100644
52525--- a/fs/9p/vfs_addr.c
52526+++ b/fs/9p/vfs_addr.c
52527@@ -187,7 +187,7 @@ static int v9fs_vfs_writepage_locked(struct page *page)
52528
52529 retval = v9fs_file_write_internal(inode,
52530 v9inode->writeback_fid,
52531- (__force const char __user *)buffer,
52532+ (const char __force_user *)buffer,
52533 len, &offset, 0);
52534 if (retval > 0)
52535 retval = 0;
52536diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
52537index 94de6d1..8d81256 100644
52538--- a/fs/9p/vfs_inode.c
52539+++ b/fs/9p/vfs_inode.c
52540@@ -1312,7 +1312,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
52541 void
52542 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
52543 {
52544- char *s = nd_get_link(nd);
52545+ const char *s = nd_get_link(nd);
52546
52547 p9_debug(P9_DEBUG_VFS, " %s %s\n",
52548 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
52549diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
52550index 370b24c..ff0be7b 100644
52551--- a/fs/Kconfig.binfmt
52552+++ b/fs/Kconfig.binfmt
52553@@ -103,7 +103,7 @@ config HAVE_AOUT
52554
52555 config BINFMT_AOUT
52556 tristate "Kernel support for a.out and ECOFF binaries"
52557- depends on HAVE_AOUT
52558+ depends on HAVE_AOUT && BROKEN
52559 ---help---
52560 A.out (Assembler.OUTput) is a set of formats for libraries and
52561 executables used in the earliest versions of UNIX. Linux used
52562diff --git a/fs/afs/inode.c b/fs/afs/inode.c
52563index 789bc25..fafaeea 100644
52564--- a/fs/afs/inode.c
52565+++ b/fs/afs/inode.c
52566@@ -141,7 +141,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
52567 struct afs_vnode *vnode;
52568 struct super_block *sb;
52569 struct inode *inode;
52570- static atomic_t afs_autocell_ino;
52571+ static atomic_unchecked_t afs_autocell_ino;
52572
52573 _enter("{%x:%u},%*.*s,",
52574 AFS_FS_I(dir)->fid.vid, AFS_FS_I(dir)->fid.vnode,
52575@@ -154,7 +154,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
52576 data.fid.unique = 0;
52577 data.fid.vnode = 0;
52578
52579- inode = iget5_locked(sb, atomic_inc_return(&afs_autocell_ino),
52580+ inode = iget5_locked(sb, atomic_inc_return_unchecked(&afs_autocell_ino),
52581 afs_iget5_autocell_test, afs_iget5_set,
52582 &data);
52583 if (!inode) {
52584diff --git a/fs/aio.c b/fs/aio.c
52585index 067e3d3..634a850 100644
52586--- a/fs/aio.c
52587+++ b/fs/aio.c
52588@@ -280,7 +280,7 @@ static int aio_setup_ring(struct kioctx *ctx)
52589 size += sizeof(struct io_event) * nr_events;
52590
52591 nr_pages = PFN_UP(size);
52592- if (nr_pages < 0)
52593+ if (nr_pages <= 0)
52594 return -EINVAL;
52595
52596 file = anon_inode_getfile_private("[aio]", &aio_ring_fops, ctx, O_RDWR);
52597diff --git a/fs/attr.c b/fs/attr.c
52598index 1449adb..a2038c2 100644
52599--- a/fs/attr.c
52600+++ b/fs/attr.c
52601@@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
52602 unsigned long limit;
52603
52604 limit = rlimit(RLIMIT_FSIZE);
52605+ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
52606 if (limit != RLIM_INFINITY && offset > limit)
52607 goto out_sig;
52608 if (offset > inode->i_sb->s_maxbytes)
52609diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
52610index 689e40d..515cac5 100644
52611--- a/fs/autofs4/waitq.c
52612+++ b/fs/autofs4/waitq.c
52613@@ -59,7 +59,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
52614 {
52615 unsigned long sigpipe, flags;
52616 mm_segment_t fs;
52617- const char *data = (const char *)addr;
52618+ const char __user *data = (const char __force_user *)addr;
52619 ssize_t wr = 0;
52620
52621 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
52622@@ -340,6 +340,10 @@ static int validate_request(struct autofs_wait_queue **wait,
52623 return 1;
52624 }
52625
52626+#ifdef CONFIG_GRKERNSEC_HIDESYM
52627+static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
52628+#endif
52629+
52630 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
52631 enum autofs_notify notify)
52632 {
52633@@ -373,7 +377,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
52634
52635 /* If this is a direct mount request create a dummy name */
52636 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
52637+#ifdef CONFIG_GRKERNSEC_HIDESYM
52638+ /* this name does get written to userland via autofs4_write() */
52639+ qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
52640+#else
52641 qstr.len = sprintf(name, "%p", dentry);
52642+#endif
52643 else {
52644 qstr.len = autofs4_getpath(sbi, dentry, &name);
52645 if (!qstr.len) {
52646diff --git a/fs/befs/endian.h b/fs/befs/endian.h
52647index 2722387..56059b5 100644
52648--- a/fs/befs/endian.h
52649+++ b/fs/befs/endian.h
52650@@ -11,7 +11,7 @@
52651
52652 #include <asm/byteorder.h>
52653
52654-static inline u64
52655+static inline u64 __intentional_overflow(-1)
52656 fs64_to_cpu(const struct super_block *sb, fs64 n)
52657 {
52658 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
52659@@ -29,7 +29,7 @@ cpu_to_fs64(const struct super_block *sb, u64 n)
52660 return (__force fs64)cpu_to_be64(n);
52661 }
52662
52663-static inline u32
52664+static inline u32 __intentional_overflow(-1)
52665 fs32_to_cpu(const struct super_block *sb, fs32 n)
52666 {
52667 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
52668@@ -47,7 +47,7 @@ cpu_to_fs32(const struct super_block *sb, u32 n)
52669 return (__force fs32)cpu_to_be32(n);
52670 }
52671
52672-static inline u16
52673+static inline u16 __intentional_overflow(-1)
52674 fs16_to_cpu(const struct super_block *sb, fs16 n)
52675 {
52676 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
52677diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
52678index e9c75e2..1baece1 100644
52679--- a/fs/befs/linuxvfs.c
52680+++ b/fs/befs/linuxvfs.c
52681@@ -514,7 +514,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
52682 {
52683 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
52684 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
52685- char *link = nd_get_link(nd);
52686+ const char *link = nd_get_link(nd);
52687 if (!IS_ERR(link))
52688 kfree(link);
52689 }
52690diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
52691index 89dec7f..361b0d75 100644
52692--- a/fs/binfmt_aout.c
52693+++ b/fs/binfmt_aout.c
52694@@ -16,6 +16,7 @@
52695 #include <linux/string.h>
52696 #include <linux/fs.h>
52697 #include <linux/file.h>
52698+#include <linux/security.h>
52699 #include <linux/stat.h>
52700 #include <linux/fcntl.h>
52701 #include <linux/ptrace.h>
52702@@ -59,6 +60,8 @@ static int aout_core_dump(struct coredump_params *cprm)
52703 #endif
52704 # define START_STACK(u) ((void __user *)u.start_stack)
52705
52706+ memset(&dump, 0, sizeof(dump));
52707+
52708 fs = get_fs();
52709 set_fs(KERNEL_DS);
52710 has_dumped = 1;
52711@@ -69,10 +72,12 @@ static int aout_core_dump(struct coredump_params *cprm)
52712
52713 /* If the size of the dump file exceeds the rlimit, then see what would happen
52714 if we wrote the stack, but not the data area. */
52715+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
52716 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
52717 dump.u_dsize = 0;
52718
52719 /* Make sure we have enough room to write the stack and data areas. */
52720+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
52721 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
52722 dump.u_ssize = 0;
52723
52724@@ -233,6 +238,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
52725 rlim = rlimit(RLIMIT_DATA);
52726 if (rlim >= RLIM_INFINITY)
52727 rlim = ~0;
52728+
52729+ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
52730 if (ex.a_data + ex.a_bss > rlim)
52731 return -ENOMEM;
52732
52733@@ -265,6 +272,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
52734
52735 install_exec_creds(bprm);
52736
52737+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
52738+ current->mm->pax_flags = 0UL;
52739+#endif
52740+
52741+#ifdef CONFIG_PAX_PAGEEXEC
52742+ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
52743+ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
52744+
52745+#ifdef CONFIG_PAX_EMUTRAMP
52746+ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
52747+ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
52748+#endif
52749+
52750+#ifdef CONFIG_PAX_MPROTECT
52751+ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
52752+ current->mm->pax_flags |= MF_PAX_MPROTECT;
52753+#endif
52754+
52755+ }
52756+#endif
52757+
52758 if (N_MAGIC(ex) == OMAGIC) {
52759 unsigned long text_addr, map_size;
52760 loff_t pos;
52761@@ -322,7 +350,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
52762 }
52763
52764 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
52765- PROT_READ | PROT_WRITE | PROT_EXEC,
52766+ PROT_READ | PROT_WRITE,
52767 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
52768 fd_offset + ex.a_text);
52769 if (error != N_DATADDR(ex)) {
52770diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
52771index 4c94a79..f428019 100644
52772--- a/fs/binfmt_elf.c
52773+++ b/fs/binfmt_elf.c
52774@@ -34,6 +34,7 @@
52775 #include <linux/utsname.h>
52776 #include <linux/coredump.h>
52777 #include <linux/sched.h>
52778+#include <linux/xattr.h>
52779 #include <asm/uaccess.h>
52780 #include <asm/param.h>
52781 #include <asm/page.h>
52782@@ -60,6 +61,14 @@ static int elf_core_dump(struct coredump_params *cprm);
52783 #define elf_core_dump NULL
52784 #endif
52785
52786+#ifdef CONFIG_PAX_MPROTECT
52787+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
52788+#endif
52789+
52790+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
52791+static void elf_handle_mmap(struct file *file);
52792+#endif
52793+
52794 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
52795 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
52796 #else
52797@@ -79,6 +88,15 @@ static struct linux_binfmt elf_format = {
52798 .load_binary = load_elf_binary,
52799 .load_shlib = load_elf_library,
52800 .core_dump = elf_core_dump,
52801+
52802+#ifdef CONFIG_PAX_MPROTECT
52803+ .handle_mprotect= elf_handle_mprotect,
52804+#endif
52805+
52806+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
52807+ .handle_mmap = elf_handle_mmap,
52808+#endif
52809+
52810 .min_coredump = ELF_EXEC_PAGESIZE,
52811 };
52812
52813@@ -86,6 +104,8 @@ static struct linux_binfmt elf_format = {
52814
52815 static int set_brk(unsigned long start, unsigned long end)
52816 {
52817+ unsigned long e = end;
52818+
52819 start = ELF_PAGEALIGN(start);
52820 end = ELF_PAGEALIGN(end);
52821 if (end > start) {
52822@@ -94,7 +114,7 @@ static int set_brk(unsigned long start, unsigned long end)
52823 if (BAD_ADDR(addr))
52824 return addr;
52825 }
52826- current->mm->start_brk = current->mm->brk = end;
52827+ current->mm->start_brk = current->mm->brk = e;
52828 return 0;
52829 }
52830
52831@@ -155,12 +175,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
52832 elf_addr_t __user *u_rand_bytes;
52833 const char *k_platform = ELF_PLATFORM;
52834 const char *k_base_platform = ELF_BASE_PLATFORM;
52835- unsigned char k_rand_bytes[16];
52836+ u32 k_rand_bytes[4];
52837 int items;
52838 elf_addr_t *elf_info;
52839 int ei_index = 0;
52840 const struct cred *cred = current_cred();
52841 struct vm_area_struct *vma;
52842+ unsigned long saved_auxv[AT_VECTOR_SIZE];
52843
52844 /*
52845 * In some cases (e.g. Hyper-Threading), we want to avoid L1
52846@@ -202,8 +223,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
52847 * Generate 16 random bytes for userspace PRNG seeding.
52848 */
52849 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
52850- u_rand_bytes = (elf_addr_t __user *)
52851- STACK_ALLOC(p, sizeof(k_rand_bytes));
52852+ prandom_seed(k_rand_bytes[0] ^ prandom_u32());
52853+ prandom_seed(k_rand_bytes[1] ^ prandom_u32());
52854+ prandom_seed(k_rand_bytes[2] ^ prandom_u32());
52855+ prandom_seed(k_rand_bytes[3] ^ prandom_u32());
52856+ p = STACK_ROUND(p, sizeof(k_rand_bytes));
52857+ u_rand_bytes = (elf_addr_t __user *) p;
52858 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
52859 return -EFAULT;
52860
52861@@ -318,9 +343,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
52862 return -EFAULT;
52863 current->mm->env_end = p;
52864
52865+ memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
52866+
52867 /* Put the elf_info on the stack in the right place. */
52868 sp = (elf_addr_t __user *)envp + 1;
52869- if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
52870+ if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
52871 return -EFAULT;
52872 return 0;
52873 }
52874@@ -388,15 +415,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
52875 an ELF header */
52876
52877 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
52878- struct file *interpreter, unsigned long *interp_map_addr,
52879- unsigned long no_base)
52880+ struct file *interpreter, unsigned long no_base)
52881 {
52882 struct elf_phdr *elf_phdata;
52883 struct elf_phdr *eppnt;
52884- unsigned long load_addr = 0;
52885+ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
52886 int load_addr_set = 0;
52887 unsigned long last_bss = 0, elf_bss = 0;
52888- unsigned long error = ~0UL;
52889+ unsigned long error = -EINVAL;
52890 unsigned long total_size;
52891 int retval, i, size;
52892
52893@@ -442,6 +468,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
52894 goto out_close;
52895 }
52896
52897+#ifdef CONFIG_PAX_SEGMEXEC
52898+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
52899+ pax_task_size = SEGMEXEC_TASK_SIZE;
52900+#endif
52901+
52902 eppnt = elf_phdata;
52903 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
52904 if (eppnt->p_type == PT_LOAD) {
52905@@ -465,8 +496,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
52906 map_addr = elf_map(interpreter, load_addr + vaddr,
52907 eppnt, elf_prot, elf_type, total_size);
52908 total_size = 0;
52909- if (!*interp_map_addr)
52910- *interp_map_addr = map_addr;
52911 error = map_addr;
52912 if (BAD_ADDR(map_addr))
52913 goto out_close;
52914@@ -485,8 +514,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
52915 k = load_addr + eppnt->p_vaddr;
52916 if (BAD_ADDR(k) ||
52917 eppnt->p_filesz > eppnt->p_memsz ||
52918- eppnt->p_memsz > TASK_SIZE ||
52919- TASK_SIZE - eppnt->p_memsz < k) {
52920+ eppnt->p_memsz > pax_task_size ||
52921+ pax_task_size - eppnt->p_memsz < k) {
52922 error = -ENOMEM;
52923 goto out_close;
52924 }
52925@@ -525,9 +554,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
52926 elf_bss = ELF_PAGESTART(elf_bss + ELF_MIN_ALIGN - 1);
52927
52928 /* Map the last of the bss segment */
52929- error = vm_brk(elf_bss, last_bss - elf_bss);
52930- if (BAD_ADDR(error))
52931- goto out_close;
52932+ if (last_bss > elf_bss) {
52933+ error = vm_brk(elf_bss, last_bss - elf_bss);
52934+ if (BAD_ADDR(error))
52935+ goto out_close;
52936+ }
52937 }
52938
52939 error = load_addr;
52940@@ -538,6 +569,315 @@ out:
52941 return error;
52942 }
52943
52944+#ifdef CONFIG_PAX_PT_PAX_FLAGS
52945+#ifdef CONFIG_PAX_SOFTMODE
52946+static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
52947+{
52948+ unsigned long pax_flags = 0UL;
52949+
52950+#ifdef CONFIG_PAX_PAGEEXEC
52951+ if (elf_phdata->p_flags & PF_PAGEEXEC)
52952+ pax_flags |= MF_PAX_PAGEEXEC;
52953+#endif
52954+
52955+#ifdef CONFIG_PAX_SEGMEXEC
52956+ if (elf_phdata->p_flags & PF_SEGMEXEC)
52957+ pax_flags |= MF_PAX_SEGMEXEC;
52958+#endif
52959+
52960+#ifdef CONFIG_PAX_EMUTRAMP
52961+ if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
52962+ pax_flags |= MF_PAX_EMUTRAMP;
52963+#endif
52964+
52965+#ifdef CONFIG_PAX_MPROTECT
52966+ if (elf_phdata->p_flags & PF_MPROTECT)
52967+ pax_flags |= MF_PAX_MPROTECT;
52968+#endif
52969+
52970+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
52971+ if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
52972+ pax_flags |= MF_PAX_RANDMMAP;
52973+#endif
52974+
52975+ return pax_flags;
52976+}
52977+#endif
52978+
52979+static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
52980+{
52981+ unsigned long pax_flags = 0UL;
52982+
52983+#ifdef CONFIG_PAX_PAGEEXEC
52984+ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
52985+ pax_flags |= MF_PAX_PAGEEXEC;
52986+#endif
52987+
52988+#ifdef CONFIG_PAX_SEGMEXEC
52989+ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
52990+ pax_flags |= MF_PAX_SEGMEXEC;
52991+#endif
52992+
52993+#ifdef CONFIG_PAX_EMUTRAMP
52994+ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
52995+ pax_flags |= MF_PAX_EMUTRAMP;
52996+#endif
52997+
52998+#ifdef CONFIG_PAX_MPROTECT
52999+ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
53000+ pax_flags |= MF_PAX_MPROTECT;
53001+#endif
53002+
53003+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
53004+ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
53005+ pax_flags |= MF_PAX_RANDMMAP;
53006+#endif
53007+
53008+ return pax_flags;
53009+}
53010+#endif
53011+
53012+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
53013+#ifdef CONFIG_PAX_SOFTMODE
53014+static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
53015+{
53016+ unsigned long pax_flags = 0UL;
53017+
53018+#ifdef CONFIG_PAX_PAGEEXEC
53019+ if (pax_flags_softmode & MF_PAX_PAGEEXEC)
53020+ pax_flags |= MF_PAX_PAGEEXEC;
53021+#endif
53022+
53023+#ifdef CONFIG_PAX_SEGMEXEC
53024+ if (pax_flags_softmode & MF_PAX_SEGMEXEC)
53025+ pax_flags |= MF_PAX_SEGMEXEC;
53026+#endif
53027+
53028+#ifdef CONFIG_PAX_EMUTRAMP
53029+ if ((pax_flags_softmode & MF_PAX_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
53030+ pax_flags |= MF_PAX_EMUTRAMP;
53031+#endif
53032+
53033+#ifdef CONFIG_PAX_MPROTECT
53034+ if (pax_flags_softmode & MF_PAX_MPROTECT)
53035+ pax_flags |= MF_PAX_MPROTECT;
53036+#endif
53037+
53038+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
53039+ if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
53040+ pax_flags |= MF_PAX_RANDMMAP;
53041+#endif
53042+
53043+ return pax_flags;
53044+}
53045+#endif
53046+
53047+static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
53048+{
53049+ unsigned long pax_flags = 0UL;
53050+
53051+#ifdef CONFIG_PAX_PAGEEXEC
53052+ if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
53053+ pax_flags |= MF_PAX_PAGEEXEC;
53054+#endif
53055+
53056+#ifdef CONFIG_PAX_SEGMEXEC
53057+ if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
53058+ pax_flags |= MF_PAX_SEGMEXEC;
53059+#endif
53060+
53061+#ifdef CONFIG_PAX_EMUTRAMP
53062+ if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
53063+ pax_flags |= MF_PAX_EMUTRAMP;
53064+#endif
53065+
53066+#ifdef CONFIG_PAX_MPROTECT
53067+ if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
53068+ pax_flags |= MF_PAX_MPROTECT;
53069+#endif
53070+
53071+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
53072+ if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
53073+ pax_flags |= MF_PAX_RANDMMAP;
53074+#endif
53075+
53076+ return pax_flags;
53077+}
53078+#endif
53079+
53080+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
53081+static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
53082+{
53083+ unsigned long pax_flags = 0UL;
53084+
53085+#ifdef CONFIG_PAX_EI_PAX
53086+
53087+#ifdef CONFIG_PAX_PAGEEXEC
53088+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
53089+ pax_flags |= MF_PAX_PAGEEXEC;
53090+#endif
53091+
53092+#ifdef CONFIG_PAX_SEGMEXEC
53093+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
53094+ pax_flags |= MF_PAX_SEGMEXEC;
53095+#endif
53096+
53097+#ifdef CONFIG_PAX_EMUTRAMP
53098+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
53099+ pax_flags |= MF_PAX_EMUTRAMP;
53100+#endif
53101+
53102+#ifdef CONFIG_PAX_MPROTECT
53103+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
53104+ pax_flags |= MF_PAX_MPROTECT;
53105+#endif
53106+
53107+#ifdef CONFIG_PAX_ASLR
53108+ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
53109+ pax_flags |= MF_PAX_RANDMMAP;
53110+#endif
53111+
53112+#else
53113+
53114+#ifdef CONFIG_PAX_PAGEEXEC
53115+ pax_flags |= MF_PAX_PAGEEXEC;
53116+#endif
53117+
53118+#ifdef CONFIG_PAX_SEGMEXEC
53119+ pax_flags |= MF_PAX_SEGMEXEC;
53120+#endif
53121+
53122+#ifdef CONFIG_PAX_MPROTECT
53123+ pax_flags |= MF_PAX_MPROTECT;
53124+#endif
53125+
53126+#ifdef CONFIG_PAX_RANDMMAP
53127+ if (randomize_va_space)
53128+ pax_flags |= MF_PAX_RANDMMAP;
53129+#endif
53130+
53131+#endif
53132+
53133+ return pax_flags;
53134+}
53135+
53136+static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
53137+{
53138+
53139+#ifdef CONFIG_PAX_PT_PAX_FLAGS
53140+ unsigned long i;
53141+
53142+ for (i = 0UL; i < elf_ex->e_phnum; i++)
53143+ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
53144+ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
53145+ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
53146+ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
53147+ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
53148+ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
53149+ return ~0UL;
53150+
53151+#ifdef CONFIG_PAX_SOFTMODE
53152+ if (pax_softmode)
53153+ return pax_parse_pt_pax_softmode(&elf_phdata[i]);
53154+ else
53155+#endif
53156+
53157+ return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
53158+ break;
53159+ }
53160+#endif
53161+
53162+ return ~0UL;
53163+}
53164+
53165+static unsigned long pax_parse_xattr_pax(struct file * const file)
53166+{
53167+
53168+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
53169+ ssize_t xattr_size, i;
53170+ unsigned char xattr_value[sizeof("pemrs") - 1];
53171+ unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
53172+
53173+ xattr_size = pax_getxattr(file->f_path.dentry, xattr_value, sizeof xattr_value);
53174+ if (xattr_size <= 0 || xattr_size > sizeof xattr_value)
53175+ return ~0UL;
53176+
53177+ for (i = 0; i < xattr_size; i++)
53178+ switch (xattr_value[i]) {
53179+ default:
53180+ return ~0UL;
53181+
53182+#define parse_flag(option1, option2, flag) \
53183+ case option1: \
53184+ if (pax_flags_hardmode & MF_PAX_##flag) \
53185+ return ~0UL; \
53186+ pax_flags_hardmode |= MF_PAX_##flag; \
53187+ break; \
53188+ case option2: \
53189+ if (pax_flags_softmode & MF_PAX_##flag) \
53190+ return ~0UL; \
53191+ pax_flags_softmode |= MF_PAX_##flag; \
53192+ break;
53193+
53194+ parse_flag('p', 'P', PAGEEXEC);
53195+ parse_flag('e', 'E', EMUTRAMP);
53196+ parse_flag('m', 'M', MPROTECT);
53197+ parse_flag('r', 'R', RANDMMAP);
53198+ parse_flag('s', 'S', SEGMEXEC);
53199+
53200+#undef parse_flag
53201+ }
53202+
53203+ if (pax_flags_hardmode & pax_flags_softmode)
53204+ return ~0UL;
53205+
53206+#ifdef CONFIG_PAX_SOFTMODE
53207+ if (pax_softmode)
53208+ return pax_parse_xattr_pax_softmode(pax_flags_softmode);
53209+ else
53210+#endif
53211+
53212+ return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
53213+#else
53214+ return ~0UL;
53215+#endif
53216+
53217+}
53218+
53219+static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
53220+{
53221+ unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
53222+
53223+ pax_flags = pax_parse_ei_pax(elf_ex);
53224+ pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
53225+ xattr_pax_flags = pax_parse_xattr_pax(file);
53226+
53227+ if (pt_pax_flags == ~0UL)
53228+ pt_pax_flags = xattr_pax_flags;
53229+ else if (xattr_pax_flags == ~0UL)
53230+ xattr_pax_flags = pt_pax_flags;
53231+ if (pt_pax_flags != xattr_pax_flags)
53232+ return -EINVAL;
53233+ if (pt_pax_flags != ~0UL)
53234+ pax_flags = pt_pax_flags;
53235+
53236+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
53237+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
53238+ if ((__supported_pte_mask & _PAGE_NX))
53239+ pax_flags &= ~MF_PAX_SEGMEXEC;
53240+ else
53241+ pax_flags &= ~MF_PAX_PAGEEXEC;
53242+ }
53243+#endif
53244+
53245+ if (0 > pax_check_flags(&pax_flags))
53246+ return -EINVAL;
53247+
53248+ current->mm->pax_flags = pax_flags;
53249+ return 0;
53250+}
53251+#endif
53252+
53253 /*
53254 * These are the functions used to load ELF style executables and shared
53255 * libraries. There is no binary dependent code anywhere else.
53256@@ -554,6 +894,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
53257 {
53258 unsigned int random_variable = 0;
53259
53260+#ifdef CONFIG_PAX_RANDUSTACK
53261+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
53262+ return stack_top - current->mm->delta_stack;
53263+#endif
53264+
53265 if ((current->flags & PF_RANDOMIZE) &&
53266 !(current->personality & ADDR_NO_RANDOMIZE)) {
53267 random_variable = get_random_int() & STACK_RND_MASK;
53268@@ -572,7 +917,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
53269 unsigned long load_addr = 0, load_bias = 0;
53270 int load_addr_set = 0;
53271 char * elf_interpreter = NULL;
53272- unsigned long error;
53273+ unsigned long error = 0;
53274 struct elf_phdr *elf_ppnt, *elf_phdata;
53275 unsigned long elf_bss, elf_brk;
53276 int retval, i;
53277@@ -582,12 +927,12 @@ static int load_elf_binary(struct linux_binprm *bprm)
53278 unsigned long start_code, end_code, start_data, end_data;
53279 unsigned long reloc_func_desc __maybe_unused = 0;
53280 int executable_stack = EXSTACK_DEFAULT;
53281- unsigned long def_flags = 0;
53282 struct pt_regs *regs = current_pt_regs();
53283 struct {
53284 struct elfhdr elf_ex;
53285 struct elfhdr interp_elf_ex;
53286 } *loc;
53287+ unsigned long pax_task_size = TASK_SIZE;
53288
53289 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
53290 if (!loc) {
53291@@ -723,11 +1068,81 @@ static int load_elf_binary(struct linux_binprm *bprm)
53292 goto out_free_dentry;
53293
53294 /* OK, This is the point of no return */
53295- current->mm->def_flags = def_flags;
53296+
53297+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
53298+ current->mm->pax_flags = 0UL;
53299+#endif
53300+
53301+#ifdef CONFIG_PAX_DLRESOLVE
53302+ current->mm->call_dl_resolve = 0UL;
53303+#endif
53304+
53305+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
53306+ current->mm->call_syscall = 0UL;
53307+#endif
53308+
53309+#ifdef CONFIG_PAX_ASLR
53310+ current->mm->delta_mmap = 0UL;
53311+ current->mm->delta_stack = 0UL;
53312+#endif
53313+
53314+ current->mm->def_flags = 0;
53315+
53316+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
53317+ if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
53318+ send_sig(SIGKILL, current, 0);
53319+ goto out_free_dentry;
53320+ }
53321+#endif
53322+
53323+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
53324+ pax_set_initial_flags(bprm);
53325+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
53326+ if (pax_set_initial_flags_func)
53327+ (pax_set_initial_flags_func)(bprm);
53328+#endif
53329+
53330+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
53331+ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
53332+ current->mm->context.user_cs_limit = PAGE_SIZE;
53333+ current->mm->def_flags |= VM_PAGEEXEC | VM_NOHUGEPAGE;
53334+ }
53335+#endif
53336+
53337+#ifdef CONFIG_PAX_SEGMEXEC
53338+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
53339+ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
53340+ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
53341+ pax_task_size = SEGMEXEC_TASK_SIZE;
53342+ current->mm->def_flags |= VM_NOHUGEPAGE;
53343+ }
53344+#endif
53345+
53346+#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
53347+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
53348+ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
53349+ put_cpu();
53350+ }
53351+#endif
53352
53353 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
53354 may depend on the personality. */
53355 SET_PERSONALITY(loc->elf_ex);
53356+
53357+#ifdef CONFIG_PAX_ASLR
53358+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
53359+ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
53360+ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
53361+ }
53362+#endif
53363+
53364+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
53365+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
53366+ executable_stack = EXSTACK_DISABLE_X;
53367+ current->personality &= ~READ_IMPLIES_EXEC;
53368+ } else
53369+#endif
53370+
53371 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
53372 current->personality |= READ_IMPLIES_EXEC;
53373
53374@@ -817,6 +1232,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
53375 #else
53376 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
53377 #endif
53378+
53379+#ifdef CONFIG_PAX_RANDMMAP
53380+ /* PaX: randomize base address at the default exe base if requested */
53381+ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
53382+#ifdef CONFIG_SPARC64
53383+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
53384+#else
53385+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
53386+#endif
53387+ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
53388+ elf_flags |= MAP_FIXED;
53389+ }
53390+#endif
53391+
53392 }
53393
53394 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
53395@@ -849,9 +1278,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
53396 * allowed task size. Note that p_filesz must always be
53397 * <= p_memsz so it is only necessary to check p_memsz.
53398 */
53399- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
53400- elf_ppnt->p_memsz > TASK_SIZE ||
53401- TASK_SIZE - elf_ppnt->p_memsz < k) {
53402+ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
53403+ elf_ppnt->p_memsz > pax_task_size ||
53404+ pax_task_size - elf_ppnt->p_memsz < k) {
53405 /* set_brk can never work. Avoid overflows. */
53406 send_sig(SIGKILL, current, 0);
53407 retval = -EINVAL;
53408@@ -890,17 +1319,45 @@ static int load_elf_binary(struct linux_binprm *bprm)
53409 goto out_free_dentry;
53410 }
53411 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
53412- send_sig(SIGSEGV, current, 0);
53413- retval = -EFAULT; /* Nobody gets to see this, but.. */
53414- goto out_free_dentry;
53415+ /*
53416+ * This bss-zeroing can fail if the ELF
53417+ * file specifies odd protections. So
53418+ * we don't check the return value
53419+ */
53420 }
53421
53422+#ifdef CONFIG_PAX_RANDMMAP
53423+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
53424+ unsigned long start, size, flags;
53425+ vm_flags_t vm_flags;
53426+
53427+ start = ELF_PAGEALIGN(elf_brk);
53428+ size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
53429+ flags = MAP_FIXED | MAP_PRIVATE;
53430+ vm_flags = VM_DONTEXPAND | VM_DONTDUMP;
53431+
53432+ down_write(&current->mm->mmap_sem);
53433+ start = get_unmapped_area(NULL, start, PAGE_ALIGN(size), 0, flags);
53434+ retval = -ENOMEM;
53435+ if (!IS_ERR_VALUE(start) && !find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
53436+// if (current->personality & ADDR_NO_RANDOMIZE)
53437+// vm_flags |= VM_READ | VM_MAYREAD;
53438+ start = mmap_region(NULL, start, PAGE_ALIGN(size), vm_flags, 0);
53439+ retval = IS_ERR_VALUE(start) ? start : 0;
53440+ }
53441+ up_write(&current->mm->mmap_sem);
53442+ if (retval == 0)
53443+ retval = set_brk(start + size, start + size + PAGE_SIZE);
53444+ if (retval < 0) {
53445+ send_sig(SIGKILL, current, 0);
53446+ goto out_free_dentry;
53447+ }
53448+ }
53449+#endif
53450+
53451 if (elf_interpreter) {
53452- unsigned long interp_map_addr = 0;
53453-
53454 elf_entry = load_elf_interp(&loc->interp_elf_ex,
53455 interpreter,
53456- &interp_map_addr,
53457 load_bias);
53458 if (!IS_ERR((void *)elf_entry)) {
53459 /*
53460@@ -1122,7 +1579,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
53461 * Decide what to dump of a segment, part, all or none.
53462 */
53463 static unsigned long vma_dump_size(struct vm_area_struct *vma,
53464- unsigned long mm_flags)
53465+ unsigned long mm_flags, long signr)
53466 {
53467 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
53468
53469@@ -1160,7 +1617,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
53470 if (vma->vm_file == NULL)
53471 return 0;
53472
53473- if (FILTER(MAPPED_PRIVATE))
53474+ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
53475 goto whole;
53476
53477 /*
53478@@ -1385,9 +1842,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
53479 {
53480 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
53481 int i = 0;
53482- do
53483+ do {
53484 i += 2;
53485- while (auxv[i - 2] != AT_NULL);
53486+ } while (auxv[i - 2] != AT_NULL);
53487 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
53488 }
53489
53490@@ -1396,7 +1853,7 @@ static void fill_siginfo_note(struct memelfnote *note, user_siginfo_t *csigdata,
53491 {
53492 mm_segment_t old_fs = get_fs();
53493 set_fs(KERNEL_DS);
53494- copy_siginfo_to_user((user_siginfo_t __user *) csigdata, siginfo);
53495+ copy_siginfo_to_user((user_siginfo_t __force_user *) csigdata, siginfo);
53496 set_fs(old_fs);
53497 fill_note(note, "CORE", NT_SIGINFO, sizeof(*csigdata), csigdata);
53498 }
53499@@ -2023,14 +2480,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
53500 }
53501
53502 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
53503- unsigned long mm_flags)
53504+ struct coredump_params *cprm)
53505 {
53506 struct vm_area_struct *vma;
53507 size_t size = 0;
53508
53509 for (vma = first_vma(current, gate_vma); vma != NULL;
53510 vma = next_vma(vma, gate_vma))
53511- size += vma_dump_size(vma, mm_flags);
53512+ size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
53513 return size;
53514 }
53515
53516@@ -2123,7 +2580,7 @@ static int elf_core_dump(struct coredump_params *cprm)
53517
53518 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
53519
53520- offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
53521+ offset += elf_core_vma_data_size(gate_vma, cprm);
53522 offset += elf_core_extra_data_size();
53523 e_shoff = offset;
53524
53525@@ -2137,10 +2594,12 @@ static int elf_core_dump(struct coredump_params *cprm)
53526 offset = dataoff;
53527
53528 size += sizeof(*elf);
53529+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
53530 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
53531 goto end_coredump;
53532
53533 size += sizeof(*phdr4note);
53534+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
53535 if (size > cprm->limit
53536 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
53537 goto end_coredump;
53538@@ -2154,7 +2613,7 @@ static int elf_core_dump(struct coredump_params *cprm)
53539 phdr.p_offset = offset;
53540 phdr.p_vaddr = vma->vm_start;
53541 phdr.p_paddr = 0;
53542- phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
53543+ phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
53544 phdr.p_memsz = vma->vm_end - vma->vm_start;
53545 offset += phdr.p_filesz;
53546 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
53547@@ -2165,6 +2624,7 @@ static int elf_core_dump(struct coredump_params *cprm)
53548 phdr.p_align = ELF_EXEC_PAGESIZE;
53549
53550 size += sizeof(phdr);
53551+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
53552 if (size > cprm->limit
53553 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
53554 goto end_coredump;
53555@@ -2189,7 +2649,7 @@ static int elf_core_dump(struct coredump_params *cprm)
53556 unsigned long addr;
53557 unsigned long end;
53558
53559- end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
53560+ end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
53561
53562 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
53563 struct page *page;
53564@@ -2198,6 +2658,7 @@ static int elf_core_dump(struct coredump_params *cprm)
53565 page = get_dump_page(addr);
53566 if (page) {
53567 void *kaddr = kmap(page);
53568+ gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
53569 stop = ((size += PAGE_SIZE) > cprm->limit) ||
53570 !dump_write(cprm->file, kaddr,
53571 PAGE_SIZE);
53572@@ -2215,6 +2676,7 @@ static int elf_core_dump(struct coredump_params *cprm)
53573
53574 if (e_phnum == PN_XNUM) {
53575 size += sizeof(*shdr4extnum);
53576+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
53577 if (size > cprm->limit
53578 || !dump_write(cprm->file, shdr4extnum,
53579 sizeof(*shdr4extnum)))
53580@@ -2235,6 +2697,167 @@ out:
53581
53582 #endif /* CONFIG_ELF_CORE */
53583
53584+#ifdef CONFIG_PAX_MPROTECT
53585+/* PaX: non-PIC ELF libraries need relocations on their executable segments
53586+ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
53587+ * we'll remove VM_MAYWRITE for good on RELRO segments.
53588+ *
53589+ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
53590+ * basis because we want to allow the common case and not the special ones.
53591+ */
53592+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
53593+{
53594+ struct elfhdr elf_h;
53595+ struct elf_phdr elf_p;
53596+ unsigned long i;
53597+ unsigned long oldflags;
53598+ bool is_textrel_rw, is_textrel_rx, is_relro;
53599+
53600+ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT) || !vma->vm_file)
53601+ return;
53602+
53603+ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
53604+ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
53605+
53606+#ifdef CONFIG_PAX_ELFRELOCS
53607+ /* possible TEXTREL */
53608+ is_textrel_rw = !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
53609+ is_textrel_rx = vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_WRITE | VM_READ) && newflags == (VM_EXEC | VM_READ);
53610+#else
53611+ is_textrel_rw = false;
53612+ is_textrel_rx = false;
53613+#endif
53614+
53615+ /* possible RELRO */
53616+ is_relro = vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
53617+
53618+ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
53619+ return;
53620+
53621+ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
53622+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
53623+
53624+#ifdef CONFIG_PAX_ETEXECRELOCS
53625+ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
53626+#else
53627+ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
53628+#endif
53629+
53630+ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
53631+ !elf_check_arch(&elf_h) ||
53632+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
53633+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
53634+ return;
53635+
53636+ for (i = 0UL; i < elf_h.e_phnum; i++) {
53637+ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
53638+ return;
53639+ switch (elf_p.p_type) {
53640+ case PT_DYNAMIC:
53641+ if (!is_textrel_rw && !is_textrel_rx)
53642+ continue;
53643+ i = 0UL;
53644+ while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
53645+ elf_dyn dyn;
53646+
53647+ if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
53648+ break;
53649+ if (dyn.d_tag == DT_NULL)
53650+ break;
53651+ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
53652+ gr_log_textrel(vma);
53653+ if (is_textrel_rw)
53654+ vma->vm_flags |= VM_MAYWRITE;
53655+ else
53656+ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
53657+ vma->vm_flags &= ~VM_MAYWRITE;
53658+ break;
53659+ }
53660+ i++;
53661+ }
53662+ is_textrel_rw = false;
53663+ is_textrel_rx = false;
53664+ continue;
53665+
53666+ case PT_GNU_RELRO:
53667+ if (!is_relro)
53668+ continue;
53669+ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
53670+ vma->vm_flags &= ~VM_MAYWRITE;
53671+ is_relro = false;
53672+ continue;
53673+
53674+#ifdef CONFIG_PAX_PT_PAX_FLAGS
53675+ case PT_PAX_FLAGS: {
53676+ const char *msg_mprotect = "", *msg_emutramp = "";
53677+ char *buffer_lib, *buffer_exe;
53678+
53679+ if (elf_p.p_flags & PF_NOMPROTECT)
53680+ msg_mprotect = "MPROTECT disabled";
53681+
53682+#ifdef CONFIG_PAX_EMUTRAMP
53683+ if (!(vma->vm_mm->pax_flags & MF_PAX_EMUTRAMP) && !(elf_p.p_flags & PF_NOEMUTRAMP))
53684+ msg_emutramp = "EMUTRAMP enabled";
53685+#endif
53686+
53687+ if (!msg_mprotect[0] && !msg_emutramp[0])
53688+ continue;
53689+
53690+ if (!printk_ratelimit())
53691+ continue;
53692+
53693+ buffer_lib = (char *)__get_free_page(GFP_KERNEL);
53694+ buffer_exe = (char *)__get_free_page(GFP_KERNEL);
53695+ if (buffer_lib && buffer_exe) {
53696+ char *path_lib, *path_exe;
53697+
53698+ path_lib = pax_get_path(&vma->vm_file->f_path, buffer_lib, PAGE_SIZE);
53699+ path_exe = pax_get_path(&vma->vm_mm->exe_file->f_path, buffer_exe, PAGE_SIZE);
53700+
53701+ pr_info("PAX: %s wants %s%s%s on %s\n", path_lib, msg_mprotect,
53702+ (msg_mprotect[0] && msg_emutramp[0] ? " and " : ""), msg_emutramp, path_exe);
53703+
53704+ }
53705+ free_page((unsigned long)buffer_exe);
53706+ free_page((unsigned long)buffer_lib);
53707+ continue;
53708+ }
53709+#endif
53710+
53711+ }
53712+ }
53713+}
53714+#endif
53715+
53716+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
53717+
53718+extern int grsec_enable_log_rwxmaps;
53719+
53720+static void elf_handle_mmap(struct file *file)
53721+{
53722+ struct elfhdr elf_h;
53723+ struct elf_phdr elf_p;
53724+ unsigned long i;
53725+
53726+ if (!grsec_enable_log_rwxmaps)
53727+ return;
53728+
53729+ if (sizeof(elf_h) != kernel_read(file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
53730+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
53731+ (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC) || !elf_check_arch(&elf_h) ||
53732+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
53733+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
53734+ return;
53735+
53736+ for (i = 0UL; i < elf_h.e_phnum; i++) {
53737+ if (sizeof(elf_p) != kernel_read(file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
53738+ return;
53739+ if (elf_p.p_type == PT_GNU_STACK && (elf_p.p_flags & PF_X))
53740+ gr_log_ptgnustack(file);
53741+ }
53742+}
53743+#endif
53744+
53745 static int __init init_elf_binfmt(void)
53746 {
53747 register_binfmt(&elf_format);
53748diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
53749index d50bbe5..af3b649 100644
53750--- a/fs/binfmt_flat.c
53751+++ b/fs/binfmt_flat.c
53752@@ -566,7 +566,9 @@ static int load_flat_file(struct linux_binprm * bprm,
53753 realdatastart = (unsigned long) -ENOMEM;
53754 printk("Unable to allocate RAM for process data, errno %d\n",
53755 (int)-realdatastart);
53756+ down_write(&current->mm->mmap_sem);
53757 vm_munmap(textpos, text_len);
53758+ up_write(&current->mm->mmap_sem);
53759 ret = realdatastart;
53760 goto err;
53761 }
53762@@ -590,8 +592,10 @@ static int load_flat_file(struct linux_binprm * bprm,
53763 }
53764 if (IS_ERR_VALUE(result)) {
53765 printk("Unable to read data+bss, errno %d\n", (int)-result);
53766+ down_write(&current->mm->mmap_sem);
53767 vm_munmap(textpos, text_len);
53768 vm_munmap(realdatastart, len);
53769+ up_write(&current->mm->mmap_sem);
53770 ret = result;
53771 goto err;
53772 }
53773@@ -653,8 +657,10 @@ static int load_flat_file(struct linux_binprm * bprm,
53774 }
53775 if (IS_ERR_VALUE(result)) {
53776 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
53777+ down_write(&current->mm->mmap_sem);
53778 vm_munmap(textpos, text_len + data_len + extra +
53779 MAX_SHARED_LIBS * sizeof(unsigned long));
53780+ up_write(&current->mm->mmap_sem);
53781 ret = result;
53782 goto err;
53783 }
53784diff --git a/fs/bio.c b/fs/bio.c
53785index ea5035d..a2932eb 100644
53786--- a/fs/bio.c
53787+++ b/fs/bio.c
53788@@ -1106,7 +1106,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
53789 /*
53790 * Overflow, abort
53791 */
53792- if (end < start)
53793+ if (end < start || end - start > INT_MAX - nr_pages)
53794 return ERR_PTR(-EINVAL);
53795
53796 nr_pages += end - start;
53797@@ -1240,7 +1240,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
53798 /*
53799 * Overflow, abort
53800 */
53801- if (end < start)
53802+ if (end < start || end - start > INT_MAX - nr_pages)
53803 return ERR_PTR(-EINVAL);
53804
53805 nr_pages += end - start;
53806@@ -1502,7 +1502,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
53807 const int read = bio_data_dir(bio) == READ;
53808 struct bio_map_data *bmd = bio->bi_private;
53809 int i;
53810- char *p = bmd->sgvecs[0].iov_base;
53811+ char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
53812
53813 bio_for_each_segment_all(bvec, bio, i) {
53814 char *addr = page_address(bvec->bv_page);
53815diff --git a/fs/block_dev.c b/fs/block_dev.c
53816index 1e86823..8e34695 100644
53817--- a/fs/block_dev.c
53818+++ b/fs/block_dev.c
53819@@ -637,7 +637,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
53820 else if (bdev->bd_contains == bdev)
53821 return true; /* is a whole device which isn't held */
53822
53823- else if (whole->bd_holder == bd_may_claim)
53824+ else if (whole->bd_holder == (void *)bd_may_claim)
53825 return true; /* is a partition of a device that is being partitioned */
53826 else if (whole->bd_holder != NULL)
53827 return false; /* is a partition of a held device */
53828diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
53829index 61b5bcd..7eeede8 100644
53830--- a/fs/btrfs/ctree.c
53831+++ b/fs/btrfs/ctree.c
53832@@ -1028,9 +1028,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
53833 free_extent_buffer(buf);
53834 add_root_to_dirty_list(root);
53835 } else {
53836- if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
53837- parent_start = parent->start;
53838- else
53839+ if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
53840+ if (parent)
53841+ parent_start = parent->start;
53842+ else
53843+ parent_start = 0;
53844+ } else
53845 parent_start = 0;
53846
53847 WARN_ON(trans->transid != btrfs_header_generation(parent));
53848diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
53849index cbd9523..5cca781 100644
53850--- a/fs/btrfs/delayed-inode.c
53851+++ b/fs/btrfs/delayed-inode.c
53852@@ -459,7 +459,7 @@ static int __btrfs_add_delayed_deletion_item(struct btrfs_delayed_node *node,
53853
53854 static void finish_one_item(struct btrfs_delayed_root *delayed_root)
53855 {
53856- int seq = atomic_inc_return(&delayed_root->items_seq);
53857+ int seq = atomic_inc_return_unchecked(&delayed_root->items_seq);
53858 if ((atomic_dec_return(&delayed_root->items) <
53859 BTRFS_DELAYED_BACKGROUND || seq % BTRFS_DELAYED_BATCH == 0) &&
53860 waitqueue_active(&delayed_root->wait))
53861@@ -1378,7 +1378,7 @@ void btrfs_assert_delayed_root_empty(struct btrfs_root *root)
53862 static int refs_newer(struct btrfs_delayed_root *delayed_root,
53863 int seq, int count)
53864 {
53865- int val = atomic_read(&delayed_root->items_seq);
53866+ int val = atomic_read_unchecked(&delayed_root->items_seq);
53867
53868 if (val < seq || val >= seq + count)
53869 return 1;
53870@@ -1395,7 +1395,7 @@ void btrfs_balance_delayed_items(struct btrfs_root *root)
53871 if (atomic_read(&delayed_root->items) < BTRFS_DELAYED_BACKGROUND)
53872 return;
53873
53874- seq = atomic_read(&delayed_root->items_seq);
53875+ seq = atomic_read_unchecked(&delayed_root->items_seq);
53876
53877 if (atomic_read(&delayed_root->items) >= BTRFS_DELAYED_WRITEBACK) {
53878 int ret;
53879diff --git a/fs/btrfs/delayed-inode.h b/fs/btrfs/delayed-inode.h
53880index a4b38f9..f86a509 100644
53881--- a/fs/btrfs/delayed-inode.h
53882+++ b/fs/btrfs/delayed-inode.h
53883@@ -43,7 +43,7 @@ struct btrfs_delayed_root {
53884 */
53885 struct list_head prepare_list;
53886 atomic_t items; /* for delayed items */
53887- atomic_t items_seq; /* for delayed items */
53888+ atomic_unchecked_t items_seq; /* for delayed items */
53889 int nodes; /* for delayed nodes */
53890 wait_queue_head_t wait;
53891 };
53892@@ -87,7 +87,7 @@ static inline void btrfs_init_delayed_root(
53893 struct btrfs_delayed_root *delayed_root)
53894 {
53895 atomic_set(&delayed_root->items, 0);
53896- atomic_set(&delayed_root->items_seq, 0);
53897+ atomic_set_unchecked(&delayed_root->items_seq, 0);
53898 delayed_root->nodes = 0;
53899 spin_lock_init(&delayed_root->lock);
53900 init_waitqueue_head(&delayed_root->wait);
53901diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
53902index 9d46f60..a8f09eb 100644
53903--- a/fs/btrfs/ioctl.c
53904+++ b/fs/btrfs/ioctl.c
53905@@ -3464,9 +3464,12 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
53906 for (i = 0; i < num_types; i++) {
53907 struct btrfs_space_info *tmp;
53908
53909+ /* Don't copy in more than we allocated */
53910 if (!slot_count)
53911 break;
53912
53913+ slot_count--;
53914+
53915 info = NULL;
53916 rcu_read_lock();
53917 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
53918@@ -3488,10 +3491,7 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
53919 memcpy(dest, &space, sizeof(space));
53920 dest++;
53921 space_args.total_spaces++;
53922- slot_count--;
53923 }
53924- if (!slot_count)
53925- break;
53926 }
53927 up_read(&info->groups_sem);
53928 }
53929diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
53930index e913328..a34fb36 100644
53931--- a/fs/btrfs/super.c
53932+++ b/fs/btrfs/super.c
53933@@ -266,7 +266,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
53934 function, line, errstr);
53935 return;
53936 }
53937- ACCESS_ONCE(trans->transaction->aborted) = errno;
53938+ ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
53939 /* Wake up anybody who may be waiting on this transaction */
53940 wake_up(&root->fs_info->transaction_wait);
53941 wake_up(&root->fs_info->transaction_blocked_wait);
53942diff --git a/fs/buffer.c b/fs/buffer.c
53943index 6024877..7bd000a 100644
53944--- a/fs/buffer.c
53945+++ b/fs/buffer.c
53946@@ -3426,7 +3426,7 @@ void __init buffer_init(void)
53947 bh_cachep = kmem_cache_create("buffer_head",
53948 sizeof(struct buffer_head), 0,
53949 (SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|
53950- SLAB_MEM_SPREAD),
53951+ SLAB_MEM_SPREAD|SLAB_NO_SANITIZE),
53952 NULL);
53953
53954 /*
53955diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
53956index 622f469..e8d2d55 100644
53957--- a/fs/cachefiles/bind.c
53958+++ b/fs/cachefiles/bind.c
53959@@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
53960 args);
53961
53962 /* start by checking things over */
53963- ASSERT(cache->fstop_percent >= 0 &&
53964- cache->fstop_percent < cache->fcull_percent &&
53965+ ASSERT(cache->fstop_percent < cache->fcull_percent &&
53966 cache->fcull_percent < cache->frun_percent &&
53967 cache->frun_percent < 100);
53968
53969- ASSERT(cache->bstop_percent >= 0 &&
53970- cache->bstop_percent < cache->bcull_percent &&
53971+ ASSERT(cache->bstop_percent < cache->bcull_percent &&
53972 cache->bcull_percent < cache->brun_percent &&
53973 cache->brun_percent < 100);
53974
53975diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
53976index 0a1467b..6a53245 100644
53977--- a/fs/cachefiles/daemon.c
53978+++ b/fs/cachefiles/daemon.c
53979@@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
53980 if (n > buflen)
53981 return -EMSGSIZE;
53982
53983- if (copy_to_user(_buffer, buffer, n) != 0)
53984+ if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
53985 return -EFAULT;
53986
53987 return n;
53988@@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
53989 if (test_bit(CACHEFILES_DEAD, &cache->flags))
53990 return -EIO;
53991
53992- if (datalen < 0 || datalen > PAGE_SIZE - 1)
53993+ if (datalen > PAGE_SIZE - 1)
53994 return -EOPNOTSUPP;
53995
53996 /* drag the command string into the kernel so we can parse it */
53997@@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
53998 if (args[0] != '%' || args[1] != '\0')
53999 return -EINVAL;
54000
54001- if (fstop < 0 || fstop >= cache->fcull_percent)
54002+ if (fstop >= cache->fcull_percent)
54003 return cachefiles_daemon_range_error(cache, args);
54004
54005 cache->fstop_percent = fstop;
54006@@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
54007 if (args[0] != '%' || args[1] != '\0')
54008 return -EINVAL;
54009
54010- if (bstop < 0 || bstop >= cache->bcull_percent)
54011+ if (bstop >= cache->bcull_percent)
54012 return cachefiles_daemon_range_error(cache, args);
54013
54014 cache->bstop_percent = bstop;
54015diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
54016index 5349473..d6c0b93 100644
54017--- a/fs/cachefiles/internal.h
54018+++ b/fs/cachefiles/internal.h
54019@@ -59,7 +59,7 @@ struct cachefiles_cache {
54020 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
54021 struct rb_root active_nodes; /* active nodes (can't be culled) */
54022 rwlock_t active_lock; /* lock for active_nodes */
54023- atomic_t gravecounter; /* graveyard uniquifier */
54024+ atomic_unchecked_t gravecounter; /* graveyard uniquifier */
54025 unsigned frun_percent; /* when to stop culling (% files) */
54026 unsigned fcull_percent; /* when to start culling (% files) */
54027 unsigned fstop_percent; /* when to stop allocating (% files) */
54028@@ -171,19 +171,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
54029 * proc.c
54030 */
54031 #ifdef CONFIG_CACHEFILES_HISTOGRAM
54032-extern atomic_t cachefiles_lookup_histogram[HZ];
54033-extern atomic_t cachefiles_mkdir_histogram[HZ];
54034-extern atomic_t cachefiles_create_histogram[HZ];
54035+extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
54036+extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
54037+extern atomic_unchecked_t cachefiles_create_histogram[HZ];
54038
54039 extern int __init cachefiles_proc_init(void);
54040 extern void cachefiles_proc_cleanup(void);
54041 static inline
54042-void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
54043+void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
54044 {
54045 unsigned long jif = jiffies - start_jif;
54046 if (jif >= HZ)
54047 jif = HZ - 1;
54048- atomic_inc(&histogram[jif]);
54049+ atomic_inc_unchecked(&histogram[jif]);
54050 }
54051
54052 #else
54053diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
54054index f4a08d7..5aa4599 100644
54055--- a/fs/cachefiles/namei.c
54056+++ b/fs/cachefiles/namei.c
54057@@ -317,7 +317,7 @@ try_again:
54058 /* first step is to make up a grave dentry in the graveyard */
54059 sprintf(nbuffer, "%08x%08x",
54060 (uint32_t) get_seconds(),
54061- (uint32_t) atomic_inc_return(&cache->gravecounter));
54062+ (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
54063
54064 /* do the multiway lock magic */
54065 trap = lock_rename(cache->graveyard, dir);
54066diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
54067index eccd339..4c1d995 100644
54068--- a/fs/cachefiles/proc.c
54069+++ b/fs/cachefiles/proc.c
54070@@ -14,9 +14,9 @@
54071 #include <linux/seq_file.h>
54072 #include "internal.h"
54073
54074-atomic_t cachefiles_lookup_histogram[HZ];
54075-atomic_t cachefiles_mkdir_histogram[HZ];
54076-atomic_t cachefiles_create_histogram[HZ];
54077+atomic_unchecked_t cachefiles_lookup_histogram[HZ];
54078+atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
54079+atomic_unchecked_t cachefiles_create_histogram[HZ];
54080
54081 /*
54082 * display the latency histogram
54083@@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
54084 return 0;
54085 default:
54086 index = (unsigned long) v - 3;
54087- x = atomic_read(&cachefiles_lookup_histogram[index]);
54088- y = atomic_read(&cachefiles_mkdir_histogram[index]);
54089- z = atomic_read(&cachefiles_create_histogram[index]);
54090+ x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
54091+ y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
54092+ z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
54093 if (x == 0 && y == 0 && z == 0)
54094 return 0;
54095
54096diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
54097index ebaff36..7e3ea26 100644
54098--- a/fs/cachefiles/rdwr.c
54099+++ b/fs/cachefiles/rdwr.c
54100@@ -950,7 +950,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
54101 old_fs = get_fs();
54102 set_fs(KERNEL_DS);
54103 ret = file->f_op->write(
54104- file, (const void __user *) data, len, &pos);
54105+ file, (const void __force_user *) data, len, &pos);
54106 set_fs(old_fs);
54107 kunmap(page);
54108 file_end_write(file);
54109diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
54110index 868b61d..58835a5 100644
54111--- a/fs/ceph/dir.c
54112+++ b/fs/ceph/dir.c
54113@@ -240,7 +240,7 @@ static int ceph_readdir(struct file *file, struct dir_context *ctx)
54114 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
54115 struct ceph_mds_client *mdsc = fsc->mdsc;
54116 unsigned frag = fpos_frag(ctx->pos);
54117- int off = fpos_off(ctx->pos);
54118+ unsigned int off = fpos_off(ctx->pos);
54119 int err;
54120 u32 ftype;
54121 struct ceph_mds_reply_info_parsed *rinfo;
54122diff --git a/fs/ceph/super.c b/fs/ceph/super.c
54123index 6a0951e..03fac6d 100644
54124--- a/fs/ceph/super.c
54125+++ b/fs/ceph/super.c
54126@@ -870,7 +870,7 @@ static int ceph_compare_super(struct super_block *sb, void *data)
54127 /*
54128 * construct our own bdi so we can control readahead, etc.
54129 */
54130-static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
54131+static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
54132
54133 static int ceph_register_bdi(struct super_block *sb,
54134 struct ceph_fs_client *fsc)
54135@@ -887,7 +887,7 @@ static int ceph_register_bdi(struct super_block *sb,
54136 default_backing_dev_info.ra_pages;
54137
54138 err = bdi_register(&fsc->backing_dev_info, NULL, "ceph-%ld",
54139- atomic_long_inc_return(&bdi_seq));
54140+ atomic_long_inc_return_unchecked(&bdi_seq));
54141 if (!err)
54142 sb->s_bdi = &fsc->backing_dev_info;
54143 return err;
54144diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
54145index f3ac415..3d2420c 100644
54146--- a/fs/cifs/cifs_debug.c
54147+++ b/fs/cifs/cifs_debug.c
54148@@ -286,8 +286,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
54149
54150 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
54151 #ifdef CONFIG_CIFS_STATS2
54152- atomic_set(&totBufAllocCount, 0);
54153- atomic_set(&totSmBufAllocCount, 0);
54154+ atomic_set_unchecked(&totBufAllocCount, 0);
54155+ atomic_set_unchecked(&totSmBufAllocCount, 0);
54156 #endif /* CONFIG_CIFS_STATS2 */
54157 spin_lock(&cifs_tcp_ses_lock);
54158 list_for_each(tmp1, &cifs_tcp_ses_list) {
54159@@ -300,7 +300,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
54160 tcon = list_entry(tmp3,
54161 struct cifs_tcon,
54162 tcon_list);
54163- atomic_set(&tcon->num_smbs_sent, 0);
54164+ atomic_set_unchecked(&tcon->num_smbs_sent, 0);
54165 if (server->ops->clear_stats)
54166 server->ops->clear_stats(tcon);
54167 }
54168@@ -332,8 +332,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
54169 smBufAllocCount.counter, cifs_min_small);
54170 #ifdef CONFIG_CIFS_STATS2
54171 seq_printf(m, "Total Large %d Small %d Allocations\n",
54172- atomic_read(&totBufAllocCount),
54173- atomic_read(&totSmBufAllocCount));
54174+ atomic_read_unchecked(&totBufAllocCount),
54175+ atomic_read_unchecked(&totSmBufAllocCount));
54176 #endif /* CONFIG_CIFS_STATS2 */
54177
54178 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
54179@@ -362,7 +362,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
54180 if (tcon->need_reconnect)
54181 seq_puts(m, "\tDISCONNECTED ");
54182 seq_printf(m, "\nSMBs: %d",
54183- atomic_read(&tcon->num_smbs_sent));
54184+ atomic_read_unchecked(&tcon->num_smbs_sent));
54185 if (server->ops->print_stats)
54186 server->ops->print_stats(m, tcon);
54187 }
54188diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
54189index 77fc5e1..e3d13e6 100644
54190--- a/fs/cifs/cifsfs.c
54191+++ b/fs/cifs/cifsfs.c
54192@@ -1056,7 +1056,7 @@ cifs_init_request_bufs(void)
54193 */
54194 cifs_req_cachep = kmem_cache_create("cifs_request",
54195 CIFSMaxBufSize + max_hdr_size, 0,
54196- SLAB_HWCACHE_ALIGN, NULL);
54197+ SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
54198 if (cifs_req_cachep == NULL)
54199 return -ENOMEM;
54200
54201@@ -1083,7 +1083,7 @@ cifs_init_request_bufs(void)
54202 efficient to alloc 1 per page off the slab compared to 17K (5page)
54203 alloc of large cifs buffers even when page debugging is on */
54204 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
54205- MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
54206+ MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
54207 NULL);
54208 if (cifs_sm_req_cachep == NULL) {
54209 mempool_destroy(cifs_req_poolp);
54210@@ -1168,8 +1168,8 @@ init_cifs(void)
54211 atomic_set(&bufAllocCount, 0);
54212 atomic_set(&smBufAllocCount, 0);
54213 #ifdef CONFIG_CIFS_STATS2
54214- atomic_set(&totBufAllocCount, 0);
54215- atomic_set(&totSmBufAllocCount, 0);
54216+ atomic_set_unchecked(&totBufAllocCount, 0);
54217+ atomic_set_unchecked(&totSmBufAllocCount, 0);
54218 #endif /* CONFIG_CIFS_STATS2 */
54219
54220 atomic_set(&midCount, 0);
54221diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
54222index 52b6f6c..68db1f4 100644
54223--- a/fs/cifs/cifsglob.h
54224+++ b/fs/cifs/cifsglob.h
54225@@ -758,35 +758,35 @@ struct cifs_tcon {
54226 __u16 Flags; /* optional support bits */
54227 enum statusEnum tidStatus;
54228 #ifdef CONFIG_CIFS_STATS
54229- atomic_t num_smbs_sent;
54230+ atomic_unchecked_t num_smbs_sent;
54231 union {
54232 struct {
54233- atomic_t num_writes;
54234- atomic_t num_reads;
54235- atomic_t num_flushes;
54236- atomic_t num_oplock_brks;
54237- atomic_t num_opens;
54238- atomic_t num_closes;
54239- atomic_t num_deletes;
54240- atomic_t num_mkdirs;
54241- atomic_t num_posixopens;
54242- atomic_t num_posixmkdirs;
54243- atomic_t num_rmdirs;
54244- atomic_t num_renames;
54245- atomic_t num_t2renames;
54246- atomic_t num_ffirst;
54247- atomic_t num_fnext;
54248- atomic_t num_fclose;
54249- atomic_t num_hardlinks;
54250- atomic_t num_symlinks;
54251- atomic_t num_locks;
54252- atomic_t num_acl_get;
54253- atomic_t num_acl_set;
54254+ atomic_unchecked_t num_writes;
54255+ atomic_unchecked_t num_reads;
54256+ atomic_unchecked_t num_flushes;
54257+ atomic_unchecked_t num_oplock_brks;
54258+ atomic_unchecked_t num_opens;
54259+ atomic_unchecked_t num_closes;
54260+ atomic_unchecked_t num_deletes;
54261+ atomic_unchecked_t num_mkdirs;
54262+ atomic_unchecked_t num_posixopens;
54263+ atomic_unchecked_t num_posixmkdirs;
54264+ atomic_unchecked_t num_rmdirs;
54265+ atomic_unchecked_t num_renames;
54266+ atomic_unchecked_t num_t2renames;
54267+ atomic_unchecked_t num_ffirst;
54268+ atomic_unchecked_t num_fnext;
54269+ atomic_unchecked_t num_fclose;
54270+ atomic_unchecked_t num_hardlinks;
54271+ atomic_unchecked_t num_symlinks;
54272+ atomic_unchecked_t num_locks;
54273+ atomic_unchecked_t num_acl_get;
54274+ atomic_unchecked_t num_acl_set;
54275 } cifs_stats;
54276 #ifdef CONFIG_CIFS_SMB2
54277 struct {
54278- atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
54279- atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
54280+ atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
54281+ atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
54282 } smb2_stats;
54283 #endif /* CONFIG_CIFS_SMB2 */
54284 } stats;
54285@@ -1111,7 +1111,7 @@ convert_delimiter(char *path, char delim)
54286 }
54287
54288 #ifdef CONFIG_CIFS_STATS
54289-#define cifs_stats_inc atomic_inc
54290+#define cifs_stats_inc atomic_inc_unchecked
54291
54292 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
54293 unsigned int bytes)
54294@@ -1477,8 +1477,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
54295 /* Various Debug counters */
54296 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
54297 #ifdef CONFIG_CIFS_STATS2
54298-GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
54299-GLOBAL_EXTERN atomic_t totSmBufAllocCount;
54300+GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
54301+GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
54302 #endif
54303 GLOBAL_EXTERN atomic_t smBufAllocCount;
54304 GLOBAL_EXTERN atomic_t midCount;
54305diff --git a/fs/cifs/link.c b/fs/cifs/link.c
54306index 7e36ceb..109252f 100644
54307--- a/fs/cifs/link.c
54308+++ b/fs/cifs/link.c
54309@@ -624,7 +624,7 @@ symlink_exit:
54310
54311 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
54312 {
54313- char *p = nd_get_link(nd);
54314+ const char *p = nd_get_link(nd);
54315 if (!IS_ERR(p))
54316 kfree(p);
54317 }
54318diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
54319index 138a011..cf9e13a 100644
54320--- a/fs/cifs/misc.c
54321+++ b/fs/cifs/misc.c
54322@@ -170,7 +170,7 @@ cifs_buf_get(void)
54323 memset(ret_buf, 0, buf_size + 3);
54324 atomic_inc(&bufAllocCount);
54325 #ifdef CONFIG_CIFS_STATS2
54326- atomic_inc(&totBufAllocCount);
54327+ atomic_inc_unchecked(&totBufAllocCount);
54328 #endif /* CONFIG_CIFS_STATS2 */
54329 }
54330
54331@@ -205,7 +205,7 @@ cifs_small_buf_get(void)
54332 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
54333 atomic_inc(&smBufAllocCount);
54334 #ifdef CONFIG_CIFS_STATS2
54335- atomic_inc(&totSmBufAllocCount);
54336+ atomic_inc_unchecked(&totSmBufAllocCount);
54337 #endif /* CONFIG_CIFS_STATS2 */
54338
54339 }
54340diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
54341index 8233b17..2b83e95 100644
54342--- a/fs/cifs/smb1ops.c
54343+++ b/fs/cifs/smb1ops.c
54344@@ -590,27 +590,27 @@ static void
54345 cifs_clear_stats(struct cifs_tcon *tcon)
54346 {
54347 #ifdef CONFIG_CIFS_STATS
54348- atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
54349- atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
54350- atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
54351- atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
54352- atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
54353- atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
54354- atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
54355- atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
54356- atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
54357- atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
54358- atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
54359- atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
54360- atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
54361- atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
54362- atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
54363- atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
54364- atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
54365- atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
54366- atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
54367- atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
54368- atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
54369+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
54370+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
54371+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
54372+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
54373+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
54374+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
54375+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
54376+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
54377+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
54378+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
54379+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
54380+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
54381+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
54382+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
54383+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
54384+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
54385+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
54386+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
54387+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
54388+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
54389+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
54390 #endif
54391 }
54392
54393@@ -619,36 +619,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
54394 {
54395 #ifdef CONFIG_CIFS_STATS
54396 seq_printf(m, " Oplocks breaks: %d",
54397- atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
54398+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
54399 seq_printf(m, "\nReads: %d Bytes: %llu",
54400- atomic_read(&tcon->stats.cifs_stats.num_reads),
54401+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
54402 (long long)(tcon->bytes_read));
54403 seq_printf(m, "\nWrites: %d Bytes: %llu",
54404- atomic_read(&tcon->stats.cifs_stats.num_writes),
54405+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
54406 (long long)(tcon->bytes_written));
54407 seq_printf(m, "\nFlushes: %d",
54408- atomic_read(&tcon->stats.cifs_stats.num_flushes));
54409+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
54410 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
54411- atomic_read(&tcon->stats.cifs_stats.num_locks),
54412- atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
54413- atomic_read(&tcon->stats.cifs_stats.num_symlinks));
54414+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
54415+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
54416+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
54417 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
54418- atomic_read(&tcon->stats.cifs_stats.num_opens),
54419- atomic_read(&tcon->stats.cifs_stats.num_closes),
54420- atomic_read(&tcon->stats.cifs_stats.num_deletes));
54421+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
54422+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
54423+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
54424 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
54425- atomic_read(&tcon->stats.cifs_stats.num_posixopens),
54426- atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
54427+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
54428+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
54429 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
54430- atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
54431- atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
54432+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
54433+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
54434 seq_printf(m, "\nRenames: %d T2 Renames %d",
54435- atomic_read(&tcon->stats.cifs_stats.num_renames),
54436- atomic_read(&tcon->stats.cifs_stats.num_t2renames));
54437+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
54438+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
54439 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
54440- atomic_read(&tcon->stats.cifs_stats.num_ffirst),
54441- atomic_read(&tcon->stats.cifs_stats.num_fnext),
54442- atomic_read(&tcon->stats.cifs_stats.num_fclose));
54443+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
54444+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
54445+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
54446 #endif
54447 }
54448
54449diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
54450index 861b332..5506392 100644
54451--- a/fs/cifs/smb2ops.c
54452+++ b/fs/cifs/smb2ops.c
54453@@ -282,8 +282,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
54454 #ifdef CONFIG_CIFS_STATS
54455 int i;
54456 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
54457- atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
54458- atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
54459+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
54460+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
54461 }
54462 #endif
54463 }
54464@@ -311,65 +311,65 @@ static void
54465 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
54466 {
54467 #ifdef CONFIG_CIFS_STATS
54468- atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
54469- atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
54470+ atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
54471+ atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
54472 seq_printf(m, "\nNegotiates: %d sent %d failed",
54473- atomic_read(&sent[SMB2_NEGOTIATE_HE]),
54474- atomic_read(&failed[SMB2_NEGOTIATE_HE]));
54475+ atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
54476+ atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
54477 seq_printf(m, "\nSessionSetups: %d sent %d failed",
54478- atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
54479- atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
54480+ atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
54481+ atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
54482 seq_printf(m, "\nLogoffs: %d sent %d failed",
54483- atomic_read(&sent[SMB2_LOGOFF_HE]),
54484- atomic_read(&failed[SMB2_LOGOFF_HE]));
54485+ atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
54486+ atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
54487 seq_printf(m, "\nTreeConnects: %d sent %d failed",
54488- atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
54489- atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
54490+ atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
54491+ atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
54492 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
54493- atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
54494- atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
54495+ atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
54496+ atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
54497 seq_printf(m, "\nCreates: %d sent %d failed",
54498- atomic_read(&sent[SMB2_CREATE_HE]),
54499- atomic_read(&failed[SMB2_CREATE_HE]));
54500+ atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
54501+ atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
54502 seq_printf(m, "\nCloses: %d sent %d failed",
54503- atomic_read(&sent[SMB2_CLOSE_HE]),
54504- atomic_read(&failed[SMB2_CLOSE_HE]));
54505+ atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
54506+ atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
54507 seq_printf(m, "\nFlushes: %d sent %d failed",
54508- atomic_read(&sent[SMB2_FLUSH_HE]),
54509- atomic_read(&failed[SMB2_FLUSH_HE]));
54510+ atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
54511+ atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
54512 seq_printf(m, "\nReads: %d sent %d failed",
54513- atomic_read(&sent[SMB2_READ_HE]),
54514- atomic_read(&failed[SMB2_READ_HE]));
54515+ atomic_read_unchecked(&sent[SMB2_READ_HE]),
54516+ atomic_read_unchecked(&failed[SMB2_READ_HE]));
54517 seq_printf(m, "\nWrites: %d sent %d failed",
54518- atomic_read(&sent[SMB2_WRITE_HE]),
54519- atomic_read(&failed[SMB2_WRITE_HE]));
54520+ atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
54521+ atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
54522 seq_printf(m, "\nLocks: %d sent %d failed",
54523- atomic_read(&sent[SMB2_LOCK_HE]),
54524- atomic_read(&failed[SMB2_LOCK_HE]));
54525+ atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
54526+ atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
54527 seq_printf(m, "\nIOCTLs: %d sent %d failed",
54528- atomic_read(&sent[SMB2_IOCTL_HE]),
54529- atomic_read(&failed[SMB2_IOCTL_HE]));
54530+ atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
54531+ atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
54532 seq_printf(m, "\nCancels: %d sent %d failed",
54533- atomic_read(&sent[SMB2_CANCEL_HE]),
54534- atomic_read(&failed[SMB2_CANCEL_HE]));
54535+ atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
54536+ atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
54537 seq_printf(m, "\nEchos: %d sent %d failed",
54538- atomic_read(&sent[SMB2_ECHO_HE]),
54539- atomic_read(&failed[SMB2_ECHO_HE]));
54540+ atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
54541+ atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
54542 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
54543- atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
54544- atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
54545+ atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
54546+ atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
54547 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
54548- atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
54549- atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
54550+ atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
54551+ atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
54552 seq_printf(m, "\nQueryInfos: %d sent %d failed",
54553- atomic_read(&sent[SMB2_QUERY_INFO_HE]),
54554- atomic_read(&failed[SMB2_QUERY_INFO_HE]));
54555+ atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
54556+ atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
54557 seq_printf(m, "\nSetInfos: %d sent %d failed",
54558- atomic_read(&sent[SMB2_SET_INFO_HE]),
54559- atomic_read(&failed[SMB2_SET_INFO_HE]));
54560+ atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
54561+ atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
54562 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
54563- atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
54564- atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
54565+ atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
54566+ atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
54567 #endif
54568 }
54569
54570diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
54571index edccb52..16bc6db 100644
54572--- a/fs/cifs/smb2pdu.c
54573+++ b/fs/cifs/smb2pdu.c
54574@@ -1957,8 +1957,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
54575 default:
54576 cifs_dbg(VFS, "info level %u isn't supported\n",
54577 srch_inf->info_level);
54578- rc = -EINVAL;
54579- goto qdir_exit;
54580+ return -EINVAL;
54581 }
54582
54583 req->FileIndex = cpu_to_le32(index);
54584diff --git a/fs/coda/cache.c b/fs/coda/cache.c
54585index 1da168c..8bc7ff6 100644
54586--- a/fs/coda/cache.c
54587+++ b/fs/coda/cache.c
54588@@ -24,7 +24,7 @@
54589 #include "coda_linux.h"
54590 #include "coda_cache.h"
54591
54592-static atomic_t permission_epoch = ATOMIC_INIT(0);
54593+static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
54594
54595 /* replace or extend an acl cache hit */
54596 void coda_cache_enter(struct inode *inode, int mask)
54597@@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
54598 struct coda_inode_info *cii = ITOC(inode);
54599
54600 spin_lock(&cii->c_lock);
54601- cii->c_cached_epoch = atomic_read(&permission_epoch);
54602+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
54603 if (!uid_eq(cii->c_uid, current_fsuid())) {
54604 cii->c_uid = current_fsuid();
54605 cii->c_cached_perm = mask;
54606@@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
54607 {
54608 struct coda_inode_info *cii = ITOC(inode);
54609 spin_lock(&cii->c_lock);
54610- cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
54611+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
54612 spin_unlock(&cii->c_lock);
54613 }
54614
54615 /* remove all acl caches */
54616 void coda_cache_clear_all(struct super_block *sb)
54617 {
54618- atomic_inc(&permission_epoch);
54619+ atomic_inc_unchecked(&permission_epoch);
54620 }
54621
54622
54623@@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
54624 spin_lock(&cii->c_lock);
54625 hit = (mask & cii->c_cached_perm) == mask &&
54626 uid_eq(cii->c_uid, current_fsuid()) &&
54627- cii->c_cached_epoch == atomic_read(&permission_epoch);
54628+ cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
54629 spin_unlock(&cii->c_lock);
54630
54631 return hit;
54632diff --git a/fs/compat.c b/fs/compat.c
54633index 6af20de..fec3fbb 100644
54634--- a/fs/compat.c
54635+++ b/fs/compat.c
54636@@ -54,7 +54,7 @@
54637 #include <asm/ioctls.h>
54638 #include "internal.h"
54639
54640-int compat_log = 1;
54641+int compat_log = 0;
54642
54643 int compat_printk(const char *fmt, ...)
54644 {
54645@@ -488,7 +488,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
54646
54647 set_fs(KERNEL_DS);
54648 /* The __user pointer cast is valid because of the set_fs() */
54649- ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
54650+ ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
54651 set_fs(oldfs);
54652 /* truncating is ok because it's a user address */
54653 if (!ret)
54654@@ -546,7 +546,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
54655 goto out;
54656
54657 ret = -EINVAL;
54658- if (nr_segs > UIO_MAXIOV || nr_segs < 0)
54659+ if (nr_segs > UIO_MAXIOV)
54660 goto out;
54661 if (nr_segs > fast_segs) {
54662 ret = -ENOMEM;
54663@@ -834,6 +834,7 @@ struct compat_old_linux_dirent {
54664 struct compat_readdir_callback {
54665 struct dir_context ctx;
54666 struct compat_old_linux_dirent __user *dirent;
54667+ struct file * file;
54668 int result;
54669 };
54670
54671@@ -851,6 +852,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
54672 buf->result = -EOVERFLOW;
54673 return -EOVERFLOW;
54674 }
54675+
54676+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
54677+ return 0;
54678+
54679 buf->result++;
54680 dirent = buf->dirent;
54681 if (!access_ok(VERIFY_WRITE, dirent,
54682@@ -882,6 +887,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
54683 if (!f.file)
54684 return -EBADF;
54685
54686+ buf.file = f.file;
54687 error = iterate_dir(f.file, &buf.ctx);
54688 if (buf.result)
54689 error = buf.result;
54690@@ -901,6 +907,7 @@ struct compat_getdents_callback {
54691 struct dir_context ctx;
54692 struct compat_linux_dirent __user *current_dir;
54693 struct compat_linux_dirent __user *previous;
54694+ struct file * file;
54695 int count;
54696 int error;
54697 };
54698@@ -922,6 +929,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
54699 buf->error = -EOVERFLOW;
54700 return -EOVERFLOW;
54701 }
54702+
54703+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
54704+ return 0;
54705+
54706 dirent = buf->previous;
54707 if (dirent) {
54708 if (__put_user(offset, &dirent->d_off))
54709@@ -967,6 +978,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
54710 if (!f.file)
54711 return -EBADF;
54712
54713+ buf.file = f.file;
54714 error = iterate_dir(f.file, &buf.ctx);
54715 if (error >= 0)
54716 error = buf.error;
54717@@ -987,6 +999,7 @@ struct compat_getdents_callback64 {
54718 struct dir_context ctx;
54719 struct linux_dirent64 __user *current_dir;
54720 struct linux_dirent64 __user *previous;
54721+ struct file * file;
54722 int count;
54723 int error;
54724 };
54725@@ -1003,6 +1016,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
54726 buf->error = -EINVAL; /* only used if we fail.. */
54727 if (reclen > buf->count)
54728 return -EINVAL;
54729+
54730+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
54731+ return 0;
54732+
54733 dirent = buf->previous;
54734
54735 if (dirent) {
54736@@ -1052,6 +1069,7 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
54737 if (!f.file)
54738 return -EBADF;
54739
54740+ buf.file = f.file;
54741 error = iterate_dir(f.file, &buf.ctx);
54742 if (error >= 0)
54743 error = buf.error;
54744diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
54745index a81147e..20bf2b5 100644
54746--- a/fs/compat_binfmt_elf.c
54747+++ b/fs/compat_binfmt_elf.c
54748@@ -30,11 +30,13 @@
54749 #undef elf_phdr
54750 #undef elf_shdr
54751 #undef elf_note
54752+#undef elf_dyn
54753 #undef elf_addr_t
54754 #define elfhdr elf32_hdr
54755 #define elf_phdr elf32_phdr
54756 #define elf_shdr elf32_shdr
54757 #define elf_note elf32_note
54758+#define elf_dyn Elf32_Dyn
54759 #define elf_addr_t Elf32_Addr
54760
54761 /*
54762diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
54763index 5d19acf..9ab093b 100644
54764--- a/fs/compat_ioctl.c
54765+++ b/fs/compat_ioctl.c
54766@@ -621,7 +621,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
54767 return -EFAULT;
54768 if (__get_user(udata, &ss32->iomem_base))
54769 return -EFAULT;
54770- ss.iomem_base = compat_ptr(udata);
54771+ ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
54772 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
54773 __get_user(ss.port_high, &ss32->port_high))
54774 return -EFAULT;
54775@@ -702,8 +702,8 @@ static int do_i2c_rdwr_ioctl(unsigned int fd, unsigned int cmd,
54776 for (i = 0; i < nmsgs; i++) {
54777 if (copy_in_user(&tmsgs[i].addr, &umsgs[i].addr, 3*sizeof(u16)))
54778 return -EFAULT;
54779- if (get_user(datap, &umsgs[i].buf) ||
54780- put_user(compat_ptr(datap), &tmsgs[i].buf))
54781+ if (get_user(datap, (u8 __user * __user *)&umsgs[i].buf) ||
54782+ put_user(compat_ptr(datap), (u8 __user * __user *)&tmsgs[i].buf))
54783 return -EFAULT;
54784 }
54785 return sys_ioctl(fd, cmd, (unsigned long)tdata);
54786@@ -796,7 +796,7 @@ static int compat_ioctl_preallocate(struct file *file,
54787 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
54788 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
54789 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
54790- copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
54791+ copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
54792 return -EFAULT;
54793
54794 return ioctl_preallocate(file, p);
54795@@ -1616,8 +1616,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
54796 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
54797 {
54798 unsigned int a, b;
54799- a = *(unsigned int *)p;
54800- b = *(unsigned int *)q;
54801+ a = *(const unsigned int *)p;
54802+ b = *(const unsigned int *)q;
54803 if (a > b)
54804 return 1;
54805 if (a < b)
54806diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
54807index 277bd1b..f312c9e 100644
54808--- a/fs/configfs/dir.c
54809+++ b/fs/configfs/dir.c
54810@@ -1546,7 +1546,8 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
54811 }
54812 for (p = q->next; p != &parent_sd->s_children; p = p->next) {
54813 struct configfs_dirent *next;
54814- const char *name;
54815+ const unsigned char * name;
54816+ char d_name[sizeof(next->s_dentry->d_iname)];
54817 int len;
54818 struct inode *inode = NULL;
54819
54820@@ -1555,7 +1556,12 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
54821 continue;
54822
54823 name = configfs_get_name(next);
54824- len = strlen(name);
54825+ if (next->s_dentry && name == next->s_dentry->d_iname) {
54826+ len = next->s_dentry->d_name.len;
54827+ memcpy(d_name, name, len);
54828+ name = d_name;
54829+ } else
54830+ len = strlen(name);
54831
54832 /*
54833 * We'll have a dentry and an inode for
54834diff --git a/fs/coredump.c b/fs/coredump.c
54835index 9bdeca1..2247b92 100644
54836--- a/fs/coredump.c
54837+++ b/fs/coredump.c
54838@@ -438,8 +438,8 @@ static void wait_for_dump_helpers(struct file *file)
54839 struct pipe_inode_info *pipe = file->private_data;
54840
54841 pipe_lock(pipe);
54842- pipe->readers++;
54843- pipe->writers--;
54844+ atomic_inc(&pipe->readers);
54845+ atomic_dec(&pipe->writers);
54846 wake_up_interruptible_sync(&pipe->wait);
54847 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
54848 pipe_unlock(pipe);
54849@@ -448,11 +448,11 @@ static void wait_for_dump_helpers(struct file *file)
54850 * We actually want wait_event_freezable() but then we need
54851 * to clear TIF_SIGPENDING and improve dump_interrupted().
54852 */
54853- wait_event_interruptible(pipe->wait, pipe->readers == 1);
54854+ wait_event_interruptible(pipe->wait, atomic_read(&pipe->readers) == 1);
54855
54856 pipe_lock(pipe);
54857- pipe->readers--;
54858- pipe->writers++;
54859+ atomic_dec(&pipe->readers);
54860+ atomic_inc(&pipe->writers);
54861 pipe_unlock(pipe);
54862 }
54863
54864@@ -499,7 +499,8 @@ void do_coredump(siginfo_t *siginfo)
54865 struct files_struct *displaced;
54866 bool need_nonrelative = false;
54867 bool core_dumped = false;
54868- static atomic_t core_dump_count = ATOMIC_INIT(0);
54869+ static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
54870+ long signr = siginfo->si_signo;
54871 struct coredump_params cprm = {
54872 .siginfo = siginfo,
54873 .regs = signal_pt_regs(),
54874@@ -512,7 +513,10 @@ void do_coredump(siginfo_t *siginfo)
54875 .mm_flags = mm->flags,
54876 };
54877
54878- audit_core_dumps(siginfo->si_signo);
54879+ audit_core_dumps(signr);
54880+
54881+ if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
54882+ gr_handle_brute_attach(cprm.mm_flags);
54883
54884 binfmt = mm->binfmt;
54885 if (!binfmt || !binfmt->core_dump)
54886@@ -536,7 +540,7 @@ void do_coredump(siginfo_t *siginfo)
54887 need_nonrelative = true;
54888 }
54889
54890- retval = coredump_wait(siginfo->si_signo, &core_state);
54891+ retval = coredump_wait(signr, &core_state);
54892 if (retval < 0)
54893 goto fail_creds;
54894
54895@@ -579,7 +583,7 @@ void do_coredump(siginfo_t *siginfo)
54896 }
54897 cprm.limit = RLIM_INFINITY;
54898
54899- dump_count = atomic_inc_return(&core_dump_count);
54900+ dump_count = atomic_inc_return_unchecked(&core_dump_count);
54901 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
54902 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
54903 task_tgid_vnr(current), current->comm);
54904@@ -611,6 +615,8 @@ void do_coredump(siginfo_t *siginfo)
54905 } else {
54906 struct inode *inode;
54907
54908+ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
54909+
54910 if (cprm.limit < binfmt->min_coredump)
54911 goto fail_unlock;
54912
54913@@ -669,7 +675,7 @@ close_fail:
54914 filp_close(cprm.file, NULL);
54915 fail_dropcount:
54916 if (ispipe)
54917- atomic_dec(&core_dump_count);
54918+ atomic_dec_unchecked(&core_dump_count);
54919 fail_unlock:
54920 kfree(cn.corename);
54921 coredump_finish(mm, core_dumped);
54922@@ -689,7 +695,7 @@ int dump_write(struct file *file, const void *addr, int nr)
54923 {
54924 return !dump_interrupted() &&
54925 access_ok(VERIFY_READ, addr, nr) &&
54926- file->f_op->write(file, addr, nr, &file->f_pos) == nr;
54927+ file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
54928 }
54929 EXPORT_SYMBOL(dump_write);
54930
54931diff --git a/fs/dcache.c b/fs/dcache.c
54932index ae6ebb8..5977a84 100644
54933--- a/fs/dcache.c
54934+++ b/fs/dcache.c
54935@@ -2881,9 +2881,9 @@ static int prepend_path(const struct path *path,
54936 const struct path *root,
54937 char **buffer, int *buflen)
54938 {
54939- struct dentry *dentry = path->dentry;
54940- struct vfsmount *vfsmnt = path->mnt;
54941- struct mount *mnt = real_mount(vfsmnt);
54942+ struct dentry *dentry;
54943+ struct vfsmount *vfsmnt;
54944+ struct mount *mnt;
54945 int error = 0;
54946 unsigned seq = 0;
54947 char *bptr;
54948@@ -2893,6 +2893,10 @@ static int prepend_path(const struct path *path,
54949 restart:
54950 bptr = *buffer;
54951 blen = *buflen;
54952+ error = 0;
54953+ dentry = path->dentry;
54954+ vfsmnt = path->mnt;
54955+ mnt = real_mount(vfsmnt);
54956 read_seqbegin_or_lock(&rename_lock, &seq);
54957 while (dentry != root->dentry || vfsmnt != root->mnt) {
54958 struct dentry * parent;
54959@@ -3429,7 +3433,8 @@ void __init vfs_caches_init(unsigned long mempages)
54960 mempages -= reserve;
54961
54962 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
54963- SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
54964+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY|
54965+ SLAB_NO_SANITIZE, NULL);
54966
54967 dcache_init();
54968 inode_init();
54969diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
54970index c7c83ff..bda9461 100644
54971--- a/fs/debugfs/inode.c
54972+++ b/fs/debugfs/inode.c
54973@@ -415,7 +415,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
54974 */
54975 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
54976 {
54977+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
54978+ return __create_file(name, S_IFDIR | S_IRWXU,
54979+#else
54980 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
54981+#endif
54982 parent, NULL, NULL);
54983 }
54984 EXPORT_SYMBOL_GPL(debugfs_create_dir);
54985diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
54986index 67e9b63..a9adb68 100644
54987--- a/fs/ecryptfs/inode.c
54988+++ b/fs/ecryptfs/inode.c
54989@@ -674,7 +674,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
54990 old_fs = get_fs();
54991 set_fs(get_ds());
54992 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
54993- (char __user *)lower_buf,
54994+ (char __force_user *)lower_buf,
54995 PATH_MAX);
54996 set_fs(old_fs);
54997 if (rc < 0)
54998@@ -706,7 +706,7 @@ out:
54999 static void
55000 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
55001 {
55002- char *buf = nd_get_link(nd);
55003+ const char *buf = nd_get_link(nd);
55004 if (!IS_ERR(buf)) {
55005 /* Free the char* */
55006 kfree(buf);
55007diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
55008index e4141f2..d8263e8 100644
55009--- a/fs/ecryptfs/miscdev.c
55010+++ b/fs/ecryptfs/miscdev.c
55011@@ -304,7 +304,7 @@ check_list:
55012 goto out_unlock_msg_ctx;
55013 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
55014 if (msg_ctx->msg) {
55015- if (copy_to_user(&buf[i], packet_length, packet_length_size))
55016+ if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
55017 goto out_unlock_msg_ctx;
55018 i += packet_length_size;
55019 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
55020diff --git a/fs/exec.c b/fs/exec.c
55021index 8875dd1..c53682a 100644
55022--- a/fs/exec.c
55023+++ b/fs/exec.c
55024@@ -55,8 +55,20 @@
55025 #include <linux/pipe_fs_i.h>
55026 #include <linux/oom.h>
55027 #include <linux/compat.h>
55028+#include <linux/random.h>
55029+#include <linux/seq_file.h>
55030+#include <linux/coredump.h>
55031+#include <linux/mman.h>
55032+
55033+#ifdef CONFIG_PAX_REFCOUNT
55034+#include <linux/kallsyms.h>
55035+#include <linux/kdebug.h>
55036+#endif
55037+
55038+#include <trace/events/fs.h>
55039
55040 #include <asm/uaccess.h>
55041+#include <asm/sections.h>
55042 #include <asm/mmu_context.h>
55043 #include <asm/tlb.h>
55044
55045@@ -66,19 +78,34 @@
55046
55047 #include <trace/events/sched.h>
55048
55049+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
55050+void __weak pax_set_initial_flags(struct linux_binprm *bprm)
55051+{
55052+ 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");
55053+}
55054+#endif
55055+
55056+#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
55057+void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
55058+EXPORT_SYMBOL(pax_set_initial_flags_func);
55059+#endif
55060+
55061 int suid_dumpable = 0;
55062
55063 static LIST_HEAD(formats);
55064 static DEFINE_RWLOCK(binfmt_lock);
55065
55066+extern int gr_process_kernel_exec_ban(void);
55067+extern int gr_process_suid_exec_ban(const struct linux_binprm *bprm);
55068+
55069 void __register_binfmt(struct linux_binfmt * fmt, int insert)
55070 {
55071 BUG_ON(!fmt);
55072 if (WARN_ON(!fmt->load_binary))
55073 return;
55074 write_lock(&binfmt_lock);
55075- insert ? list_add(&fmt->lh, &formats) :
55076- list_add_tail(&fmt->lh, &formats);
55077+ insert ? pax_list_add((struct list_head *)&fmt->lh, &formats) :
55078+ pax_list_add_tail((struct list_head *)&fmt->lh, &formats);
55079 write_unlock(&binfmt_lock);
55080 }
55081
55082@@ -87,7 +114,7 @@ EXPORT_SYMBOL(__register_binfmt);
55083 void unregister_binfmt(struct linux_binfmt * fmt)
55084 {
55085 write_lock(&binfmt_lock);
55086- list_del(&fmt->lh);
55087+ pax_list_del((struct list_head *)&fmt->lh);
55088 write_unlock(&binfmt_lock);
55089 }
55090
55091@@ -183,18 +210,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
55092 int write)
55093 {
55094 struct page *page;
55095- int ret;
55096
55097-#ifdef CONFIG_STACK_GROWSUP
55098- if (write) {
55099- ret = expand_downwards(bprm->vma, pos);
55100- if (ret < 0)
55101- return NULL;
55102- }
55103-#endif
55104- ret = get_user_pages(current, bprm->mm, pos,
55105- 1, write, 1, &page, NULL);
55106- if (ret <= 0)
55107+ if (0 > expand_downwards(bprm->vma, pos))
55108+ return NULL;
55109+ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
55110 return NULL;
55111
55112 if (write) {
55113@@ -210,6 +229,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
55114 if (size <= ARG_MAX)
55115 return page;
55116
55117+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55118+ // only allow 512KB for argv+env on suid/sgid binaries
55119+ // to prevent easy ASLR exhaustion
55120+ if (((!uid_eq(bprm->cred->euid, current_euid())) ||
55121+ (!gid_eq(bprm->cred->egid, current_egid()))) &&
55122+ (size > (512 * 1024))) {
55123+ put_page(page);
55124+ return NULL;
55125+ }
55126+#endif
55127+
55128 /*
55129 * Limit to 1/4-th the stack size for the argv+env strings.
55130 * This ensures that:
55131@@ -269,6 +299,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
55132 vma->vm_end = STACK_TOP_MAX;
55133 vma->vm_start = vma->vm_end - PAGE_SIZE;
55134 vma->vm_flags = VM_SOFTDIRTY | VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
55135+
55136+#ifdef CONFIG_PAX_SEGMEXEC
55137+ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
55138+#endif
55139+
55140 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
55141 INIT_LIST_HEAD(&vma->anon_vma_chain);
55142
55143@@ -279,6 +314,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
55144 mm->stack_vm = mm->total_vm = 1;
55145 up_write(&mm->mmap_sem);
55146 bprm->p = vma->vm_end - sizeof(void *);
55147+
55148+#ifdef CONFIG_PAX_RANDUSTACK
55149+ if (randomize_va_space)
55150+ bprm->p ^= prandom_u32() & ~PAGE_MASK;
55151+#endif
55152+
55153 return 0;
55154 err:
55155 up_write(&mm->mmap_sem);
55156@@ -399,7 +440,7 @@ struct user_arg_ptr {
55157 } ptr;
55158 };
55159
55160-static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
55161+const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
55162 {
55163 const char __user *native;
55164
55165@@ -408,14 +449,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
55166 compat_uptr_t compat;
55167
55168 if (get_user(compat, argv.ptr.compat + nr))
55169- return ERR_PTR(-EFAULT);
55170+ return (const char __force_user *)ERR_PTR(-EFAULT);
55171
55172 return compat_ptr(compat);
55173 }
55174 #endif
55175
55176 if (get_user(native, argv.ptr.native + nr))
55177- return ERR_PTR(-EFAULT);
55178+ return (const char __force_user *)ERR_PTR(-EFAULT);
55179
55180 return native;
55181 }
55182@@ -434,7 +475,7 @@ static int count(struct user_arg_ptr argv, int max)
55183 if (!p)
55184 break;
55185
55186- if (IS_ERR(p))
55187+ if (IS_ERR((const char __force_kernel *)p))
55188 return -EFAULT;
55189
55190 if (i >= max)
55191@@ -469,7 +510,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
55192
55193 ret = -EFAULT;
55194 str = get_user_arg_ptr(argv, argc);
55195- if (IS_ERR(str))
55196+ if (IS_ERR((const char __force_kernel *)str))
55197 goto out;
55198
55199 len = strnlen_user(str, MAX_ARG_STRLEN);
55200@@ -551,7 +592,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
55201 int r;
55202 mm_segment_t oldfs = get_fs();
55203 struct user_arg_ptr argv = {
55204- .ptr.native = (const char __user *const __user *)__argv,
55205+ .ptr.native = (const char __force_user * const __force_user *)__argv,
55206 };
55207
55208 set_fs(KERNEL_DS);
55209@@ -586,7 +627,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
55210 unsigned long new_end = old_end - shift;
55211 struct mmu_gather tlb;
55212
55213- BUG_ON(new_start > new_end);
55214+ if (new_start >= new_end || new_start < mmap_min_addr)
55215+ return -ENOMEM;
55216
55217 /*
55218 * ensure there are no vmas between where we want to go
55219@@ -595,6 +637,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
55220 if (vma != find_vma(mm, new_start))
55221 return -EFAULT;
55222
55223+#ifdef CONFIG_PAX_SEGMEXEC
55224+ BUG_ON(pax_find_mirror_vma(vma));
55225+#endif
55226+
55227 /*
55228 * cover the whole range: [new_start, old_end)
55229 */
55230@@ -675,10 +721,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
55231 stack_top = arch_align_stack(stack_top);
55232 stack_top = PAGE_ALIGN(stack_top);
55233
55234- if (unlikely(stack_top < mmap_min_addr) ||
55235- unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
55236- return -ENOMEM;
55237-
55238 stack_shift = vma->vm_end - stack_top;
55239
55240 bprm->p -= stack_shift;
55241@@ -690,8 +732,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
55242 bprm->exec -= stack_shift;
55243
55244 down_write(&mm->mmap_sem);
55245+
55246+ /* Move stack pages down in memory. */
55247+ if (stack_shift) {
55248+ ret = shift_arg_pages(vma, stack_shift);
55249+ if (ret)
55250+ goto out_unlock;
55251+ }
55252+
55253 vm_flags = VM_STACK_FLAGS;
55254
55255+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
55256+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
55257+ vm_flags &= ~VM_EXEC;
55258+
55259+#ifdef CONFIG_PAX_MPROTECT
55260+ if (mm->pax_flags & MF_PAX_MPROTECT)
55261+ vm_flags &= ~VM_MAYEXEC;
55262+#endif
55263+
55264+ }
55265+#endif
55266+
55267 /*
55268 * Adjust stack execute permissions; explicitly enable for
55269 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
55270@@ -710,13 +772,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
55271 goto out_unlock;
55272 BUG_ON(prev != vma);
55273
55274- /* Move stack pages down in memory. */
55275- if (stack_shift) {
55276- ret = shift_arg_pages(vma, stack_shift);
55277- if (ret)
55278- goto out_unlock;
55279- }
55280-
55281 /* mprotect_fixup is overkill to remove the temporary stack flags */
55282 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
55283
55284@@ -740,6 +795,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
55285 #endif
55286 current->mm->start_stack = bprm->p;
55287 ret = expand_stack(vma, stack_base);
55288+
55289+#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_RANDMMAP)
55290+ if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
55291+ unsigned long size;
55292+ vm_flags_t vm_flags;
55293+
55294+ size = STACK_TOP - vma->vm_end;
55295+ vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
55296+
55297+ ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, vm_flags, 0);
55298+
55299+#ifdef CONFIG_X86
55300+ if (!ret) {
55301+ size = PAGE_SIZE + mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
55302+ ret = 0 != mmap_region(NULL, 0, PAGE_ALIGN(size), vm_flags, 0);
55303+ }
55304+#endif
55305+
55306+ }
55307+#endif
55308+
55309 if (ret)
55310 ret = -EFAULT;
55311
55312@@ -776,6 +852,8 @@ struct file *open_exec(const char *name)
55313
55314 fsnotify_open(file);
55315
55316+ trace_open_exec(name);
55317+
55318 err = deny_write_access(file);
55319 if (err)
55320 goto exit;
55321@@ -799,7 +877,7 @@ int kernel_read(struct file *file, loff_t offset,
55322 old_fs = get_fs();
55323 set_fs(get_ds());
55324 /* The cast to a user pointer is valid due to the set_fs() */
55325- result = vfs_read(file, (void __user *)addr, count, &pos);
55326+ result = vfs_read(file, (void __force_user *)addr, count, &pos);
55327 set_fs(old_fs);
55328 return result;
55329 }
55330@@ -1255,7 +1333,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
55331 }
55332 rcu_read_unlock();
55333
55334- if (p->fs->users > n_fs) {
55335+ if (atomic_read(&p->fs->users) > n_fs) {
55336 bprm->unsafe |= LSM_UNSAFE_SHARE;
55337 } else {
55338 res = -EAGAIN;
55339@@ -1451,6 +1529,31 @@ static int exec_binprm(struct linux_binprm *bprm)
55340 return ret;
55341 }
55342
55343+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55344+static DEFINE_PER_CPU(u64, exec_counter);
55345+static int __init init_exec_counters(void)
55346+{
55347+ unsigned int cpu;
55348+
55349+ for_each_possible_cpu(cpu) {
55350+ per_cpu(exec_counter, cpu) = (u64)cpu;
55351+ }
55352+
55353+ return 0;
55354+}
55355+early_initcall(init_exec_counters);
55356+static inline void increment_exec_counter(void)
55357+{
55358+ BUILD_BUG_ON(NR_CPUS > (1 << 16));
55359+ current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
55360+}
55361+#else
55362+static inline void increment_exec_counter(void) {}
55363+#endif
55364+
55365+extern void gr_handle_exec_args(struct linux_binprm *bprm,
55366+ struct user_arg_ptr argv);
55367+
55368 /*
55369 * sys_execve() executes a new program.
55370 */
55371@@ -1458,12 +1561,19 @@ static int do_execve_common(const char *filename,
55372 struct user_arg_ptr argv,
55373 struct user_arg_ptr envp)
55374 {
55375+#ifdef CONFIG_GRKERNSEC
55376+ struct file *old_exec_file;
55377+ struct acl_subject_label *old_acl;
55378+ struct rlimit old_rlim[RLIM_NLIMITS];
55379+#endif
55380 struct linux_binprm *bprm;
55381 struct file *file;
55382 struct files_struct *displaced;
55383 bool clear_in_exec;
55384 int retval;
55385
55386+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current_user()->processes), 1);
55387+
55388 /*
55389 * We move the actual failure in case of RLIMIT_NPROC excess from
55390 * set*uid() to execve() because too many poorly written programs
55391@@ -1504,12 +1614,22 @@ static int do_execve_common(const char *filename,
55392 if (IS_ERR(file))
55393 goto out_unmark;
55394
55395+ if (gr_ptrace_readexec(file, bprm->unsafe)) {
55396+ retval = -EPERM;
55397+ goto out_file;
55398+ }
55399+
55400 sched_exec();
55401
55402 bprm->file = file;
55403 bprm->filename = filename;
55404 bprm->interp = filename;
55405
55406+ if (!gr_acl_handle_execve(file->f_path.dentry, file->f_path.mnt)) {
55407+ retval = -EACCES;
55408+ goto out_file;
55409+ }
55410+
55411 retval = bprm_mm_init(bprm);
55412 if (retval)
55413 goto out_file;
55414@@ -1526,24 +1646,70 @@ static int do_execve_common(const char *filename,
55415 if (retval < 0)
55416 goto out;
55417
55418+#ifdef CONFIG_GRKERNSEC
55419+ old_acl = current->acl;
55420+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
55421+ old_exec_file = current->exec_file;
55422+ get_file(file);
55423+ current->exec_file = file;
55424+#endif
55425+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55426+ /* limit suid stack to 8MB
55427+ * we saved the old limits above and will restore them if this exec fails
55428+ */
55429+ if (((!uid_eq(bprm->cred->euid, current_euid())) || (!gid_eq(bprm->cred->egid, current_egid()))) &&
55430+ (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
55431+ current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
55432+#endif
55433+
55434+ if (gr_process_kernel_exec_ban() || gr_process_suid_exec_ban(bprm)) {
55435+ retval = -EPERM;
55436+ goto out_fail;
55437+ }
55438+
55439+ if (!gr_tpe_allow(file)) {
55440+ retval = -EACCES;
55441+ goto out_fail;
55442+ }
55443+
55444+ if (gr_check_crash_exec(file)) {
55445+ retval = -EACCES;
55446+ goto out_fail;
55447+ }
55448+
55449+ retval = gr_set_proc_label(file->f_path.dentry, file->f_path.mnt,
55450+ bprm->unsafe);
55451+ if (retval < 0)
55452+ goto out_fail;
55453+
55454 retval = copy_strings_kernel(1, &bprm->filename, bprm);
55455 if (retval < 0)
55456- goto out;
55457+ goto out_fail;
55458
55459 bprm->exec = bprm->p;
55460 retval = copy_strings(bprm->envc, envp, bprm);
55461 if (retval < 0)
55462- goto out;
55463+ goto out_fail;
55464
55465 retval = copy_strings(bprm->argc, argv, bprm);
55466 if (retval < 0)
55467- goto out;
55468+ goto out_fail;
55469+
55470+ gr_log_chroot_exec(file->f_path.dentry, file->f_path.mnt);
55471+
55472+ gr_handle_exec_args(bprm, argv);
55473
55474 retval = exec_binprm(bprm);
55475 if (retval < 0)
55476- goto out;
55477+ goto out_fail;
55478+#ifdef CONFIG_GRKERNSEC
55479+ if (old_exec_file)
55480+ fput(old_exec_file);
55481+#endif
55482
55483 /* execve succeeded */
55484+
55485+ increment_exec_counter();
55486 current->fs->in_exec = 0;
55487 current->in_execve = 0;
55488 acct_update_integrals(current);
55489@@ -1552,6 +1718,14 @@ static int do_execve_common(const char *filename,
55490 put_files_struct(displaced);
55491 return retval;
55492
55493+out_fail:
55494+#ifdef CONFIG_GRKERNSEC
55495+ current->acl = old_acl;
55496+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
55497+ fput(current->exec_file);
55498+ current->exec_file = old_exec_file;
55499+#endif
55500+
55501 out:
55502 if (bprm->mm) {
55503 acct_arg_size(bprm, 0);
55504@@ -1700,3 +1874,295 @@ asmlinkage long compat_sys_execve(const char __user * filename,
55505 return error;
55506 }
55507 #endif
55508+
55509+int pax_check_flags(unsigned long *flags)
55510+{
55511+ int retval = 0;
55512+
55513+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
55514+ if (*flags & MF_PAX_SEGMEXEC)
55515+ {
55516+ *flags &= ~MF_PAX_SEGMEXEC;
55517+ retval = -EINVAL;
55518+ }
55519+#endif
55520+
55521+ if ((*flags & MF_PAX_PAGEEXEC)
55522+
55523+#ifdef CONFIG_PAX_PAGEEXEC
55524+ && (*flags & MF_PAX_SEGMEXEC)
55525+#endif
55526+
55527+ )
55528+ {
55529+ *flags &= ~MF_PAX_PAGEEXEC;
55530+ retval = -EINVAL;
55531+ }
55532+
55533+ if ((*flags & MF_PAX_MPROTECT)
55534+
55535+#ifdef CONFIG_PAX_MPROTECT
55536+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
55537+#endif
55538+
55539+ )
55540+ {
55541+ *flags &= ~MF_PAX_MPROTECT;
55542+ retval = -EINVAL;
55543+ }
55544+
55545+ if ((*flags & MF_PAX_EMUTRAMP)
55546+
55547+#ifdef CONFIG_PAX_EMUTRAMP
55548+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
55549+#endif
55550+
55551+ )
55552+ {
55553+ *flags &= ~MF_PAX_EMUTRAMP;
55554+ retval = -EINVAL;
55555+ }
55556+
55557+ return retval;
55558+}
55559+
55560+EXPORT_SYMBOL(pax_check_flags);
55561+
55562+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
55563+char *pax_get_path(const struct path *path, char *buf, int buflen)
55564+{
55565+ char *pathname = d_path(path, buf, buflen);
55566+
55567+ if (IS_ERR(pathname))
55568+ goto toolong;
55569+
55570+ pathname = mangle_path(buf, pathname, "\t\n\\");
55571+ if (!pathname)
55572+ goto toolong;
55573+
55574+ *pathname = 0;
55575+ return buf;
55576+
55577+toolong:
55578+ return "<path too long>";
55579+}
55580+EXPORT_SYMBOL(pax_get_path);
55581+
55582+void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
55583+{
55584+ struct task_struct *tsk = current;
55585+ struct mm_struct *mm = current->mm;
55586+ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
55587+ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
55588+ char *path_exec = NULL;
55589+ char *path_fault = NULL;
55590+ unsigned long start = 0UL, end = 0UL, offset = 0UL;
55591+ siginfo_t info = { };
55592+
55593+ if (buffer_exec && buffer_fault) {
55594+ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
55595+
55596+ down_read(&mm->mmap_sem);
55597+ vma = mm->mmap;
55598+ while (vma && (!vma_exec || !vma_fault)) {
55599+ if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
55600+ vma_exec = vma;
55601+ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
55602+ vma_fault = vma;
55603+ vma = vma->vm_next;
55604+ }
55605+ if (vma_exec)
55606+ path_exec = pax_get_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
55607+ if (vma_fault) {
55608+ start = vma_fault->vm_start;
55609+ end = vma_fault->vm_end;
55610+ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
55611+ if (vma_fault->vm_file)
55612+ path_fault = pax_get_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
55613+ else if ((unsigned long)pc >= mm->start_brk && (unsigned long)pc < mm->brk)
55614+ path_fault = "<heap>";
55615+ else if (vma_fault->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
55616+ path_fault = "<stack>";
55617+ else
55618+ path_fault = "<anonymous mapping>";
55619+ }
55620+ up_read(&mm->mmap_sem);
55621+ }
55622+ if (tsk->signal->curr_ip)
55623+ printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
55624+ else
55625+ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
55626+ 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),
55627+ from_kuid_munged(&init_user_ns, task_uid(tsk)), from_kuid_munged(&init_user_ns, task_euid(tsk)), pc, sp);
55628+ free_page((unsigned long)buffer_exec);
55629+ free_page((unsigned long)buffer_fault);
55630+ pax_report_insns(regs, pc, sp);
55631+ info.si_signo = SIGKILL;
55632+ info.si_errno = 0;
55633+ info.si_code = SI_KERNEL;
55634+ info.si_pid = 0;
55635+ info.si_uid = 0;
55636+ do_coredump(&info);
55637+}
55638+#endif
55639+
55640+#ifdef CONFIG_PAX_REFCOUNT
55641+void pax_report_refcount_overflow(struct pt_regs *regs)
55642+{
55643+ if (current->signal->curr_ip)
55644+ printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
55645+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
55646+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
55647+ else
55648+ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
55649+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
55650+ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
55651+ preempt_disable();
55652+ show_regs(regs);
55653+ preempt_enable();
55654+ force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
55655+}
55656+#endif
55657+
55658+#ifdef CONFIG_PAX_USERCOPY
55659+/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
55660+static noinline int check_stack_object(const void *obj, unsigned long len)
55661+{
55662+ const void * const stack = task_stack_page(current);
55663+ const void * const stackend = stack + THREAD_SIZE;
55664+
55665+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
55666+ const void *frame = NULL;
55667+ const void *oldframe;
55668+#endif
55669+
55670+ if (obj + len < obj)
55671+ return -1;
55672+
55673+ if (obj + len <= stack || stackend <= obj)
55674+ return 0;
55675+
55676+ if (obj < stack || stackend < obj + len)
55677+ return -1;
55678+
55679+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
55680+ oldframe = __builtin_frame_address(1);
55681+ if (oldframe)
55682+ frame = __builtin_frame_address(2);
55683+ /*
55684+ low ----------------------------------------------> high
55685+ [saved bp][saved ip][args][local vars][saved bp][saved ip]
55686+ ^----------------^
55687+ allow copies only within here
55688+ */
55689+ while (stack <= frame && frame < stackend) {
55690+ /* if obj + len extends past the last frame, this
55691+ check won't pass and the next frame will be 0,
55692+ causing us to bail out and correctly report
55693+ the copy as invalid
55694+ */
55695+ if (obj + len <= frame)
55696+ return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
55697+ oldframe = frame;
55698+ frame = *(const void * const *)frame;
55699+ }
55700+ return -1;
55701+#else
55702+ return 1;
55703+#endif
55704+}
55705+
55706+static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to_user, const char *type)
55707+{
55708+ if (current->signal->curr_ip)
55709+ printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
55710+ &current->signal->curr_ip, to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
55711+ else
55712+ printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
55713+ to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
55714+ dump_stack();
55715+ gr_handle_kernel_exploit();
55716+ do_group_exit(SIGKILL);
55717+}
55718+#endif
55719+
55720+#ifdef CONFIG_PAX_USERCOPY
55721+static inline bool check_kernel_text_object(unsigned long low, unsigned long high)
55722+{
55723+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
55724+ unsigned long textlow = ktla_ktva((unsigned long)_stext);
55725+#ifdef CONFIG_MODULES
55726+ unsigned long texthigh = (unsigned long)MODULES_EXEC_VADDR;
55727+#else
55728+ unsigned long texthigh = ktla_ktva((unsigned long)_etext);
55729+#endif
55730+
55731+#else
55732+ unsigned long textlow = (unsigned long)_stext;
55733+ unsigned long texthigh = (unsigned long)_etext;
55734+
55735+#ifdef CONFIG_X86_64
55736+ /* check against linear mapping as well */
55737+ if (high > (unsigned long)__va(__pa(textlow)) &&
55738+ low <= (unsigned long)__va(__pa(texthigh)))
55739+ return true;
55740+#endif
55741+
55742+#endif
55743+
55744+ if (high <= textlow || low > texthigh)
55745+ return false;
55746+ else
55747+ return true;
55748+}
55749+#endif
55750+
55751+void __check_object_size(const void *ptr, unsigned long n, bool to_user)
55752+{
55753+
55754+#ifdef CONFIG_PAX_USERCOPY
55755+ const char *type;
55756+
55757+ if (!n)
55758+ return;
55759+
55760+ type = check_heap_object(ptr, n);
55761+ if (!type) {
55762+ int ret = check_stack_object(ptr, n);
55763+ if (ret == 1 || ret == 2)
55764+ return;
55765+ if (ret == 0) {
55766+ if (check_kernel_text_object((unsigned long)ptr, (unsigned long)ptr + n))
55767+ type = "<kernel text>";
55768+ else
55769+ return;
55770+ } else
55771+ type = "<process stack>";
55772+ }
55773+
55774+ pax_report_usercopy(ptr, n, to_user, type);
55775+#endif
55776+
55777+}
55778+EXPORT_SYMBOL(__check_object_size);
55779+
55780+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
55781+void pax_track_stack(void)
55782+{
55783+ unsigned long sp = (unsigned long)&sp;
55784+ if (sp < current_thread_info()->lowest_stack &&
55785+ sp > (unsigned long)task_stack_page(current))
55786+ current_thread_info()->lowest_stack = sp;
55787+}
55788+EXPORT_SYMBOL(pax_track_stack);
55789+#endif
55790+
55791+#ifdef CONFIG_PAX_SIZE_OVERFLOW
55792+void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
55793+{
55794+ printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
55795+ dump_stack();
55796+ do_group_exit(SIGKILL);
55797+}
55798+EXPORT_SYMBOL(report_size_overflow);
55799+#endif
55800diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
55801index 9f9992b..8b59411 100644
55802--- a/fs/ext2/balloc.c
55803+++ b/fs/ext2/balloc.c
55804@@ -1184,10 +1184,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
55805
55806 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
55807 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
55808- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
55809+ if (free_blocks < root_blocks + 1 &&
55810 !uid_eq(sbi->s_resuid, current_fsuid()) &&
55811 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
55812- !in_group_p (sbi->s_resgid))) {
55813+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
55814 return 0;
55815 }
55816 return 1;
55817diff --git a/fs/ext2/xattr.c b/fs/ext2/xattr.c
55818index 2d7557d..14e38f94 100644
55819--- a/fs/ext2/xattr.c
55820+++ b/fs/ext2/xattr.c
55821@@ -247,7 +247,7 @@ ext2_xattr_list(struct dentry *dentry, char *buffer, size_t buffer_size)
55822 struct buffer_head *bh = NULL;
55823 struct ext2_xattr_entry *entry;
55824 char *end;
55825- size_t rest = buffer_size;
55826+ size_t rest = buffer_size, total_size = 0;
55827 int error;
55828
55829 ea_idebug(inode, "buffer=%p, buffer_size=%ld",
55830@@ -305,9 +305,10 @@ bad_block: ext2_error(inode->i_sb, "ext2_xattr_list",
55831 buffer += size;
55832 }
55833 rest -= size;
55834+ total_size += size;
55835 }
55836 }
55837- error = buffer_size - rest; /* total size */
55838+ error = total_size;
55839
55840 cleanup:
55841 brelse(bh);
55842diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
55843index 22548f5..41521d8 100644
55844--- a/fs/ext3/balloc.c
55845+++ b/fs/ext3/balloc.c
55846@@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
55847
55848 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
55849 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
55850- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
55851+ if (free_blocks < root_blocks + 1 &&
55852 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
55853 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
55854- !in_group_p (sbi->s_resgid))) {
55855+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
55856 return 0;
55857 }
55858 return 1;
55859diff --git a/fs/ext3/xattr.c b/fs/ext3/xattr.c
55860index b1fc963..881228c 100644
55861--- a/fs/ext3/xattr.c
55862+++ b/fs/ext3/xattr.c
55863@@ -330,7 +330,7 @@ static int
55864 ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
55865 char *buffer, size_t buffer_size)
55866 {
55867- size_t rest = buffer_size;
55868+ size_t rest = buffer_size, total_size = 0;
55869
55870 for (; !IS_LAST_ENTRY(entry); entry = EXT3_XATTR_NEXT(entry)) {
55871 const struct xattr_handler *handler =
55872@@ -347,9 +347,10 @@ ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
55873 buffer += size;
55874 }
55875 rest -= size;
55876+ total_size += size;
55877 }
55878 }
55879- return buffer_size - rest;
55880+ return total_size;
55881 }
55882
55883 static int
55884diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
55885index dc5d572..4c21f8e 100644
55886--- a/fs/ext4/balloc.c
55887+++ b/fs/ext4/balloc.c
55888@@ -534,8 +534,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
55889 /* Hm, nope. Are (enough) root reserved clusters available? */
55890 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
55891 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
55892- capable(CAP_SYS_RESOURCE) ||
55893- (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
55894+ (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
55895+ capable_nolog(CAP_SYS_RESOURCE)) {
55896
55897 if (free_clusters >= (nclusters + dirty_clusters +
55898 resv_clusters))
55899diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
55900index af815ea..99294a6 100644
55901--- a/fs/ext4/ext4.h
55902+++ b/fs/ext4/ext4.h
55903@@ -1256,19 +1256,19 @@ struct ext4_sb_info {
55904 unsigned long s_mb_last_start;
55905
55906 /* stats for buddy allocator */
55907- atomic_t s_bal_reqs; /* number of reqs with len > 1 */
55908- atomic_t s_bal_success; /* we found long enough chunks */
55909- atomic_t s_bal_allocated; /* in blocks */
55910- atomic_t s_bal_ex_scanned; /* total extents scanned */
55911- atomic_t s_bal_goals; /* goal hits */
55912- atomic_t s_bal_breaks; /* too long searches */
55913- atomic_t s_bal_2orders; /* 2^order hits */
55914+ atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
55915+ atomic_unchecked_t s_bal_success; /* we found long enough chunks */
55916+ atomic_unchecked_t s_bal_allocated; /* in blocks */
55917+ atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
55918+ atomic_unchecked_t s_bal_goals; /* goal hits */
55919+ atomic_unchecked_t s_bal_breaks; /* too long searches */
55920+ atomic_unchecked_t s_bal_2orders; /* 2^order hits */
55921 spinlock_t s_bal_lock;
55922 unsigned long s_mb_buddies_generated;
55923 unsigned long long s_mb_generation_time;
55924- atomic_t s_mb_lost_chunks;
55925- atomic_t s_mb_preallocated;
55926- atomic_t s_mb_discarded;
55927+ atomic_unchecked_t s_mb_lost_chunks;
55928+ atomic_unchecked_t s_mb_preallocated;
55929+ atomic_unchecked_t s_mb_discarded;
55930 atomic_t s_lock_busy;
55931
55932 /* locality groups */
55933diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
55934index a41e3ba..e574a00 100644
55935--- a/fs/ext4/mballoc.c
55936+++ b/fs/ext4/mballoc.c
55937@@ -1880,7 +1880,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
55938 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
55939
55940 if (EXT4_SB(sb)->s_mb_stats)
55941- atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
55942+ atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
55943
55944 break;
55945 }
55946@@ -2189,7 +2189,7 @@ repeat:
55947 ac->ac_status = AC_STATUS_CONTINUE;
55948 ac->ac_flags |= EXT4_MB_HINT_FIRST;
55949 cr = 3;
55950- atomic_inc(&sbi->s_mb_lost_chunks);
55951+ atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
55952 goto repeat;
55953 }
55954 }
55955@@ -2697,25 +2697,25 @@ int ext4_mb_release(struct super_block *sb)
55956 if (sbi->s_mb_stats) {
55957 ext4_msg(sb, KERN_INFO,
55958 "mballoc: %u blocks %u reqs (%u success)",
55959- atomic_read(&sbi->s_bal_allocated),
55960- atomic_read(&sbi->s_bal_reqs),
55961- atomic_read(&sbi->s_bal_success));
55962+ atomic_read_unchecked(&sbi->s_bal_allocated),
55963+ atomic_read_unchecked(&sbi->s_bal_reqs),
55964+ atomic_read_unchecked(&sbi->s_bal_success));
55965 ext4_msg(sb, KERN_INFO,
55966 "mballoc: %u extents scanned, %u goal hits, "
55967 "%u 2^N hits, %u breaks, %u lost",
55968- atomic_read(&sbi->s_bal_ex_scanned),
55969- atomic_read(&sbi->s_bal_goals),
55970- atomic_read(&sbi->s_bal_2orders),
55971- atomic_read(&sbi->s_bal_breaks),
55972- atomic_read(&sbi->s_mb_lost_chunks));
55973+ atomic_read_unchecked(&sbi->s_bal_ex_scanned),
55974+ atomic_read_unchecked(&sbi->s_bal_goals),
55975+ atomic_read_unchecked(&sbi->s_bal_2orders),
55976+ atomic_read_unchecked(&sbi->s_bal_breaks),
55977+ atomic_read_unchecked(&sbi->s_mb_lost_chunks));
55978 ext4_msg(sb, KERN_INFO,
55979 "mballoc: %lu generated and it took %Lu",
55980 sbi->s_mb_buddies_generated,
55981 sbi->s_mb_generation_time);
55982 ext4_msg(sb, KERN_INFO,
55983 "mballoc: %u preallocated, %u discarded",
55984- atomic_read(&sbi->s_mb_preallocated),
55985- atomic_read(&sbi->s_mb_discarded));
55986+ atomic_read_unchecked(&sbi->s_mb_preallocated),
55987+ atomic_read_unchecked(&sbi->s_mb_discarded));
55988 }
55989
55990 free_percpu(sbi->s_locality_groups);
55991@@ -3169,16 +3169,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
55992 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
55993
55994 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
55995- atomic_inc(&sbi->s_bal_reqs);
55996- atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
55997+ atomic_inc_unchecked(&sbi->s_bal_reqs);
55998+ atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
55999 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
56000- atomic_inc(&sbi->s_bal_success);
56001- atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
56002+ atomic_inc_unchecked(&sbi->s_bal_success);
56003+ atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
56004 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
56005 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
56006- atomic_inc(&sbi->s_bal_goals);
56007+ atomic_inc_unchecked(&sbi->s_bal_goals);
56008 if (ac->ac_found > sbi->s_mb_max_to_scan)
56009- atomic_inc(&sbi->s_bal_breaks);
56010+ atomic_inc_unchecked(&sbi->s_bal_breaks);
56011 }
56012
56013 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
56014@@ -3578,7 +3578,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
56015 trace_ext4_mb_new_inode_pa(ac, pa);
56016
56017 ext4_mb_use_inode_pa(ac, pa);
56018- atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
56019+ atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
56020
56021 ei = EXT4_I(ac->ac_inode);
56022 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
56023@@ -3638,7 +3638,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
56024 trace_ext4_mb_new_group_pa(ac, pa);
56025
56026 ext4_mb_use_group_pa(ac, pa);
56027- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
56028+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
56029
56030 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
56031 lg = ac->ac_lg;
56032@@ -3727,7 +3727,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
56033 * from the bitmap and continue.
56034 */
56035 }
56036- atomic_add(free, &sbi->s_mb_discarded);
56037+ atomic_add_unchecked(free, &sbi->s_mb_discarded);
56038
56039 return err;
56040 }
56041@@ -3745,7 +3745,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
56042 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
56043 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
56044 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
56045- atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
56046+ atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
56047 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
56048
56049 return 0;
56050diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c
56051index 214461e..3614c89 100644
56052--- a/fs/ext4/mmp.c
56053+++ b/fs/ext4/mmp.c
56054@@ -113,7 +113,7 @@ static int read_mmp_block(struct super_block *sb, struct buffer_head **bh,
56055 void __dump_mmp_msg(struct super_block *sb, struct mmp_struct *mmp,
56056 const char *function, unsigned int line, const char *msg)
56057 {
56058- __ext4_warning(sb, function, line, msg);
56059+ __ext4_warning(sb, function, line, "%s", msg);
56060 __ext4_warning(sb, function, line,
56061 "MMP failure info: last update time: %llu, last update "
56062 "node: %s, last update device: %s\n",
56063diff --git a/fs/ext4/super.c b/fs/ext4/super.c
56064index 2c2e6cb..7c3ee62 100644
56065--- a/fs/ext4/super.c
56066+++ b/fs/ext4/super.c
56067@@ -1251,7 +1251,7 @@ static ext4_fsblk_t get_sb_block(void **data)
56068 }
56069
56070 #define DEFAULT_JOURNAL_IOPRIO (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 3))
56071-static char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
56072+static const char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
56073 "Contact linux-ext4@vger.kernel.org if you think we should keep it.\n";
56074
56075 #ifdef CONFIG_QUOTA
56076@@ -2431,7 +2431,7 @@ struct ext4_attr {
56077 int offset;
56078 int deprecated_val;
56079 } u;
56080-};
56081+} __do_const;
56082
56083 static int parse_strtoull(const char *buf,
56084 unsigned long long max, unsigned long long *value)
56085diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
56086index 03e9beb..e86ce98 100644
56087--- a/fs/ext4/xattr.c
56088+++ b/fs/ext4/xattr.c
56089@@ -381,7 +381,7 @@ static int
56090 ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
56091 char *buffer, size_t buffer_size)
56092 {
56093- size_t rest = buffer_size;
56094+ size_t rest = buffer_size, total_size = 0;
56095
56096 for (; !IS_LAST_ENTRY(entry); entry = EXT4_XATTR_NEXT(entry)) {
56097 const struct xattr_handler *handler =
56098@@ -398,9 +398,10 @@ ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
56099 buffer += size;
56100 }
56101 rest -= size;
56102+ total_size += size;
56103 }
56104 }
56105- return buffer_size - rest;
56106+ return total_size;
56107 }
56108
56109 static int
56110diff --git a/fs/fcntl.c b/fs/fcntl.c
56111index 65343c3..9969dcf 100644
56112--- a/fs/fcntl.c
56113+++ b/fs/fcntl.c
56114@@ -107,6 +107,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
56115 if (err)
56116 return err;
56117
56118+ if (gr_handle_chroot_fowner(pid, type))
56119+ return -ENOENT;
56120+ if (gr_check_protected_task_fowner(pid, type))
56121+ return -EACCES;
56122+
56123 f_modown(filp, pid, type, force);
56124 return 0;
56125 }
56126diff --git a/fs/fhandle.c b/fs/fhandle.c
56127index 999ff5c..41f4109 100644
56128--- a/fs/fhandle.c
56129+++ b/fs/fhandle.c
56130@@ -67,8 +67,7 @@ static long do_sys_name_to_handle(struct path *path,
56131 } else
56132 retval = 0;
56133 /* copy the mount id */
56134- if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
56135- sizeof(*mnt_id)) ||
56136+ if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
56137 copy_to_user(ufh, handle,
56138 sizeof(struct file_handle) + handle_bytes))
56139 retval = -EFAULT;
56140diff --git a/fs/file.c b/fs/file.c
56141index 4a78f98..9447397 100644
56142--- a/fs/file.c
56143+++ b/fs/file.c
56144@@ -16,6 +16,7 @@
56145 #include <linux/slab.h>
56146 #include <linux/vmalloc.h>
56147 #include <linux/file.h>
56148+#include <linux/security.h>
56149 #include <linux/fdtable.h>
56150 #include <linux/bitops.h>
56151 #include <linux/interrupt.h>
56152@@ -828,6 +829,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
56153 if (!file)
56154 return __close_fd(files, fd);
56155
56156+ gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
56157 if (fd >= rlimit(RLIMIT_NOFILE))
56158 return -EBADF;
56159
56160@@ -854,6 +856,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
56161 if (unlikely(oldfd == newfd))
56162 return -EINVAL;
56163
56164+ gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
56165 if (newfd >= rlimit(RLIMIT_NOFILE))
56166 return -EBADF;
56167
56168@@ -909,6 +912,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
56169 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
56170 {
56171 int err;
56172+ gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
56173 if (from >= rlimit(RLIMIT_NOFILE))
56174 return -EINVAL;
56175 err = alloc_fd(from, flags);
56176diff --git a/fs/filesystems.c b/fs/filesystems.c
56177index 92567d9..fcd8cbf 100644
56178--- a/fs/filesystems.c
56179+++ b/fs/filesystems.c
56180@@ -273,7 +273,11 @@ struct file_system_type *get_fs_type(const char *name)
56181 int len = dot ? dot - name : strlen(name);
56182
56183 fs = __get_fs_type(name, len);
56184+#ifdef CONFIG_GRKERNSEC_MODHARDEN
56185+ if (!fs && (___request_module(true, "grsec_modharden_fs", "fs-%.*s", len, name) == 0))
56186+#else
56187 if (!fs && (request_module("fs-%.*s", len, name) == 0))
56188+#endif
56189 fs = __get_fs_type(name, len);
56190
56191 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
56192diff --git a/fs/fs_struct.c b/fs/fs_struct.c
56193index d8ac61d..79a36f0 100644
56194--- a/fs/fs_struct.c
56195+++ b/fs/fs_struct.c
56196@@ -4,6 +4,7 @@
56197 #include <linux/path.h>
56198 #include <linux/slab.h>
56199 #include <linux/fs_struct.h>
56200+#include <linux/grsecurity.h>
56201 #include "internal.h"
56202
56203 /*
56204@@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, const struct path *path)
56205 write_seqcount_begin(&fs->seq);
56206 old_root = fs->root;
56207 fs->root = *path;
56208+ gr_set_chroot_entries(current, path);
56209 write_seqcount_end(&fs->seq);
56210 spin_unlock(&fs->lock);
56211 if (old_root.dentry)
56212@@ -67,6 +69,10 @@ void chroot_fs_refs(const struct path *old_root, const struct path *new_root)
56213 int hits = 0;
56214 spin_lock(&fs->lock);
56215 write_seqcount_begin(&fs->seq);
56216+ /* this root replacement is only done by pivot_root,
56217+ leave grsec's chroot tagging alone for this task
56218+ so that a pivoted root isn't treated as a chroot
56219+ */
56220 hits += replace_path(&fs->root, old_root, new_root);
56221 hits += replace_path(&fs->pwd, old_root, new_root);
56222 write_seqcount_end(&fs->seq);
56223@@ -99,7 +105,8 @@ void exit_fs(struct task_struct *tsk)
56224 task_lock(tsk);
56225 spin_lock(&fs->lock);
56226 tsk->fs = NULL;
56227- kill = !--fs->users;
56228+ gr_clear_chroot_entries(tsk);
56229+ kill = !atomic_dec_return(&fs->users);
56230 spin_unlock(&fs->lock);
56231 task_unlock(tsk);
56232 if (kill)
56233@@ -112,7 +119,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
56234 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
56235 /* We don't need to lock fs - think why ;-) */
56236 if (fs) {
56237- fs->users = 1;
56238+ atomic_set(&fs->users, 1);
56239 fs->in_exec = 0;
56240 spin_lock_init(&fs->lock);
56241 seqcount_init(&fs->seq);
56242@@ -121,6 +128,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
56243 spin_lock(&old->lock);
56244 fs->root = old->root;
56245 path_get(&fs->root);
56246+ /* instead of calling gr_set_chroot_entries here,
56247+ we call it from every caller of this function
56248+ */
56249 fs->pwd = old->pwd;
56250 path_get(&fs->pwd);
56251 spin_unlock(&old->lock);
56252@@ -139,8 +149,9 @@ int unshare_fs_struct(void)
56253
56254 task_lock(current);
56255 spin_lock(&fs->lock);
56256- kill = !--fs->users;
56257+ kill = !atomic_dec_return(&fs->users);
56258 current->fs = new_fs;
56259+ gr_set_chroot_entries(current, &new_fs->root);
56260 spin_unlock(&fs->lock);
56261 task_unlock(current);
56262
56263@@ -153,13 +164,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
56264
56265 int current_umask(void)
56266 {
56267- return current->fs->umask;
56268+ return current->fs->umask | gr_acl_umask();
56269 }
56270 EXPORT_SYMBOL(current_umask);
56271
56272 /* to be mentioned only in INIT_TASK */
56273 struct fs_struct init_fs = {
56274- .users = 1,
56275+ .users = ATOMIC_INIT(1),
56276 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
56277 .seq = SEQCNT_ZERO,
56278 .umask = 0022,
56279diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
56280index b2a86e3..37f425a 100644
56281--- a/fs/fscache/cookie.c
56282+++ b/fs/fscache/cookie.c
56283@@ -19,7 +19,7 @@
56284
56285 struct kmem_cache *fscache_cookie_jar;
56286
56287-static atomic_t fscache_object_debug_id = ATOMIC_INIT(0);
56288+static atomic_unchecked_t fscache_object_debug_id = ATOMIC_INIT(0);
56289
56290 static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie);
56291 static int fscache_alloc_object(struct fscache_cache *cache,
56292@@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
56293 parent ? (char *) parent->def->name : "<no-parent>",
56294 def->name, netfs_data);
56295
56296- fscache_stat(&fscache_n_acquires);
56297+ fscache_stat_unchecked(&fscache_n_acquires);
56298
56299 /* if there's no parent cookie, then we don't create one here either */
56300 if (!parent) {
56301- fscache_stat(&fscache_n_acquires_null);
56302+ fscache_stat_unchecked(&fscache_n_acquires_null);
56303 _leave(" [no parent]");
56304 return NULL;
56305 }
56306@@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
56307 /* allocate and initialise a cookie */
56308 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
56309 if (!cookie) {
56310- fscache_stat(&fscache_n_acquires_oom);
56311+ fscache_stat_unchecked(&fscache_n_acquires_oom);
56312 _leave(" [ENOMEM]");
56313 return NULL;
56314 }
56315@@ -114,13 +114,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
56316
56317 switch (cookie->def->type) {
56318 case FSCACHE_COOKIE_TYPE_INDEX:
56319- fscache_stat(&fscache_n_cookie_index);
56320+ fscache_stat_unchecked(&fscache_n_cookie_index);
56321 break;
56322 case FSCACHE_COOKIE_TYPE_DATAFILE:
56323- fscache_stat(&fscache_n_cookie_data);
56324+ fscache_stat_unchecked(&fscache_n_cookie_data);
56325 break;
56326 default:
56327- fscache_stat(&fscache_n_cookie_special);
56328+ fscache_stat_unchecked(&fscache_n_cookie_special);
56329 break;
56330 }
56331
56332@@ -131,13 +131,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
56333 if (fscache_acquire_non_index_cookie(cookie) < 0) {
56334 atomic_dec(&parent->n_children);
56335 __fscache_cookie_put(cookie);
56336- fscache_stat(&fscache_n_acquires_nobufs);
56337+ fscache_stat_unchecked(&fscache_n_acquires_nobufs);
56338 _leave(" = NULL");
56339 return NULL;
56340 }
56341 }
56342
56343- fscache_stat(&fscache_n_acquires_ok);
56344+ fscache_stat_unchecked(&fscache_n_acquires_ok);
56345 _leave(" = %p", cookie);
56346 return cookie;
56347 }
56348@@ -173,7 +173,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
56349 cache = fscache_select_cache_for_object(cookie->parent);
56350 if (!cache) {
56351 up_read(&fscache_addremove_sem);
56352- fscache_stat(&fscache_n_acquires_no_cache);
56353+ fscache_stat_unchecked(&fscache_n_acquires_no_cache);
56354 _leave(" = -ENOMEDIUM [no cache]");
56355 return -ENOMEDIUM;
56356 }
56357@@ -259,14 +259,14 @@ static int fscache_alloc_object(struct fscache_cache *cache,
56358 object = cache->ops->alloc_object(cache, cookie);
56359 fscache_stat_d(&fscache_n_cop_alloc_object);
56360 if (IS_ERR(object)) {
56361- fscache_stat(&fscache_n_object_no_alloc);
56362+ fscache_stat_unchecked(&fscache_n_object_no_alloc);
56363 ret = PTR_ERR(object);
56364 goto error;
56365 }
56366
56367- fscache_stat(&fscache_n_object_alloc);
56368+ fscache_stat_unchecked(&fscache_n_object_alloc);
56369
56370- object->debug_id = atomic_inc_return(&fscache_object_debug_id);
56371+ object->debug_id = atomic_inc_return_unchecked(&fscache_object_debug_id);
56372
56373 _debug("ALLOC OBJ%x: %s {%lx}",
56374 object->debug_id, cookie->def->name, object->events);
56375@@ -380,7 +380,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
56376
56377 _enter("{%s}", cookie->def->name);
56378
56379- fscache_stat(&fscache_n_invalidates);
56380+ fscache_stat_unchecked(&fscache_n_invalidates);
56381
56382 /* Only permit invalidation of data files. Invalidating an index will
56383 * require the caller to release all its attachments to the tree rooted
56384@@ -438,10 +438,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
56385 {
56386 struct fscache_object *object;
56387
56388- fscache_stat(&fscache_n_updates);
56389+ fscache_stat_unchecked(&fscache_n_updates);
56390
56391 if (!cookie) {
56392- fscache_stat(&fscache_n_updates_null);
56393+ fscache_stat_unchecked(&fscache_n_updates_null);
56394 _leave(" [no cookie]");
56395 return;
56396 }
56397@@ -473,12 +473,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
56398 {
56399 struct fscache_object *object;
56400
56401- fscache_stat(&fscache_n_relinquishes);
56402+ fscache_stat_unchecked(&fscache_n_relinquishes);
56403 if (retire)
56404- fscache_stat(&fscache_n_relinquishes_retire);
56405+ fscache_stat_unchecked(&fscache_n_relinquishes_retire);
56406
56407 if (!cookie) {
56408- fscache_stat(&fscache_n_relinquishes_null);
56409+ fscache_stat_unchecked(&fscache_n_relinquishes_null);
56410 _leave(" [no cookie]");
56411 return;
56412 }
56413@@ -598,7 +598,7 @@ int __fscache_check_consistency(struct fscache_cookie *cookie)
56414 if (test_bit(FSCACHE_IOERROR, &object->cache->flags))
56415 goto inconsistent;
56416
56417- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
56418+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
56419
56420 atomic_inc(&cookie->n_active);
56421 if (fscache_submit_op(object, op) < 0)
56422diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
56423index 4226f66..0fb3f45 100644
56424--- a/fs/fscache/internal.h
56425+++ b/fs/fscache/internal.h
56426@@ -133,8 +133,8 @@ extern void fscache_operation_gc(struct work_struct *);
56427 extern int fscache_wait_for_deferred_lookup(struct fscache_cookie *);
56428 extern int fscache_wait_for_operation_activation(struct fscache_object *,
56429 struct fscache_operation *,
56430- atomic_t *,
56431- atomic_t *,
56432+ atomic_unchecked_t *,
56433+ atomic_unchecked_t *,
56434 void (*)(struct fscache_operation *));
56435 extern void fscache_invalidate_writes(struct fscache_cookie *);
56436
56437@@ -153,101 +153,101 @@ extern void fscache_proc_cleanup(void);
56438 * stats.c
56439 */
56440 #ifdef CONFIG_FSCACHE_STATS
56441-extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
56442-extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
56443+extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
56444+extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
56445
56446-extern atomic_t fscache_n_op_pend;
56447-extern atomic_t fscache_n_op_run;
56448-extern atomic_t fscache_n_op_enqueue;
56449-extern atomic_t fscache_n_op_deferred_release;
56450-extern atomic_t fscache_n_op_release;
56451-extern atomic_t fscache_n_op_gc;
56452-extern atomic_t fscache_n_op_cancelled;
56453-extern atomic_t fscache_n_op_rejected;
56454+extern atomic_unchecked_t fscache_n_op_pend;
56455+extern atomic_unchecked_t fscache_n_op_run;
56456+extern atomic_unchecked_t fscache_n_op_enqueue;
56457+extern atomic_unchecked_t fscache_n_op_deferred_release;
56458+extern atomic_unchecked_t fscache_n_op_release;
56459+extern atomic_unchecked_t fscache_n_op_gc;
56460+extern atomic_unchecked_t fscache_n_op_cancelled;
56461+extern atomic_unchecked_t fscache_n_op_rejected;
56462
56463-extern atomic_t fscache_n_attr_changed;
56464-extern atomic_t fscache_n_attr_changed_ok;
56465-extern atomic_t fscache_n_attr_changed_nobufs;
56466-extern atomic_t fscache_n_attr_changed_nomem;
56467-extern atomic_t fscache_n_attr_changed_calls;
56468+extern atomic_unchecked_t fscache_n_attr_changed;
56469+extern atomic_unchecked_t fscache_n_attr_changed_ok;
56470+extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
56471+extern atomic_unchecked_t fscache_n_attr_changed_nomem;
56472+extern atomic_unchecked_t fscache_n_attr_changed_calls;
56473
56474-extern atomic_t fscache_n_allocs;
56475-extern atomic_t fscache_n_allocs_ok;
56476-extern atomic_t fscache_n_allocs_wait;
56477-extern atomic_t fscache_n_allocs_nobufs;
56478-extern atomic_t fscache_n_allocs_intr;
56479-extern atomic_t fscache_n_allocs_object_dead;
56480-extern atomic_t fscache_n_alloc_ops;
56481-extern atomic_t fscache_n_alloc_op_waits;
56482+extern atomic_unchecked_t fscache_n_allocs;
56483+extern atomic_unchecked_t fscache_n_allocs_ok;
56484+extern atomic_unchecked_t fscache_n_allocs_wait;
56485+extern atomic_unchecked_t fscache_n_allocs_nobufs;
56486+extern atomic_unchecked_t fscache_n_allocs_intr;
56487+extern atomic_unchecked_t fscache_n_allocs_object_dead;
56488+extern atomic_unchecked_t fscache_n_alloc_ops;
56489+extern atomic_unchecked_t fscache_n_alloc_op_waits;
56490
56491-extern atomic_t fscache_n_retrievals;
56492-extern atomic_t fscache_n_retrievals_ok;
56493-extern atomic_t fscache_n_retrievals_wait;
56494-extern atomic_t fscache_n_retrievals_nodata;
56495-extern atomic_t fscache_n_retrievals_nobufs;
56496-extern atomic_t fscache_n_retrievals_intr;
56497-extern atomic_t fscache_n_retrievals_nomem;
56498-extern atomic_t fscache_n_retrievals_object_dead;
56499-extern atomic_t fscache_n_retrieval_ops;
56500-extern atomic_t fscache_n_retrieval_op_waits;
56501+extern atomic_unchecked_t fscache_n_retrievals;
56502+extern atomic_unchecked_t fscache_n_retrievals_ok;
56503+extern atomic_unchecked_t fscache_n_retrievals_wait;
56504+extern atomic_unchecked_t fscache_n_retrievals_nodata;
56505+extern atomic_unchecked_t fscache_n_retrievals_nobufs;
56506+extern atomic_unchecked_t fscache_n_retrievals_intr;
56507+extern atomic_unchecked_t fscache_n_retrievals_nomem;
56508+extern atomic_unchecked_t fscache_n_retrievals_object_dead;
56509+extern atomic_unchecked_t fscache_n_retrieval_ops;
56510+extern atomic_unchecked_t fscache_n_retrieval_op_waits;
56511
56512-extern atomic_t fscache_n_stores;
56513-extern atomic_t fscache_n_stores_ok;
56514-extern atomic_t fscache_n_stores_again;
56515-extern atomic_t fscache_n_stores_nobufs;
56516-extern atomic_t fscache_n_stores_oom;
56517-extern atomic_t fscache_n_store_ops;
56518-extern atomic_t fscache_n_store_calls;
56519-extern atomic_t fscache_n_store_pages;
56520-extern atomic_t fscache_n_store_radix_deletes;
56521-extern atomic_t fscache_n_store_pages_over_limit;
56522+extern atomic_unchecked_t fscache_n_stores;
56523+extern atomic_unchecked_t fscache_n_stores_ok;
56524+extern atomic_unchecked_t fscache_n_stores_again;
56525+extern atomic_unchecked_t fscache_n_stores_nobufs;
56526+extern atomic_unchecked_t fscache_n_stores_oom;
56527+extern atomic_unchecked_t fscache_n_store_ops;
56528+extern atomic_unchecked_t fscache_n_store_calls;
56529+extern atomic_unchecked_t fscache_n_store_pages;
56530+extern atomic_unchecked_t fscache_n_store_radix_deletes;
56531+extern atomic_unchecked_t fscache_n_store_pages_over_limit;
56532
56533-extern atomic_t fscache_n_store_vmscan_not_storing;
56534-extern atomic_t fscache_n_store_vmscan_gone;
56535-extern atomic_t fscache_n_store_vmscan_busy;
56536-extern atomic_t fscache_n_store_vmscan_cancelled;
56537-extern atomic_t fscache_n_store_vmscan_wait;
56538+extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
56539+extern atomic_unchecked_t fscache_n_store_vmscan_gone;
56540+extern atomic_unchecked_t fscache_n_store_vmscan_busy;
56541+extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
56542+extern atomic_unchecked_t fscache_n_store_vmscan_wait;
56543
56544-extern atomic_t fscache_n_marks;
56545-extern atomic_t fscache_n_uncaches;
56546+extern atomic_unchecked_t fscache_n_marks;
56547+extern atomic_unchecked_t fscache_n_uncaches;
56548
56549-extern atomic_t fscache_n_acquires;
56550-extern atomic_t fscache_n_acquires_null;
56551-extern atomic_t fscache_n_acquires_no_cache;
56552-extern atomic_t fscache_n_acquires_ok;
56553-extern atomic_t fscache_n_acquires_nobufs;
56554-extern atomic_t fscache_n_acquires_oom;
56555+extern atomic_unchecked_t fscache_n_acquires;
56556+extern atomic_unchecked_t fscache_n_acquires_null;
56557+extern atomic_unchecked_t fscache_n_acquires_no_cache;
56558+extern atomic_unchecked_t fscache_n_acquires_ok;
56559+extern atomic_unchecked_t fscache_n_acquires_nobufs;
56560+extern atomic_unchecked_t fscache_n_acquires_oom;
56561
56562-extern atomic_t fscache_n_invalidates;
56563-extern atomic_t fscache_n_invalidates_run;
56564+extern atomic_unchecked_t fscache_n_invalidates;
56565+extern atomic_unchecked_t fscache_n_invalidates_run;
56566
56567-extern atomic_t fscache_n_updates;
56568-extern atomic_t fscache_n_updates_null;
56569-extern atomic_t fscache_n_updates_run;
56570+extern atomic_unchecked_t fscache_n_updates;
56571+extern atomic_unchecked_t fscache_n_updates_null;
56572+extern atomic_unchecked_t fscache_n_updates_run;
56573
56574-extern atomic_t fscache_n_relinquishes;
56575-extern atomic_t fscache_n_relinquishes_null;
56576-extern atomic_t fscache_n_relinquishes_waitcrt;
56577-extern atomic_t fscache_n_relinquishes_retire;
56578+extern atomic_unchecked_t fscache_n_relinquishes;
56579+extern atomic_unchecked_t fscache_n_relinquishes_null;
56580+extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
56581+extern atomic_unchecked_t fscache_n_relinquishes_retire;
56582
56583-extern atomic_t fscache_n_cookie_index;
56584-extern atomic_t fscache_n_cookie_data;
56585-extern atomic_t fscache_n_cookie_special;
56586+extern atomic_unchecked_t fscache_n_cookie_index;
56587+extern atomic_unchecked_t fscache_n_cookie_data;
56588+extern atomic_unchecked_t fscache_n_cookie_special;
56589
56590-extern atomic_t fscache_n_object_alloc;
56591-extern atomic_t fscache_n_object_no_alloc;
56592-extern atomic_t fscache_n_object_lookups;
56593-extern atomic_t fscache_n_object_lookups_negative;
56594-extern atomic_t fscache_n_object_lookups_positive;
56595-extern atomic_t fscache_n_object_lookups_timed_out;
56596-extern atomic_t fscache_n_object_created;
56597-extern atomic_t fscache_n_object_avail;
56598-extern atomic_t fscache_n_object_dead;
56599+extern atomic_unchecked_t fscache_n_object_alloc;
56600+extern atomic_unchecked_t fscache_n_object_no_alloc;
56601+extern atomic_unchecked_t fscache_n_object_lookups;
56602+extern atomic_unchecked_t fscache_n_object_lookups_negative;
56603+extern atomic_unchecked_t fscache_n_object_lookups_positive;
56604+extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
56605+extern atomic_unchecked_t fscache_n_object_created;
56606+extern atomic_unchecked_t fscache_n_object_avail;
56607+extern atomic_unchecked_t fscache_n_object_dead;
56608
56609-extern atomic_t fscache_n_checkaux_none;
56610-extern atomic_t fscache_n_checkaux_okay;
56611-extern atomic_t fscache_n_checkaux_update;
56612-extern atomic_t fscache_n_checkaux_obsolete;
56613+extern atomic_unchecked_t fscache_n_checkaux_none;
56614+extern atomic_unchecked_t fscache_n_checkaux_okay;
56615+extern atomic_unchecked_t fscache_n_checkaux_update;
56616+extern atomic_unchecked_t fscache_n_checkaux_obsolete;
56617
56618 extern atomic_t fscache_n_cop_alloc_object;
56619 extern atomic_t fscache_n_cop_lookup_object;
56620@@ -272,6 +272,11 @@ static inline void fscache_stat(atomic_t *stat)
56621 atomic_inc(stat);
56622 }
56623
56624+static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
56625+{
56626+ atomic_inc_unchecked(stat);
56627+}
56628+
56629 static inline void fscache_stat_d(atomic_t *stat)
56630 {
56631 atomic_dec(stat);
56632@@ -284,6 +289,7 @@ extern const struct file_operations fscache_stats_fops;
56633
56634 #define __fscache_stat(stat) (NULL)
56635 #define fscache_stat(stat) do {} while (0)
56636+#define fscache_stat_unchecked(stat) do {} while (0)
56637 #define fscache_stat_d(stat) do {} while (0)
56638 #endif
56639
56640diff --git a/fs/fscache/object.c b/fs/fscache/object.c
56641index 86d75a6..5f3d7a0 100644
56642--- a/fs/fscache/object.c
56643+++ b/fs/fscache/object.c
56644@@ -451,7 +451,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
56645 _debug("LOOKUP \"%s\" in \"%s\"",
56646 cookie->def->name, object->cache->tag->name);
56647
56648- fscache_stat(&fscache_n_object_lookups);
56649+ fscache_stat_unchecked(&fscache_n_object_lookups);
56650 fscache_stat(&fscache_n_cop_lookup_object);
56651 ret = object->cache->ops->lookup_object(object);
56652 fscache_stat_d(&fscache_n_cop_lookup_object);
56653@@ -461,7 +461,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
56654 if (ret == -ETIMEDOUT) {
56655 /* probably stuck behind another object, so move this one to
56656 * the back of the queue */
56657- fscache_stat(&fscache_n_object_lookups_timed_out);
56658+ fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
56659 _leave(" [timeout]");
56660 return NO_TRANSIT;
56661 }
56662@@ -489,7 +489,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
56663 _enter("{OBJ%x,%s}", object->debug_id, object->state->name);
56664
56665 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
56666- fscache_stat(&fscache_n_object_lookups_negative);
56667+ fscache_stat_unchecked(&fscache_n_object_lookups_negative);
56668
56669 /* Allow write requests to begin stacking up and read requests to begin
56670 * returning ENODATA.
56671@@ -523,7 +523,7 @@ void fscache_obtained_object(struct fscache_object *object)
56672 /* if we were still looking up, then we must have a positive lookup
56673 * result, in which case there may be data available */
56674 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
56675- fscache_stat(&fscache_n_object_lookups_positive);
56676+ fscache_stat_unchecked(&fscache_n_object_lookups_positive);
56677
56678 /* We do (presumably) have data */
56679 clear_bit_unlock(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
56680@@ -534,7 +534,7 @@ void fscache_obtained_object(struct fscache_object *object)
56681 clear_bit_unlock(FSCACHE_COOKIE_LOOKING_UP, &cookie->flags);
56682 wake_up_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP);
56683 } else {
56684- fscache_stat(&fscache_n_object_created);
56685+ fscache_stat_unchecked(&fscache_n_object_created);
56686 }
56687
56688 set_bit(FSCACHE_OBJECT_IS_AVAILABLE, &object->flags);
56689@@ -570,7 +570,7 @@ static const struct fscache_state *fscache_object_available(struct fscache_objec
56690 fscache_stat_d(&fscache_n_cop_lookup_complete);
56691
56692 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
56693- fscache_stat(&fscache_n_object_avail);
56694+ fscache_stat_unchecked(&fscache_n_object_avail);
56695
56696 _leave("");
56697 return transit_to(JUMPSTART_DEPS);
56698@@ -716,7 +716,7 @@ static const struct fscache_state *fscache_drop_object(struct fscache_object *ob
56699
56700 /* this just shifts the object release to the work processor */
56701 fscache_put_object(object);
56702- fscache_stat(&fscache_n_object_dead);
56703+ fscache_stat_unchecked(&fscache_n_object_dead);
56704
56705 _leave("");
56706 return transit_to(OBJECT_DEAD);
56707@@ -881,7 +881,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
56708 enum fscache_checkaux result;
56709
56710 if (!object->cookie->def->check_aux) {
56711- fscache_stat(&fscache_n_checkaux_none);
56712+ fscache_stat_unchecked(&fscache_n_checkaux_none);
56713 return FSCACHE_CHECKAUX_OKAY;
56714 }
56715
56716@@ -890,17 +890,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
56717 switch (result) {
56718 /* entry okay as is */
56719 case FSCACHE_CHECKAUX_OKAY:
56720- fscache_stat(&fscache_n_checkaux_okay);
56721+ fscache_stat_unchecked(&fscache_n_checkaux_okay);
56722 break;
56723
56724 /* entry requires update */
56725 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
56726- fscache_stat(&fscache_n_checkaux_update);
56727+ fscache_stat_unchecked(&fscache_n_checkaux_update);
56728 break;
56729
56730 /* entry requires deletion */
56731 case FSCACHE_CHECKAUX_OBSOLETE:
56732- fscache_stat(&fscache_n_checkaux_obsolete);
56733+ fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
56734 break;
56735
56736 default:
56737@@ -986,7 +986,7 @@ static const struct fscache_state *fscache_invalidate_object(struct fscache_obje
56738 {
56739 const struct fscache_state *s;
56740
56741- fscache_stat(&fscache_n_invalidates_run);
56742+ fscache_stat_unchecked(&fscache_n_invalidates_run);
56743 fscache_stat(&fscache_n_cop_invalidate_object);
56744 s = _fscache_invalidate_object(object, event);
56745 fscache_stat_d(&fscache_n_cop_invalidate_object);
56746@@ -1001,7 +1001,7 @@ static const struct fscache_state *fscache_update_object(struct fscache_object *
56747 {
56748 _enter("{OBJ%x},%d", object->debug_id, event);
56749
56750- fscache_stat(&fscache_n_updates_run);
56751+ fscache_stat_unchecked(&fscache_n_updates_run);
56752 fscache_stat(&fscache_n_cop_update_object);
56753 object->cache->ops->update_object(object);
56754 fscache_stat_d(&fscache_n_cop_update_object);
56755diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
56756index 318071a..379938b 100644
56757--- a/fs/fscache/operation.c
56758+++ b/fs/fscache/operation.c
56759@@ -17,7 +17,7 @@
56760 #include <linux/slab.h>
56761 #include "internal.h"
56762
56763-atomic_t fscache_op_debug_id;
56764+atomic_unchecked_t fscache_op_debug_id;
56765 EXPORT_SYMBOL(fscache_op_debug_id);
56766
56767 /**
56768@@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
56769 ASSERTCMP(atomic_read(&op->usage), >, 0);
56770 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
56771
56772- fscache_stat(&fscache_n_op_enqueue);
56773+ fscache_stat_unchecked(&fscache_n_op_enqueue);
56774 switch (op->flags & FSCACHE_OP_TYPE) {
56775 case FSCACHE_OP_ASYNC:
56776 _debug("queue async");
56777@@ -73,7 +73,7 @@ static void fscache_run_op(struct fscache_object *object,
56778 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
56779 if (op->processor)
56780 fscache_enqueue_operation(op);
56781- fscache_stat(&fscache_n_op_run);
56782+ fscache_stat_unchecked(&fscache_n_op_run);
56783 }
56784
56785 /*
56786@@ -105,11 +105,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
56787 if (object->n_in_progress > 0) {
56788 atomic_inc(&op->usage);
56789 list_add_tail(&op->pend_link, &object->pending_ops);
56790- fscache_stat(&fscache_n_op_pend);
56791+ fscache_stat_unchecked(&fscache_n_op_pend);
56792 } else if (!list_empty(&object->pending_ops)) {
56793 atomic_inc(&op->usage);
56794 list_add_tail(&op->pend_link, &object->pending_ops);
56795- fscache_stat(&fscache_n_op_pend);
56796+ fscache_stat_unchecked(&fscache_n_op_pend);
56797 fscache_start_operations(object);
56798 } else {
56799 ASSERTCMP(object->n_in_progress, ==, 0);
56800@@ -125,7 +125,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
56801 object->n_exclusive++; /* reads and writes must wait */
56802 atomic_inc(&op->usage);
56803 list_add_tail(&op->pend_link, &object->pending_ops);
56804- fscache_stat(&fscache_n_op_pend);
56805+ fscache_stat_unchecked(&fscache_n_op_pend);
56806 ret = 0;
56807 } else {
56808 /* If we're in any other state, there must have been an I/O
56809@@ -212,11 +212,11 @@ int fscache_submit_op(struct fscache_object *object,
56810 if (object->n_exclusive > 0) {
56811 atomic_inc(&op->usage);
56812 list_add_tail(&op->pend_link, &object->pending_ops);
56813- fscache_stat(&fscache_n_op_pend);
56814+ fscache_stat_unchecked(&fscache_n_op_pend);
56815 } else if (!list_empty(&object->pending_ops)) {
56816 atomic_inc(&op->usage);
56817 list_add_tail(&op->pend_link, &object->pending_ops);
56818- fscache_stat(&fscache_n_op_pend);
56819+ fscache_stat_unchecked(&fscache_n_op_pend);
56820 fscache_start_operations(object);
56821 } else {
56822 ASSERTCMP(object->n_exclusive, ==, 0);
56823@@ -228,10 +228,10 @@ int fscache_submit_op(struct fscache_object *object,
56824 object->n_ops++;
56825 atomic_inc(&op->usage);
56826 list_add_tail(&op->pend_link, &object->pending_ops);
56827- fscache_stat(&fscache_n_op_pend);
56828+ fscache_stat_unchecked(&fscache_n_op_pend);
56829 ret = 0;
56830 } else if (fscache_object_is_dying(object)) {
56831- fscache_stat(&fscache_n_op_rejected);
56832+ fscache_stat_unchecked(&fscache_n_op_rejected);
56833 op->state = FSCACHE_OP_ST_CANCELLED;
56834 ret = -ENOBUFS;
56835 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
56836@@ -310,7 +310,7 @@ int fscache_cancel_op(struct fscache_operation *op,
56837 ret = -EBUSY;
56838 if (op->state == FSCACHE_OP_ST_PENDING) {
56839 ASSERT(!list_empty(&op->pend_link));
56840- fscache_stat(&fscache_n_op_cancelled);
56841+ fscache_stat_unchecked(&fscache_n_op_cancelled);
56842 list_del_init(&op->pend_link);
56843 if (do_cancel)
56844 do_cancel(op);
56845@@ -342,7 +342,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
56846 while (!list_empty(&object->pending_ops)) {
56847 op = list_entry(object->pending_ops.next,
56848 struct fscache_operation, pend_link);
56849- fscache_stat(&fscache_n_op_cancelled);
56850+ fscache_stat_unchecked(&fscache_n_op_cancelled);
56851 list_del_init(&op->pend_link);
56852
56853 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
56854@@ -414,7 +414,7 @@ void fscache_put_operation(struct fscache_operation *op)
56855 op->state, ==, FSCACHE_OP_ST_CANCELLED);
56856 op->state = FSCACHE_OP_ST_DEAD;
56857
56858- fscache_stat(&fscache_n_op_release);
56859+ fscache_stat_unchecked(&fscache_n_op_release);
56860
56861 if (op->release) {
56862 op->release(op);
56863@@ -433,7 +433,7 @@ void fscache_put_operation(struct fscache_operation *op)
56864 * lock, and defer it otherwise */
56865 if (!spin_trylock(&object->lock)) {
56866 _debug("defer put");
56867- fscache_stat(&fscache_n_op_deferred_release);
56868+ fscache_stat_unchecked(&fscache_n_op_deferred_release);
56869
56870 cache = object->cache;
56871 spin_lock(&cache->op_gc_list_lock);
56872@@ -486,7 +486,7 @@ void fscache_operation_gc(struct work_struct *work)
56873
56874 _debug("GC DEFERRED REL OBJ%x OP%x",
56875 object->debug_id, op->debug_id);
56876- fscache_stat(&fscache_n_op_gc);
56877+ fscache_stat_unchecked(&fscache_n_op_gc);
56878
56879 ASSERTCMP(atomic_read(&op->usage), ==, 0);
56880 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
56881diff --git a/fs/fscache/page.c b/fs/fscache/page.c
56882index 73899c1..ae40c58 100644
56883--- a/fs/fscache/page.c
56884+++ b/fs/fscache/page.c
56885@@ -61,7 +61,7 @@ try_again:
56886 val = radix_tree_lookup(&cookie->stores, page->index);
56887 if (!val) {
56888 rcu_read_unlock();
56889- fscache_stat(&fscache_n_store_vmscan_not_storing);
56890+ fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
56891 __fscache_uncache_page(cookie, page);
56892 return true;
56893 }
56894@@ -91,11 +91,11 @@ try_again:
56895 spin_unlock(&cookie->stores_lock);
56896
56897 if (xpage) {
56898- fscache_stat(&fscache_n_store_vmscan_cancelled);
56899- fscache_stat(&fscache_n_store_radix_deletes);
56900+ fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
56901+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
56902 ASSERTCMP(xpage, ==, page);
56903 } else {
56904- fscache_stat(&fscache_n_store_vmscan_gone);
56905+ fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
56906 }
56907
56908 wake_up_bit(&cookie->flags, 0);
56909@@ -110,11 +110,11 @@ page_busy:
56910 * sleeping on memory allocation, so we may need to impose a timeout
56911 * too. */
56912 if (!(gfp & __GFP_WAIT) || !(gfp & __GFP_FS)) {
56913- fscache_stat(&fscache_n_store_vmscan_busy);
56914+ fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
56915 return false;
56916 }
56917
56918- fscache_stat(&fscache_n_store_vmscan_wait);
56919+ fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
56920 __fscache_wait_on_page_write(cookie, page);
56921 gfp &= ~__GFP_WAIT;
56922 goto try_again;
56923@@ -140,7 +140,7 @@ static void fscache_end_page_write(struct fscache_object *object,
56924 FSCACHE_COOKIE_STORING_TAG);
56925 if (!radix_tree_tag_get(&cookie->stores, page->index,
56926 FSCACHE_COOKIE_PENDING_TAG)) {
56927- fscache_stat(&fscache_n_store_radix_deletes);
56928+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
56929 xpage = radix_tree_delete(&cookie->stores, page->index);
56930 }
56931 spin_unlock(&cookie->stores_lock);
56932@@ -161,7 +161,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
56933
56934 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
56935
56936- fscache_stat(&fscache_n_attr_changed_calls);
56937+ fscache_stat_unchecked(&fscache_n_attr_changed_calls);
56938
56939 if (fscache_object_is_active(object) &&
56940 fscache_use_cookie(object)) {
56941@@ -189,11 +189,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
56942
56943 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
56944
56945- fscache_stat(&fscache_n_attr_changed);
56946+ fscache_stat_unchecked(&fscache_n_attr_changed);
56947
56948 op = kzalloc(sizeof(*op), GFP_KERNEL);
56949 if (!op) {
56950- fscache_stat(&fscache_n_attr_changed_nomem);
56951+ fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
56952 _leave(" = -ENOMEM");
56953 return -ENOMEM;
56954 }
56955@@ -211,7 +211,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
56956 if (fscache_submit_exclusive_op(object, op) < 0)
56957 goto nobufs;
56958 spin_unlock(&cookie->lock);
56959- fscache_stat(&fscache_n_attr_changed_ok);
56960+ fscache_stat_unchecked(&fscache_n_attr_changed_ok);
56961 fscache_put_operation(op);
56962 _leave(" = 0");
56963 return 0;
56964@@ -219,7 +219,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
56965 nobufs:
56966 spin_unlock(&cookie->lock);
56967 kfree(op);
56968- fscache_stat(&fscache_n_attr_changed_nobufs);
56969+ fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
56970 _leave(" = %d", -ENOBUFS);
56971 return -ENOBUFS;
56972 }
56973@@ -258,7 +258,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
56974 /* allocate a retrieval operation and attempt to submit it */
56975 op = kzalloc(sizeof(*op), GFP_NOIO);
56976 if (!op) {
56977- fscache_stat(&fscache_n_retrievals_nomem);
56978+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
56979 return NULL;
56980 }
56981
56982@@ -289,13 +289,13 @@ int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
56983 return 0;
56984 }
56985
56986- fscache_stat(&fscache_n_retrievals_wait);
56987+ fscache_stat_unchecked(&fscache_n_retrievals_wait);
56988
56989 jif = jiffies;
56990 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
56991 fscache_wait_bit_interruptible,
56992 TASK_INTERRUPTIBLE) != 0) {
56993- fscache_stat(&fscache_n_retrievals_intr);
56994+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
56995 _leave(" = -ERESTARTSYS");
56996 return -ERESTARTSYS;
56997 }
56998@@ -324,8 +324,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
56999 */
57000 int fscache_wait_for_operation_activation(struct fscache_object *object,
57001 struct fscache_operation *op,
57002- atomic_t *stat_op_waits,
57003- atomic_t *stat_object_dead,
57004+ atomic_unchecked_t *stat_op_waits,
57005+ atomic_unchecked_t *stat_object_dead,
57006 void (*do_cancel)(struct fscache_operation *))
57007 {
57008 int ret;
57009@@ -335,7 +335,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
57010
57011 _debug(">>> WT");
57012 if (stat_op_waits)
57013- fscache_stat(stat_op_waits);
57014+ fscache_stat_unchecked(stat_op_waits);
57015 if (wait_on_bit(&op->flags, FSCACHE_OP_WAITING,
57016 fscache_wait_bit_interruptible,
57017 TASK_INTERRUPTIBLE) != 0) {
57018@@ -353,7 +353,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
57019 check_if_dead:
57020 if (op->state == FSCACHE_OP_ST_CANCELLED) {
57021 if (stat_object_dead)
57022- fscache_stat(stat_object_dead);
57023+ fscache_stat_unchecked(stat_object_dead);
57024 _leave(" = -ENOBUFS [cancelled]");
57025 return -ENOBUFS;
57026 }
57027@@ -361,7 +361,7 @@ check_if_dead:
57028 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->state);
57029 fscache_cancel_op(op, do_cancel);
57030 if (stat_object_dead)
57031- fscache_stat(stat_object_dead);
57032+ fscache_stat_unchecked(stat_object_dead);
57033 return -ENOBUFS;
57034 }
57035 return 0;
57036@@ -388,7 +388,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
57037
57038 _enter("%p,%p,,,", cookie, page);
57039
57040- fscache_stat(&fscache_n_retrievals);
57041+ fscache_stat_unchecked(&fscache_n_retrievals);
57042
57043 if (hlist_empty(&cookie->backing_objects))
57044 goto nobufs;
57045@@ -428,7 +428,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
57046 goto nobufs_unlock_dec;
57047 spin_unlock(&cookie->lock);
57048
57049- fscache_stat(&fscache_n_retrieval_ops);
57050+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
57051
57052 /* pin the netfs read context in case we need to do the actual netfs
57053 * read because we've encountered a cache read failure */
57054@@ -459,15 +459,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
57055
57056 error:
57057 if (ret == -ENOMEM)
57058- fscache_stat(&fscache_n_retrievals_nomem);
57059+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
57060 else if (ret == -ERESTARTSYS)
57061- fscache_stat(&fscache_n_retrievals_intr);
57062+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
57063 else if (ret == -ENODATA)
57064- fscache_stat(&fscache_n_retrievals_nodata);
57065+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
57066 else if (ret < 0)
57067- fscache_stat(&fscache_n_retrievals_nobufs);
57068+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
57069 else
57070- fscache_stat(&fscache_n_retrievals_ok);
57071+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
57072
57073 fscache_put_retrieval(op);
57074 _leave(" = %d", ret);
57075@@ -480,7 +480,7 @@ nobufs_unlock:
57076 atomic_dec(&cookie->n_active);
57077 kfree(op);
57078 nobufs:
57079- fscache_stat(&fscache_n_retrievals_nobufs);
57080+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
57081 _leave(" = -ENOBUFS");
57082 return -ENOBUFS;
57083 }
57084@@ -518,7 +518,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
57085
57086 _enter("%p,,%d,,,", cookie, *nr_pages);
57087
57088- fscache_stat(&fscache_n_retrievals);
57089+ fscache_stat_unchecked(&fscache_n_retrievals);
57090
57091 if (hlist_empty(&cookie->backing_objects))
57092 goto nobufs;
57093@@ -554,7 +554,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
57094 goto nobufs_unlock_dec;
57095 spin_unlock(&cookie->lock);
57096
57097- fscache_stat(&fscache_n_retrieval_ops);
57098+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
57099
57100 /* pin the netfs read context in case we need to do the actual netfs
57101 * read because we've encountered a cache read failure */
57102@@ -585,15 +585,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
57103
57104 error:
57105 if (ret == -ENOMEM)
57106- fscache_stat(&fscache_n_retrievals_nomem);
57107+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
57108 else if (ret == -ERESTARTSYS)
57109- fscache_stat(&fscache_n_retrievals_intr);
57110+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
57111 else if (ret == -ENODATA)
57112- fscache_stat(&fscache_n_retrievals_nodata);
57113+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
57114 else if (ret < 0)
57115- fscache_stat(&fscache_n_retrievals_nobufs);
57116+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
57117 else
57118- fscache_stat(&fscache_n_retrievals_ok);
57119+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
57120
57121 fscache_put_retrieval(op);
57122 _leave(" = %d", ret);
57123@@ -606,7 +606,7 @@ nobufs_unlock:
57124 atomic_dec(&cookie->n_active);
57125 kfree(op);
57126 nobufs:
57127- fscache_stat(&fscache_n_retrievals_nobufs);
57128+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
57129 _leave(" = -ENOBUFS");
57130 return -ENOBUFS;
57131 }
57132@@ -630,7 +630,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
57133
57134 _enter("%p,%p,,,", cookie, page);
57135
57136- fscache_stat(&fscache_n_allocs);
57137+ fscache_stat_unchecked(&fscache_n_allocs);
57138
57139 if (hlist_empty(&cookie->backing_objects))
57140 goto nobufs;
57141@@ -662,7 +662,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
57142 goto nobufs_unlock;
57143 spin_unlock(&cookie->lock);
57144
57145- fscache_stat(&fscache_n_alloc_ops);
57146+ fscache_stat_unchecked(&fscache_n_alloc_ops);
57147
57148 ret = fscache_wait_for_operation_activation(
57149 object, &op->op,
57150@@ -679,11 +679,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
57151
57152 error:
57153 if (ret == -ERESTARTSYS)
57154- fscache_stat(&fscache_n_allocs_intr);
57155+ fscache_stat_unchecked(&fscache_n_allocs_intr);
57156 else if (ret < 0)
57157- fscache_stat(&fscache_n_allocs_nobufs);
57158+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
57159 else
57160- fscache_stat(&fscache_n_allocs_ok);
57161+ fscache_stat_unchecked(&fscache_n_allocs_ok);
57162
57163 fscache_put_retrieval(op);
57164 _leave(" = %d", ret);
57165@@ -694,7 +694,7 @@ nobufs_unlock:
57166 atomic_dec(&cookie->n_active);
57167 kfree(op);
57168 nobufs:
57169- fscache_stat(&fscache_n_allocs_nobufs);
57170+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
57171 _leave(" = -ENOBUFS");
57172 return -ENOBUFS;
57173 }
57174@@ -770,7 +770,7 @@ static void fscache_write_op(struct fscache_operation *_op)
57175
57176 spin_lock(&cookie->stores_lock);
57177
57178- fscache_stat(&fscache_n_store_calls);
57179+ fscache_stat_unchecked(&fscache_n_store_calls);
57180
57181 /* find a page to store */
57182 page = NULL;
57183@@ -781,7 +781,7 @@ static void fscache_write_op(struct fscache_operation *_op)
57184 page = results[0];
57185 _debug("gang %d [%lx]", n, page->index);
57186 if (page->index > op->store_limit) {
57187- fscache_stat(&fscache_n_store_pages_over_limit);
57188+ fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
57189 goto superseded;
57190 }
57191
57192@@ -793,7 +793,7 @@ static void fscache_write_op(struct fscache_operation *_op)
57193 spin_unlock(&cookie->stores_lock);
57194 spin_unlock(&object->lock);
57195
57196- fscache_stat(&fscache_n_store_pages);
57197+ fscache_stat_unchecked(&fscache_n_store_pages);
57198 fscache_stat(&fscache_n_cop_write_page);
57199 ret = object->cache->ops->write_page(op, page);
57200 fscache_stat_d(&fscache_n_cop_write_page);
57201@@ -896,7 +896,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
57202 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
57203 ASSERT(PageFsCache(page));
57204
57205- fscache_stat(&fscache_n_stores);
57206+ fscache_stat_unchecked(&fscache_n_stores);
57207
57208 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
57209 _leave(" = -ENOBUFS [invalidating]");
57210@@ -954,7 +954,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
57211 spin_unlock(&cookie->stores_lock);
57212 spin_unlock(&object->lock);
57213
57214- op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
57215+ op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
57216 op->store_limit = object->store_limit;
57217
57218 atomic_inc(&cookie->n_active);
57219@@ -963,8 +963,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
57220
57221 spin_unlock(&cookie->lock);
57222 radix_tree_preload_end();
57223- fscache_stat(&fscache_n_store_ops);
57224- fscache_stat(&fscache_n_stores_ok);
57225+ fscache_stat_unchecked(&fscache_n_store_ops);
57226+ fscache_stat_unchecked(&fscache_n_stores_ok);
57227
57228 /* the work queue now carries its own ref on the object */
57229 fscache_put_operation(&op->op);
57230@@ -972,14 +972,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
57231 return 0;
57232
57233 already_queued:
57234- fscache_stat(&fscache_n_stores_again);
57235+ fscache_stat_unchecked(&fscache_n_stores_again);
57236 already_pending:
57237 spin_unlock(&cookie->stores_lock);
57238 spin_unlock(&object->lock);
57239 spin_unlock(&cookie->lock);
57240 radix_tree_preload_end();
57241 kfree(op);
57242- fscache_stat(&fscache_n_stores_ok);
57243+ fscache_stat_unchecked(&fscache_n_stores_ok);
57244 _leave(" = 0");
57245 return 0;
57246
57247@@ -999,14 +999,14 @@ nobufs:
57248 spin_unlock(&cookie->lock);
57249 radix_tree_preload_end();
57250 kfree(op);
57251- fscache_stat(&fscache_n_stores_nobufs);
57252+ fscache_stat_unchecked(&fscache_n_stores_nobufs);
57253 _leave(" = -ENOBUFS");
57254 return -ENOBUFS;
57255
57256 nomem_free:
57257 kfree(op);
57258 nomem:
57259- fscache_stat(&fscache_n_stores_oom);
57260+ fscache_stat_unchecked(&fscache_n_stores_oom);
57261 _leave(" = -ENOMEM");
57262 return -ENOMEM;
57263 }
57264@@ -1024,7 +1024,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
57265 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
57266 ASSERTCMP(page, !=, NULL);
57267
57268- fscache_stat(&fscache_n_uncaches);
57269+ fscache_stat_unchecked(&fscache_n_uncaches);
57270
57271 /* cache withdrawal may beat us to it */
57272 if (!PageFsCache(page))
57273@@ -1075,7 +1075,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
57274 struct fscache_cookie *cookie = op->op.object->cookie;
57275
57276 #ifdef CONFIG_FSCACHE_STATS
57277- atomic_inc(&fscache_n_marks);
57278+ atomic_inc_unchecked(&fscache_n_marks);
57279 #endif
57280
57281 _debug("- mark %p{%lx}", page, page->index);
57282diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
57283index 40d13c7..ddf52b9 100644
57284--- a/fs/fscache/stats.c
57285+++ b/fs/fscache/stats.c
57286@@ -18,99 +18,99 @@
57287 /*
57288 * operation counters
57289 */
57290-atomic_t fscache_n_op_pend;
57291-atomic_t fscache_n_op_run;
57292-atomic_t fscache_n_op_enqueue;
57293-atomic_t fscache_n_op_requeue;
57294-atomic_t fscache_n_op_deferred_release;
57295-atomic_t fscache_n_op_release;
57296-atomic_t fscache_n_op_gc;
57297-atomic_t fscache_n_op_cancelled;
57298-atomic_t fscache_n_op_rejected;
57299+atomic_unchecked_t fscache_n_op_pend;
57300+atomic_unchecked_t fscache_n_op_run;
57301+atomic_unchecked_t fscache_n_op_enqueue;
57302+atomic_unchecked_t fscache_n_op_requeue;
57303+atomic_unchecked_t fscache_n_op_deferred_release;
57304+atomic_unchecked_t fscache_n_op_release;
57305+atomic_unchecked_t fscache_n_op_gc;
57306+atomic_unchecked_t fscache_n_op_cancelled;
57307+atomic_unchecked_t fscache_n_op_rejected;
57308
57309-atomic_t fscache_n_attr_changed;
57310-atomic_t fscache_n_attr_changed_ok;
57311-atomic_t fscache_n_attr_changed_nobufs;
57312-atomic_t fscache_n_attr_changed_nomem;
57313-atomic_t fscache_n_attr_changed_calls;
57314+atomic_unchecked_t fscache_n_attr_changed;
57315+atomic_unchecked_t fscache_n_attr_changed_ok;
57316+atomic_unchecked_t fscache_n_attr_changed_nobufs;
57317+atomic_unchecked_t fscache_n_attr_changed_nomem;
57318+atomic_unchecked_t fscache_n_attr_changed_calls;
57319
57320-atomic_t fscache_n_allocs;
57321-atomic_t fscache_n_allocs_ok;
57322-atomic_t fscache_n_allocs_wait;
57323-atomic_t fscache_n_allocs_nobufs;
57324-atomic_t fscache_n_allocs_intr;
57325-atomic_t fscache_n_allocs_object_dead;
57326-atomic_t fscache_n_alloc_ops;
57327-atomic_t fscache_n_alloc_op_waits;
57328+atomic_unchecked_t fscache_n_allocs;
57329+atomic_unchecked_t fscache_n_allocs_ok;
57330+atomic_unchecked_t fscache_n_allocs_wait;
57331+atomic_unchecked_t fscache_n_allocs_nobufs;
57332+atomic_unchecked_t fscache_n_allocs_intr;
57333+atomic_unchecked_t fscache_n_allocs_object_dead;
57334+atomic_unchecked_t fscache_n_alloc_ops;
57335+atomic_unchecked_t fscache_n_alloc_op_waits;
57336
57337-atomic_t fscache_n_retrievals;
57338-atomic_t fscache_n_retrievals_ok;
57339-atomic_t fscache_n_retrievals_wait;
57340-atomic_t fscache_n_retrievals_nodata;
57341-atomic_t fscache_n_retrievals_nobufs;
57342-atomic_t fscache_n_retrievals_intr;
57343-atomic_t fscache_n_retrievals_nomem;
57344-atomic_t fscache_n_retrievals_object_dead;
57345-atomic_t fscache_n_retrieval_ops;
57346-atomic_t fscache_n_retrieval_op_waits;
57347+atomic_unchecked_t fscache_n_retrievals;
57348+atomic_unchecked_t fscache_n_retrievals_ok;
57349+atomic_unchecked_t fscache_n_retrievals_wait;
57350+atomic_unchecked_t fscache_n_retrievals_nodata;
57351+atomic_unchecked_t fscache_n_retrievals_nobufs;
57352+atomic_unchecked_t fscache_n_retrievals_intr;
57353+atomic_unchecked_t fscache_n_retrievals_nomem;
57354+atomic_unchecked_t fscache_n_retrievals_object_dead;
57355+atomic_unchecked_t fscache_n_retrieval_ops;
57356+atomic_unchecked_t fscache_n_retrieval_op_waits;
57357
57358-atomic_t fscache_n_stores;
57359-atomic_t fscache_n_stores_ok;
57360-atomic_t fscache_n_stores_again;
57361-atomic_t fscache_n_stores_nobufs;
57362-atomic_t fscache_n_stores_oom;
57363-atomic_t fscache_n_store_ops;
57364-atomic_t fscache_n_store_calls;
57365-atomic_t fscache_n_store_pages;
57366-atomic_t fscache_n_store_radix_deletes;
57367-atomic_t fscache_n_store_pages_over_limit;
57368+atomic_unchecked_t fscache_n_stores;
57369+atomic_unchecked_t fscache_n_stores_ok;
57370+atomic_unchecked_t fscache_n_stores_again;
57371+atomic_unchecked_t fscache_n_stores_nobufs;
57372+atomic_unchecked_t fscache_n_stores_oom;
57373+atomic_unchecked_t fscache_n_store_ops;
57374+atomic_unchecked_t fscache_n_store_calls;
57375+atomic_unchecked_t fscache_n_store_pages;
57376+atomic_unchecked_t fscache_n_store_radix_deletes;
57377+atomic_unchecked_t fscache_n_store_pages_over_limit;
57378
57379-atomic_t fscache_n_store_vmscan_not_storing;
57380-atomic_t fscache_n_store_vmscan_gone;
57381-atomic_t fscache_n_store_vmscan_busy;
57382-atomic_t fscache_n_store_vmscan_cancelled;
57383-atomic_t fscache_n_store_vmscan_wait;
57384+atomic_unchecked_t fscache_n_store_vmscan_not_storing;
57385+atomic_unchecked_t fscache_n_store_vmscan_gone;
57386+atomic_unchecked_t fscache_n_store_vmscan_busy;
57387+atomic_unchecked_t fscache_n_store_vmscan_cancelled;
57388+atomic_unchecked_t fscache_n_store_vmscan_wait;
57389
57390-atomic_t fscache_n_marks;
57391-atomic_t fscache_n_uncaches;
57392+atomic_unchecked_t fscache_n_marks;
57393+atomic_unchecked_t fscache_n_uncaches;
57394
57395-atomic_t fscache_n_acquires;
57396-atomic_t fscache_n_acquires_null;
57397-atomic_t fscache_n_acquires_no_cache;
57398-atomic_t fscache_n_acquires_ok;
57399-atomic_t fscache_n_acquires_nobufs;
57400-atomic_t fscache_n_acquires_oom;
57401+atomic_unchecked_t fscache_n_acquires;
57402+atomic_unchecked_t fscache_n_acquires_null;
57403+atomic_unchecked_t fscache_n_acquires_no_cache;
57404+atomic_unchecked_t fscache_n_acquires_ok;
57405+atomic_unchecked_t fscache_n_acquires_nobufs;
57406+atomic_unchecked_t fscache_n_acquires_oom;
57407
57408-atomic_t fscache_n_invalidates;
57409-atomic_t fscache_n_invalidates_run;
57410+atomic_unchecked_t fscache_n_invalidates;
57411+atomic_unchecked_t fscache_n_invalidates_run;
57412
57413-atomic_t fscache_n_updates;
57414-atomic_t fscache_n_updates_null;
57415-atomic_t fscache_n_updates_run;
57416+atomic_unchecked_t fscache_n_updates;
57417+atomic_unchecked_t fscache_n_updates_null;
57418+atomic_unchecked_t fscache_n_updates_run;
57419
57420-atomic_t fscache_n_relinquishes;
57421-atomic_t fscache_n_relinquishes_null;
57422-atomic_t fscache_n_relinquishes_waitcrt;
57423-atomic_t fscache_n_relinquishes_retire;
57424+atomic_unchecked_t fscache_n_relinquishes;
57425+atomic_unchecked_t fscache_n_relinquishes_null;
57426+atomic_unchecked_t fscache_n_relinquishes_waitcrt;
57427+atomic_unchecked_t fscache_n_relinquishes_retire;
57428
57429-atomic_t fscache_n_cookie_index;
57430-atomic_t fscache_n_cookie_data;
57431-atomic_t fscache_n_cookie_special;
57432+atomic_unchecked_t fscache_n_cookie_index;
57433+atomic_unchecked_t fscache_n_cookie_data;
57434+atomic_unchecked_t fscache_n_cookie_special;
57435
57436-atomic_t fscache_n_object_alloc;
57437-atomic_t fscache_n_object_no_alloc;
57438-atomic_t fscache_n_object_lookups;
57439-atomic_t fscache_n_object_lookups_negative;
57440-atomic_t fscache_n_object_lookups_positive;
57441-atomic_t fscache_n_object_lookups_timed_out;
57442-atomic_t fscache_n_object_created;
57443-atomic_t fscache_n_object_avail;
57444-atomic_t fscache_n_object_dead;
57445+atomic_unchecked_t fscache_n_object_alloc;
57446+atomic_unchecked_t fscache_n_object_no_alloc;
57447+atomic_unchecked_t fscache_n_object_lookups;
57448+atomic_unchecked_t fscache_n_object_lookups_negative;
57449+atomic_unchecked_t fscache_n_object_lookups_positive;
57450+atomic_unchecked_t fscache_n_object_lookups_timed_out;
57451+atomic_unchecked_t fscache_n_object_created;
57452+atomic_unchecked_t fscache_n_object_avail;
57453+atomic_unchecked_t fscache_n_object_dead;
57454
57455-atomic_t fscache_n_checkaux_none;
57456-atomic_t fscache_n_checkaux_okay;
57457-atomic_t fscache_n_checkaux_update;
57458-atomic_t fscache_n_checkaux_obsolete;
57459+atomic_unchecked_t fscache_n_checkaux_none;
57460+atomic_unchecked_t fscache_n_checkaux_okay;
57461+atomic_unchecked_t fscache_n_checkaux_update;
57462+atomic_unchecked_t fscache_n_checkaux_obsolete;
57463
57464 atomic_t fscache_n_cop_alloc_object;
57465 atomic_t fscache_n_cop_lookup_object;
57466@@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
57467 seq_puts(m, "FS-Cache statistics\n");
57468
57469 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
57470- atomic_read(&fscache_n_cookie_index),
57471- atomic_read(&fscache_n_cookie_data),
57472- atomic_read(&fscache_n_cookie_special));
57473+ atomic_read_unchecked(&fscache_n_cookie_index),
57474+ atomic_read_unchecked(&fscache_n_cookie_data),
57475+ atomic_read_unchecked(&fscache_n_cookie_special));
57476
57477 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
57478- atomic_read(&fscache_n_object_alloc),
57479- atomic_read(&fscache_n_object_no_alloc),
57480- atomic_read(&fscache_n_object_avail),
57481- atomic_read(&fscache_n_object_dead));
57482+ atomic_read_unchecked(&fscache_n_object_alloc),
57483+ atomic_read_unchecked(&fscache_n_object_no_alloc),
57484+ atomic_read_unchecked(&fscache_n_object_avail),
57485+ atomic_read_unchecked(&fscache_n_object_dead));
57486 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
57487- atomic_read(&fscache_n_checkaux_none),
57488- atomic_read(&fscache_n_checkaux_okay),
57489- atomic_read(&fscache_n_checkaux_update),
57490- atomic_read(&fscache_n_checkaux_obsolete));
57491+ atomic_read_unchecked(&fscache_n_checkaux_none),
57492+ atomic_read_unchecked(&fscache_n_checkaux_okay),
57493+ atomic_read_unchecked(&fscache_n_checkaux_update),
57494+ atomic_read_unchecked(&fscache_n_checkaux_obsolete));
57495
57496 seq_printf(m, "Pages : mrk=%u unc=%u\n",
57497- atomic_read(&fscache_n_marks),
57498- atomic_read(&fscache_n_uncaches));
57499+ atomic_read_unchecked(&fscache_n_marks),
57500+ atomic_read_unchecked(&fscache_n_uncaches));
57501
57502 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
57503 " oom=%u\n",
57504- atomic_read(&fscache_n_acquires),
57505- atomic_read(&fscache_n_acquires_null),
57506- atomic_read(&fscache_n_acquires_no_cache),
57507- atomic_read(&fscache_n_acquires_ok),
57508- atomic_read(&fscache_n_acquires_nobufs),
57509- atomic_read(&fscache_n_acquires_oom));
57510+ atomic_read_unchecked(&fscache_n_acquires),
57511+ atomic_read_unchecked(&fscache_n_acquires_null),
57512+ atomic_read_unchecked(&fscache_n_acquires_no_cache),
57513+ atomic_read_unchecked(&fscache_n_acquires_ok),
57514+ atomic_read_unchecked(&fscache_n_acquires_nobufs),
57515+ atomic_read_unchecked(&fscache_n_acquires_oom));
57516
57517 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
57518- atomic_read(&fscache_n_object_lookups),
57519- atomic_read(&fscache_n_object_lookups_negative),
57520- atomic_read(&fscache_n_object_lookups_positive),
57521- atomic_read(&fscache_n_object_created),
57522- atomic_read(&fscache_n_object_lookups_timed_out));
57523+ atomic_read_unchecked(&fscache_n_object_lookups),
57524+ atomic_read_unchecked(&fscache_n_object_lookups_negative),
57525+ atomic_read_unchecked(&fscache_n_object_lookups_positive),
57526+ atomic_read_unchecked(&fscache_n_object_created),
57527+ atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
57528
57529 seq_printf(m, "Invals : n=%u run=%u\n",
57530- atomic_read(&fscache_n_invalidates),
57531- atomic_read(&fscache_n_invalidates_run));
57532+ atomic_read_unchecked(&fscache_n_invalidates),
57533+ atomic_read_unchecked(&fscache_n_invalidates_run));
57534
57535 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
57536- atomic_read(&fscache_n_updates),
57537- atomic_read(&fscache_n_updates_null),
57538- atomic_read(&fscache_n_updates_run));
57539+ atomic_read_unchecked(&fscache_n_updates),
57540+ atomic_read_unchecked(&fscache_n_updates_null),
57541+ atomic_read_unchecked(&fscache_n_updates_run));
57542
57543 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
57544- atomic_read(&fscache_n_relinquishes),
57545- atomic_read(&fscache_n_relinquishes_null),
57546- atomic_read(&fscache_n_relinquishes_waitcrt),
57547- atomic_read(&fscache_n_relinquishes_retire));
57548+ atomic_read_unchecked(&fscache_n_relinquishes),
57549+ atomic_read_unchecked(&fscache_n_relinquishes_null),
57550+ atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
57551+ atomic_read_unchecked(&fscache_n_relinquishes_retire));
57552
57553 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
57554- atomic_read(&fscache_n_attr_changed),
57555- atomic_read(&fscache_n_attr_changed_ok),
57556- atomic_read(&fscache_n_attr_changed_nobufs),
57557- atomic_read(&fscache_n_attr_changed_nomem),
57558- atomic_read(&fscache_n_attr_changed_calls));
57559+ atomic_read_unchecked(&fscache_n_attr_changed),
57560+ atomic_read_unchecked(&fscache_n_attr_changed_ok),
57561+ atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
57562+ atomic_read_unchecked(&fscache_n_attr_changed_nomem),
57563+ atomic_read_unchecked(&fscache_n_attr_changed_calls));
57564
57565 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
57566- atomic_read(&fscache_n_allocs),
57567- atomic_read(&fscache_n_allocs_ok),
57568- atomic_read(&fscache_n_allocs_wait),
57569- atomic_read(&fscache_n_allocs_nobufs),
57570- atomic_read(&fscache_n_allocs_intr));
57571+ atomic_read_unchecked(&fscache_n_allocs),
57572+ atomic_read_unchecked(&fscache_n_allocs_ok),
57573+ atomic_read_unchecked(&fscache_n_allocs_wait),
57574+ atomic_read_unchecked(&fscache_n_allocs_nobufs),
57575+ atomic_read_unchecked(&fscache_n_allocs_intr));
57576 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
57577- atomic_read(&fscache_n_alloc_ops),
57578- atomic_read(&fscache_n_alloc_op_waits),
57579- atomic_read(&fscache_n_allocs_object_dead));
57580+ atomic_read_unchecked(&fscache_n_alloc_ops),
57581+ atomic_read_unchecked(&fscache_n_alloc_op_waits),
57582+ atomic_read_unchecked(&fscache_n_allocs_object_dead));
57583
57584 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
57585 " int=%u oom=%u\n",
57586- atomic_read(&fscache_n_retrievals),
57587- atomic_read(&fscache_n_retrievals_ok),
57588- atomic_read(&fscache_n_retrievals_wait),
57589- atomic_read(&fscache_n_retrievals_nodata),
57590- atomic_read(&fscache_n_retrievals_nobufs),
57591- atomic_read(&fscache_n_retrievals_intr),
57592- atomic_read(&fscache_n_retrievals_nomem));
57593+ atomic_read_unchecked(&fscache_n_retrievals),
57594+ atomic_read_unchecked(&fscache_n_retrievals_ok),
57595+ atomic_read_unchecked(&fscache_n_retrievals_wait),
57596+ atomic_read_unchecked(&fscache_n_retrievals_nodata),
57597+ atomic_read_unchecked(&fscache_n_retrievals_nobufs),
57598+ atomic_read_unchecked(&fscache_n_retrievals_intr),
57599+ atomic_read_unchecked(&fscache_n_retrievals_nomem));
57600 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
57601- atomic_read(&fscache_n_retrieval_ops),
57602- atomic_read(&fscache_n_retrieval_op_waits),
57603- atomic_read(&fscache_n_retrievals_object_dead));
57604+ atomic_read_unchecked(&fscache_n_retrieval_ops),
57605+ atomic_read_unchecked(&fscache_n_retrieval_op_waits),
57606+ atomic_read_unchecked(&fscache_n_retrievals_object_dead));
57607
57608 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
57609- atomic_read(&fscache_n_stores),
57610- atomic_read(&fscache_n_stores_ok),
57611- atomic_read(&fscache_n_stores_again),
57612- atomic_read(&fscache_n_stores_nobufs),
57613- atomic_read(&fscache_n_stores_oom));
57614+ atomic_read_unchecked(&fscache_n_stores),
57615+ atomic_read_unchecked(&fscache_n_stores_ok),
57616+ atomic_read_unchecked(&fscache_n_stores_again),
57617+ atomic_read_unchecked(&fscache_n_stores_nobufs),
57618+ atomic_read_unchecked(&fscache_n_stores_oom));
57619 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
57620- atomic_read(&fscache_n_store_ops),
57621- atomic_read(&fscache_n_store_calls),
57622- atomic_read(&fscache_n_store_pages),
57623- atomic_read(&fscache_n_store_radix_deletes),
57624- atomic_read(&fscache_n_store_pages_over_limit));
57625+ atomic_read_unchecked(&fscache_n_store_ops),
57626+ atomic_read_unchecked(&fscache_n_store_calls),
57627+ atomic_read_unchecked(&fscache_n_store_pages),
57628+ atomic_read_unchecked(&fscache_n_store_radix_deletes),
57629+ atomic_read_unchecked(&fscache_n_store_pages_over_limit));
57630
57631 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
57632- atomic_read(&fscache_n_store_vmscan_not_storing),
57633- atomic_read(&fscache_n_store_vmscan_gone),
57634- atomic_read(&fscache_n_store_vmscan_busy),
57635- atomic_read(&fscache_n_store_vmscan_cancelled),
57636- atomic_read(&fscache_n_store_vmscan_wait));
57637+ atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
57638+ atomic_read_unchecked(&fscache_n_store_vmscan_gone),
57639+ atomic_read_unchecked(&fscache_n_store_vmscan_busy),
57640+ atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
57641+ atomic_read_unchecked(&fscache_n_store_vmscan_wait));
57642
57643 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
57644- atomic_read(&fscache_n_op_pend),
57645- atomic_read(&fscache_n_op_run),
57646- atomic_read(&fscache_n_op_enqueue),
57647- atomic_read(&fscache_n_op_cancelled),
57648- atomic_read(&fscache_n_op_rejected));
57649+ atomic_read_unchecked(&fscache_n_op_pend),
57650+ atomic_read_unchecked(&fscache_n_op_run),
57651+ atomic_read_unchecked(&fscache_n_op_enqueue),
57652+ atomic_read_unchecked(&fscache_n_op_cancelled),
57653+ atomic_read_unchecked(&fscache_n_op_rejected));
57654 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
57655- atomic_read(&fscache_n_op_deferred_release),
57656- atomic_read(&fscache_n_op_release),
57657- atomic_read(&fscache_n_op_gc));
57658+ atomic_read_unchecked(&fscache_n_op_deferred_release),
57659+ atomic_read_unchecked(&fscache_n_op_release),
57660+ atomic_read_unchecked(&fscache_n_op_gc));
57661
57662 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
57663 atomic_read(&fscache_n_cop_alloc_object),
57664diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
57665index adbfd66..4b25822 100644
57666--- a/fs/fuse/cuse.c
57667+++ b/fs/fuse/cuse.c
57668@@ -603,10 +603,12 @@ static int __init cuse_init(void)
57669 INIT_LIST_HEAD(&cuse_conntbl[i]);
57670
57671 /* inherit and extend fuse_dev_operations */
57672- cuse_channel_fops = fuse_dev_operations;
57673- cuse_channel_fops.owner = THIS_MODULE;
57674- cuse_channel_fops.open = cuse_channel_open;
57675- cuse_channel_fops.release = cuse_channel_release;
57676+ pax_open_kernel();
57677+ memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
57678+ *(void **)&cuse_channel_fops.owner = THIS_MODULE;
57679+ *(void **)&cuse_channel_fops.open = cuse_channel_open;
57680+ *(void **)&cuse_channel_fops.release = cuse_channel_release;
57681+ pax_close_kernel();
57682
57683 cuse_class = class_create(THIS_MODULE, "cuse");
57684 if (IS_ERR(cuse_class))
57685diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
57686index ef74ad5..c9ac759e 100644
57687--- a/fs/fuse/dev.c
57688+++ b/fs/fuse/dev.c
57689@@ -1339,7 +1339,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
57690 ret = 0;
57691 pipe_lock(pipe);
57692
57693- if (!pipe->readers) {
57694+ if (!atomic_read(&pipe->readers)) {
57695 send_sig(SIGPIPE, current, 0);
57696 if (!ret)
57697 ret = -EPIPE;
57698@@ -1364,7 +1364,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
57699 page_nr++;
57700 ret += buf->len;
57701
57702- if (pipe->files)
57703+ if (atomic_read(&pipe->files))
57704 do_wakeup = 1;
57705 }
57706
57707diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
57708index b7989f2..1f72ec4 100644
57709--- a/fs/fuse/dir.c
57710+++ b/fs/fuse/dir.c
57711@@ -1438,7 +1438,7 @@ static char *read_link(struct dentry *dentry)
57712 return link;
57713 }
57714
57715-static void free_link(char *link)
57716+static void free_link(const char *link)
57717 {
57718 if (!IS_ERR(link))
57719 free_page((unsigned long) link);
57720diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
57721index ced3257..b5c3b942 100644
57722--- a/fs/gfs2/inode.c
57723+++ b/fs/gfs2/inode.c
57724@@ -1508,7 +1508,7 @@ out:
57725
57726 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
57727 {
57728- char *s = nd_get_link(nd);
57729+ const char *s = nd_get_link(nd);
57730 if (!IS_ERR(s))
57731 kfree(s);
57732 }
57733diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c
57734index 2543728..14d7bd4 100644
57735--- a/fs/hostfs/hostfs_kern.c
57736+++ b/fs/hostfs/hostfs_kern.c
57737@@ -904,7 +904,7 @@ static void *hostfs_follow_link(struct dentry *dentry, struct nameidata *nd)
57738
57739 static void hostfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
57740 {
57741- char *s = nd_get_link(nd);
57742+ const char *s = nd_get_link(nd);
57743 if (!IS_ERR(s))
57744 __putname(s);
57745 }
57746diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
57747index d19b30a..ef89c36 100644
57748--- a/fs/hugetlbfs/inode.c
57749+++ b/fs/hugetlbfs/inode.c
57750@@ -152,6 +152,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
57751 struct mm_struct *mm = current->mm;
57752 struct vm_area_struct *vma;
57753 struct hstate *h = hstate_file(file);
57754+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
57755 struct vm_unmapped_area_info info;
57756
57757 if (len & ~huge_page_mask(h))
57758@@ -165,17 +166,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
57759 return addr;
57760 }
57761
57762+#ifdef CONFIG_PAX_RANDMMAP
57763+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
57764+#endif
57765+
57766 if (addr) {
57767 addr = ALIGN(addr, huge_page_size(h));
57768 vma = find_vma(mm, addr);
57769- if (TASK_SIZE - len >= addr &&
57770- (!vma || addr + len <= vma->vm_start))
57771+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
57772 return addr;
57773 }
57774
57775 info.flags = 0;
57776 info.length = len;
57777 info.low_limit = TASK_UNMAPPED_BASE;
57778+
57779+#ifdef CONFIG_PAX_RANDMMAP
57780+ if (mm->pax_flags & MF_PAX_RANDMMAP)
57781+ info.low_limit += mm->delta_mmap;
57782+#endif
57783+
57784 info.high_limit = TASK_SIZE;
57785 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
57786 info.align_offset = 0;
57787@@ -908,7 +918,7 @@ static struct file_system_type hugetlbfs_fs_type = {
57788 };
57789 MODULE_ALIAS_FS("hugetlbfs");
57790
57791-static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
57792+struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
57793
57794 static int can_do_hugetlb_shm(void)
57795 {
57796diff --git a/fs/inode.c b/fs/inode.c
57797index b33ba8e..3c79a47 100644
57798--- a/fs/inode.c
57799+++ b/fs/inode.c
57800@@ -849,8 +849,8 @@ unsigned int get_next_ino(void)
57801
57802 #ifdef CONFIG_SMP
57803 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
57804- static atomic_t shared_last_ino;
57805- int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
57806+ static atomic_unchecked_t shared_last_ino;
57807+ int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
57808
57809 res = next - LAST_INO_BATCH;
57810 }
57811diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
57812index 4a6cf28..d3a29d3 100644
57813--- a/fs/jffs2/erase.c
57814+++ b/fs/jffs2/erase.c
57815@@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
57816 struct jffs2_unknown_node marker = {
57817 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
57818 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
57819- .totlen = cpu_to_je32(c->cleanmarker_size)
57820+ .totlen = cpu_to_je32(c->cleanmarker_size),
57821+ .hdr_crc = cpu_to_je32(0)
57822 };
57823
57824 jffs2_prealloc_raw_node_refs(c, jeb, 1);
57825diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
57826index a6597d6..41b30ec 100644
57827--- a/fs/jffs2/wbuf.c
57828+++ b/fs/jffs2/wbuf.c
57829@@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
57830 {
57831 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
57832 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
57833- .totlen = constant_cpu_to_je32(8)
57834+ .totlen = constant_cpu_to_je32(8),
57835+ .hdr_crc = constant_cpu_to_je32(0)
57836 };
57837
57838 /*
57839diff --git a/fs/jfs/super.c b/fs/jfs/super.c
57840index 6669aa2..36b033d 100644
57841--- a/fs/jfs/super.c
57842+++ b/fs/jfs/super.c
57843@@ -882,7 +882,7 @@ static int __init init_jfs_fs(void)
57844
57845 jfs_inode_cachep =
57846 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
57847- SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
57848+ SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
57849 init_once);
57850 if (jfs_inode_cachep == NULL)
57851 return -ENOMEM;
57852diff --git a/fs/libfs.c b/fs/libfs.c
57853index 3a3a9b5..3a9b074 100644
57854--- a/fs/libfs.c
57855+++ b/fs/libfs.c
57856@@ -150,6 +150,9 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
57857
57858 for (p = q->next; p != &dentry->d_subdirs; p = p->next) {
57859 struct dentry *next = list_entry(p, struct dentry, d_u.d_child);
57860+ char d_name[sizeof(next->d_iname)];
57861+ const unsigned char *name;
57862+
57863 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
57864 if (!simple_positive(next)) {
57865 spin_unlock(&next->d_lock);
57866@@ -158,7 +161,12 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
57867
57868 spin_unlock(&next->d_lock);
57869 spin_unlock(&dentry->d_lock);
57870- if (!dir_emit(ctx, next->d_name.name, next->d_name.len,
57871+ name = next->d_name.name;
57872+ if (name == next->d_iname) {
57873+ memcpy(d_name, name, next->d_name.len);
57874+ name = d_name;
57875+ }
57876+ if (!dir_emit(ctx, name, next->d_name.len,
57877 next->d_inode->i_ino, dt_type(next->d_inode)))
57878 return 0;
57879 spin_lock(&dentry->d_lock);
57880diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
57881index acd3947..1f896e2 100644
57882--- a/fs/lockd/clntproc.c
57883+++ b/fs/lockd/clntproc.c
57884@@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
57885 /*
57886 * Cookie counter for NLM requests
57887 */
57888-static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
57889+static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
57890
57891 void nlmclnt_next_cookie(struct nlm_cookie *c)
57892 {
57893- u32 cookie = atomic_inc_return(&nlm_cookie);
57894+ u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
57895
57896 memcpy(c->data, &cookie, 4);
57897 c->len=4;
57898diff --git a/fs/locks.c b/fs/locks.c
57899index b27a300..4156d0b 100644
57900--- a/fs/locks.c
57901+++ b/fs/locks.c
57902@@ -2183,16 +2183,16 @@ void locks_remove_flock(struct file *filp)
57903 return;
57904
57905 if (filp->f_op && filp->f_op->flock) {
57906- struct file_lock fl = {
57907+ struct file_lock flock = {
57908 .fl_pid = current->tgid,
57909 .fl_file = filp,
57910 .fl_flags = FL_FLOCK,
57911 .fl_type = F_UNLCK,
57912 .fl_end = OFFSET_MAX,
57913 };
57914- filp->f_op->flock(filp, F_SETLKW, &fl);
57915- if (fl.fl_ops && fl.fl_ops->fl_release_private)
57916- fl.fl_ops->fl_release_private(&fl);
57917+ filp->f_op->flock(filp, F_SETLKW, &flock);
57918+ if (flock.fl_ops && flock.fl_ops->fl_release_private)
57919+ flock.fl_ops->fl_release_private(&flock);
57920 }
57921
57922 spin_lock(&inode->i_lock);
57923diff --git a/fs/namei.c b/fs/namei.c
57924index caa2805..c9d3edc 100644
57925--- a/fs/namei.c
57926+++ b/fs/namei.c
57927@@ -319,16 +319,32 @@ int generic_permission(struct inode *inode, int mask)
57928 if (ret != -EACCES)
57929 return ret;
57930
57931+#ifdef CONFIG_GRKERNSEC
57932+ /* we'll block if we have to log due to a denied capability use */
57933+ if (mask & MAY_NOT_BLOCK)
57934+ return -ECHILD;
57935+#endif
57936+
57937 if (S_ISDIR(inode->i_mode)) {
57938 /* DACs are overridable for directories */
57939- if (inode_capable(inode, CAP_DAC_OVERRIDE))
57940- return 0;
57941 if (!(mask & MAY_WRITE))
57942- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
57943+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
57944+ inode_capable(inode, CAP_DAC_READ_SEARCH))
57945 return 0;
57946+ if (inode_capable(inode, CAP_DAC_OVERRIDE))
57947+ return 0;
57948 return -EACCES;
57949 }
57950 /*
57951+ * Searching includes executable on directories, else just read.
57952+ */
57953+ mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
57954+ if (mask == MAY_READ)
57955+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
57956+ inode_capable(inode, CAP_DAC_READ_SEARCH))
57957+ return 0;
57958+
57959+ /*
57960 * Read/write DACs are always overridable.
57961 * Executable DACs are overridable when there is
57962 * at least one exec bit set.
57963@@ -337,14 +353,6 @@ int generic_permission(struct inode *inode, int mask)
57964 if (inode_capable(inode, CAP_DAC_OVERRIDE))
57965 return 0;
57966
57967- /*
57968- * Searching includes executable on directories, else just read.
57969- */
57970- mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
57971- if (mask == MAY_READ)
57972- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
57973- return 0;
57974-
57975 return -EACCES;
57976 }
57977
57978@@ -821,7 +829,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
57979 {
57980 struct dentry *dentry = link->dentry;
57981 int error;
57982- char *s;
57983+ const char *s;
57984
57985 BUG_ON(nd->flags & LOOKUP_RCU);
57986
57987@@ -842,6 +850,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
57988 if (error)
57989 goto out_put_nd_path;
57990
57991+ if (gr_handle_follow_link(dentry->d_parent->d_inode,
57992+ dentry->d_inode, dentry, nd->path.mnt)) {
57993+ error = -EACCES;
57994+ goto out_put_nd_path;
57995+ }
57996+
57997 nd->last_type = LAST_BIND;
57998 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
57999 error = PTR_ERR(*p);
58000@@ -1602,6 +1616,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
58001 if (res)
58002 break;
58003 res = walk_component(nd, path, LOOKUP_FOLLOW);
58004+ if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
58005+ res = -EACCES;
58006 put_link(nd, &link, cookie);
58007 } while (res > 0);
58008
58009@@ -1700,7 +1716,7 @@ EXPORT_SYMBOL(full_name_hash);
58010 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
58011 {
58012 unsigned long a, b, adata, bdata, mask, hash, len;
58013- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
58014+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
58015
58016 hash = a = 0;
58017 len = -sizeof(unsigned long);
58018@@ -1981,6 +1997,8 @@ static int path_lookupat(int dfd, const char *name,
58019 if (err)
58020 break;
58021 err = lookup_last(nd, &path);
58022+ if (!err && gr_handle_symlink_owner(&link, nd->inode))
58023+ err = -EACCES;
58024 put_link(nd, &link, cookie);
58025 }
58026 }
58027@@ -1988,6 +2006,13 @@ static int path_lookupat(int dfd, const char *name,
58028 if (!err)
58029 err = complete_walk(nd);
58030
58031+ if (!err && !(nd->flags & LOOKUP_PARENT)) {
58032+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
58033+ path_put(&nd->path);
58034+ err = -ENOENT;
58035+ }
58036+ }
58037+
58038 if (!err && nd->flags & LOOKUP_DIRECTORY) {
58039 if (!can_lookup(nd->inode)) {
58040 path_put(&nd->path);
58041@@ -2015,8 +2040,15 @@ static int filename_lookup(int dfd, struct filename *name,
58042 retval = path_lookupat(dfd, name->name,
58043 flags | LOOKUP_REVAL, nd);
58044
58045- if (likely(!retval))
58046+ if (likely(!retval)) {
58047 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
58048+ if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
58049+ if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt)) {
58050+ path_put(&nd->path);
58051+ return -ENOENT;
58052+ }
58053+ }
58054+ }
58055 return retval;
58056 }
58057
58058@@ -2586,6 +2618,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
58059 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
58060 return -EPERM;
58061
58062+ if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
58063+ return -EPERM;
58064+ if (gr_handle_rawio(inode))
58065+ return -EPERM;
58066+ if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
58067+ return -EACCES;
58068+
58069 return 0;
58070 }
58071
58072@@ -2817,7 +2856,7 @@ looked_up:
58073 * cleared otherwise prior to returning.
58074 */
58075 static int lookup_open(struct nameidata *nd, struct path *path,
58076- struct file *file,
58077+ struct path *link, struct file *file,
58078 const struct open_flags *op,
58079 bool got_write, int *opened)
58080 {
58081@@ -2852,6 +2891,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
58082 /* Negative dentry, just create the file */
58083 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
58084 umode_t mode = op->mode;
58085+
58086+ if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
58087+ error = -EACCES;
58088+ goto out_dput;
58089+ }
58090+
58091+ if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
58092+ error = -EACCES;
58093+ goto out_dput;
58094+ }
58095+
58096 if (!IS_POSIXACL(dir->d_inode))
58097 mode &= ~current_umask();
58098 /*
58099@@ -2873,6 +2923,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
58100 nd->flags & LOOKUP_EXCL);
58101 if (error)
58102 goto out_dput;
58103+ else
58104+ gr_handle_create(dentry, nd->path.mnt);
58105 }
58106 out_no_open:
58107 path->dentry = dentry;
58108@@ -2887,7 +2939,7 @@ out_dput:
58109 /*
58110 * Handle the last step of open()
58111 */
58112-static int do_last(struct nameidata *nd, struct path *path,
58113+static int do_last(struct nameidata *nd, struct path *path, struct path *link,
58114 struct file *file, const struct open_flags *op,
58115 int *opened, struct filename *name)
58116 {
58117@@ -2937,6 +2989,15 @@ static int do_last(struct nameidata *nd, struct path *path,
58118 if (error)
58119 return error;
58120
58121+ if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
58122+ error = -ENOENT;
58123+ goto out;
58124+ }
58125+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
58126+ error = -EACCES;
58127+ goto out;
58128+ }
58129+
58130 audit_inode(name, dir, LOOKUP_PARENT);
58131 error = -EISDIR;
58132 /* trailing slashes? */
58133@@ -2956,7 +3017,7 @@ retry_lookup:
58134 */
58135 }
58136 mutex_lock(&dir->d_inode->i_mutex);
58137- error = lookup_open(nd, path, file, op, got_write, opened);
58138+ error = lookup_open(nd, path, link, file, op, got_write, opened);
58139 mutex_unlock(&dir->d_inode->i_mutex);
58140
58141 if (error <= 0) {
58142@@ -2980,11 +3041,28 @@ retry_lookup:
58143 goto finish_open_created;
58144 }
58145
58146+ if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
58147+ error = -ENOENT;
58148+ goto exit_dput;
58149+ }
58150+ if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
58151+ error = -EACCES;
58152+ goto exit_dput;
58153+ }
58154+
58155 /*
58156 * create/update audit record if it already exists.
58157 */
58158- if (path->dentry->d_inode)
58159+ if (path->dentry->d_inode) {
58160+ /* only check if O_CREAT is specified, all other checks need to go
58161+ into may_open */
58162+ if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
58163+ error = -EACCES;
58164+ goto exit_dput;
58165+ }
58166+
58167 audit_inode(name, path->dentry, 0);
58168+ }
58169
58170 /*
58171 * If atomic_open() acquired write access it is dropped now due to
58172@@ -3025,6 +3103,11 @@ finish_lookup:
58173 }
58174 }
58175 BUG_ON(inode != path->dentry->d_inode);
58176+ /* if we're resolving a symlink to another symlink */
58177+ if (link && gr_handle_symlink_owner(link, inode)) {
58178+ error = -EACCES;
58179+ goto out;
58180+ }
58181 return 1;
58182 }
58183
58184@@ -3034,7 +3117,6 @@ finish_lookup:
58185 save_parent.dentry = nd->path.dentry;
58186 save_parent.mnt = mntget(path->mnt);
58187 nd->path.dentry = path->dentry;
58188-
58189 }
58190 nd->inode = inode;
58191 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
58192@@ -3044,7 +3126,18 @@ finish_open:
58193 path_put(&save_parent);
58194 return error;
58195 }
58196+
58197+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
58198+ error = -ENOENT;
58199+ goto out;
58200+ }
58201+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
58202+ error = -EACCES;
58203+ goto out;
58204+ }
58205+
58206 audit_inode(name, nd->path.dentry, 0);
58207+
58208 error = -EISDIR;
58209 if ((open_flag & O_CREAT) && S_ISDIR(nd->inode->i_mode))
58210 goto out;
58211@@ -3207,7 +3300,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
58212 if (unlikely(error))
58213 goto out;
58214
58215- error = do_last(nd, &path, file, op, &opened, pathname);
58216+ error = do_last(nd, &path, NULL, file, op, &opened, pathname);
58217 while (unlikely(error > 0)) { /* trailing symlink */
58218 struct path link = path;
58219 void *cookie;
58220@@ -3225,7 +3318,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
58221 error = follow_link(&link, nd, &cookie);
58222 if (unlikely(error))
58223 break;
58224- error = do_last(nd, &path, file, op, &opened, pathname);
58225+ error = do_last(nd, &path, &link, file, op, &opened, pathname);
58226 put_link(nd, &link, cookie);
58227 }
58228 out:
58229@@ -3325,8 +3418,12 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
58230 goto unlock;
58231
58232 error = -EEXIST;
58233- if (dentry->d_inode)
58234+ if (dentry->d_inode) {
58235+ if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
58236+ error = -ENOENT;
58237+ }
58238 goto fail;
58239+ }
58240 /*
58241 * Special case - lookup gave negative, but... we had foo/bar/
58242 * From the vfs_mknod() POV we just have a negative dentry -
58243@@ -3378,6 +3475,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
58244 }
58245 EXPORT_SYMBOL(user_path_create);
58246
58247+static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, unsigned int lookup_flags)
58248+{
58249+ struct filename *tmp = getname(pathname);
58250+ struct dentry *res;
58251+ if (IS_ERR(tmp))
58252+ return ERR_CAST(tmp);
58253+ res = kern_path_create(dfd, tmp->name, path, lookup_flags);
58254+ if (IS_ERR(res))
58255+ putname(tmp);
58256+ else
58257+ *to = tmp;
58258+ return res;
58259+}
58260+
58261 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
58262 {
58263 int error = may_create(dir, dentry);
58264@@ -3440,6 +3551,17 @@ retry:
58265
58266 if (!IS_POSIXACL(path.dentry->d_inode))
58267 mode &= ~current_umask();
58268+
58269+ if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
58270+ error = -EPERM;
58271+ goto out;
58272+ }
58273+
58274+ if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
58275+ error = -EACCES;
58276+ goto out;
58277+ }
58278+
58279 error = security_path_mknod(&path, dentry, mode, dev);
58280 if (error)
58281 goto out;
58282@@ -3456,6 +3578,8 @@ retry:
58283 break;
58284 }
58285 out:
58286+ if (!error)
58287+ gr_handle_create(dentry, path.mnt);
58288 done_path_create(&path, dentry);
58289 if (retry_estale(error, lookup_flags)) {
58290 lookup_flags |= LOOKUP_REVAL;
58291@@ -3508,9 +3632,16 @@ retry:
58292
58293 if (!IS_POSIXACL(path.dentry->d_inode))
58294 mode &= ~current_umask();
58295+ if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
58296+ error = -EACCES;
58297+ goto out;
58298+ }
58299 error = security_path_mkdir(&path, dentry, mode);
58300 if (!error)
58301 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
58302+ if (!error)
58303+ gr_handle_create(dentry, path.mnt);
58304+out:
58305 done_path_create(&path, dentry);
58306 if (retry_estale(error, lookup_flags)) {
58307 lookup_flags |= LOOKUP_REVAL;
58308@@ -3591,6 +3722,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
58309 struct filename *name;
58310 struct dentry *dentry;
58311 struct nameidata nd;
58312+ ino_t saved_ino = 0;
58313+ dev_t saved_dev = 0;
58314 unsigned int lookup_flags = 0;
58315 retry:
58316 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
58317@@ -3623,10 +3756,21 @@ retry:
58318 error = -ENOENT;
58319 goto exit3;
58320 }
58321+
58322+ saved_ino = dentry->d_inode->i_ino;
58323+ saved_dev = gr_get_dev_from_dentry(dentry);
58324+
58325+ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
58326+ error = -EACCES;
58327+ goto exit3;
58328+ }
58329+
58330 error = security_path_rmdir(&nd.path, dentry);
58331 if (error)
58332 goto exit3;
58333 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
58334+ if (!error && (saved_dev || saved_ino))
58335+ gr_handle_delete(saved_ino, saved_dev);
58336 exit3:
58337 dput(dentry);
58338 exit2:
58339@@ -3692,6 +3836,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
58340 struct dentry *dentry;
58341 struct nameidata nd;
58342 struct inode *inode = NULL;
58343+ ino_t saved_ino = 0;
58344+ dev_t saved_dev = 0;
58345 unsigned int lookup_flags = 0;
58346 retry:
58347 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
58348@@ -3718,10 +3864,22 @@ retry:
58349 if (!inode)
58350 goto slashes;
58351 ihold(inode);
58352+
58353+ if (inode->i_nlink <= 1) {
58354+ saved_ino = inode->i_ino;
58355+ saved_dev = gr_get_dev_from_dentry(dentry);
58356+ }
58357+ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
58358+ error = -EACCES;
58359+ goto exit2;
58360+ }
58361+
58362 error = security_path_unlink(&nd.path, dentry);
58363 if (error)
58364 goto exit2;
58365 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
58366+ if (!error && (saved_ino || saved_dev))
58367+ gr_handle_delete(saved_ino, saved_dev);
58368 exit2:
58369 dput(dentry);
58370 }
58371@@ -3799,9 +3957,17 @@ retry:
58372 if (IS_ERR(dentry))
58373 goto out_putname;
58374
58375+ if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
58376+ error = -EACCES;
58377+ goto out;
58378+ }
58379+
58380 error = security_path_symlink(&path, dentry, from->name);
58381 if (!error)
58382 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
58383+ if (!error)
58384+ gr_handle_create(dentry, path.mnt);
58385+out:
58386 done_path_create(&path, dentry);
58387 if (retry_estale(error, lookup_flags)) {
58388 lookup_flags |= LOOKUP_REVAL;
58389@@ -3881,6 +4047,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
58390 {
58391 struct dentry *new_dentry;
58392 struct path old_path, new_path;
58393+ struct filename *to = NULL;
58394 int how = 0;
58395 int error;
58396
58397@@ -3904,7 +4071,7 @@ retry:
58398 if (error)
58399 return error;
58400
58401- new_dentry = user_path_create(newdfd, newname, &new_path,
58402+ new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
58403 (how & LOOKUP_REVAL));
58404 error = PTR_ERR(new_dentry);
58405 if (IS_ERR(new_dentry))
58406@@ -3916,11 +4083,28 @@ retry:
58407 error = may_linkat(&old_path);
58408 if (unlikely(error))
58409 goto out_dput;
58410+
58411+ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
58412+ old_path.dentry->d_inode,
58413+ old_path.dentry->d_inode->i_mode, to)) {
58414+ error = -EACCES;
58415+ goto out_dput;
58416+ }
58417+
58418+ if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
58419+ old_path.dentry, old_path.mnt, to)) {
58420+ error = -EACCES;
58421+ goto out_dput;
58422+ }
58423+
58424 error = security_path_link(old_path.dentry, &new_path, new_dentry);
58425 if (error)
58426 goto out_dput;
58427 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
58428+ if (!error)
58429+ gr_handle_create(new_dentry, new_path.mnt);
58430 out_dput:
58431+ putname(to);
58432 done_path_create(&new_path, new_dentry);
58433 if (retry_estale(error, how)) {
58434 how |= LOOKUP_REVAL;
58435@@ -4166,12 +4350,21 @@ retry:
58436 if (new_dentry == trap)
58437 goto exit5;
58438
58439+ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
58440+ old_dentry, old_dir->d_inode, oldnd.path.mnt,
58441+ to);
58442+ if (error)
58443+ goto exit5;
58444+
58445 error = security_path_rename(&oldnd.path, old_dentry,
58446 &newnd.path, new_dentry);
58447 if (error)
58448 goto exit5;
58449 error = vfs_rename(old_dir->d_inode, old_dentry,
58450 new_dir->d_inode, new_dentry);
58451+ if (!error)
58452+ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
58453+ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
58454 exit5:
58455 dput(new_dentry);
58456 exit4:
58457@@ -4203,6 +4396,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
58458
58459 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
58460 {
58461+ char tmpbuf[64];
58462+ const char *newlink;
58463 int len;
58464
58465 len = PTR_ERR(link);
58466@@ -4212,7 +4407,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
58467 len = strlen(link);
58468 if (len > (unsigned) buflen)
58469 len = buflen;
58470- if (copy_to_user(buffer, link, len))
58471+
58472+ if (len < sizeof(tmpbuf)) {
58473+ memcpy(tmpbuf, link, len);
58474+ newlink = tmpbuf;
58475+ } else
58476+ newlink = link;
58477+
58478+ if (copy_to_user(buffer, newlink, len))
58479 len = -EFAULT;
58480 out:
58481 return len;
58482diff --git a/fs/namespace.c b/fs/namespace.c
58483index da5c494..a755a54 100644
58484--- a/fs/namespace.c
58485+++ b/fs/namespace.c
58486@@ -1268,6 +1268,9 @@ static int do_umount(struct mount *mnt, int flags)
58487 if (!(sb->s_flags & MS_RDONLY))
58488 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
58489 up_write(&sb->s_umount);
58490+
58491+ gr_log_remount(mnt->mnt_devname, retval);
58492+
58493 return retval;
58494 }
58495
58496@@ -1286,6 +1289,9 @@ static int do_umount(struct mount *mnt, int flags)
58497 }
58498 br_write_unlock(&vfsmount_lock);
58499 namespace_unlock();
58500+
58501+ gr_log_unmount(mnt->mnt_devname, retval);
58502+
58503 return retval;
58504 }
58505
58506@@ -1305,7 +1311,7 @@ static inline bool may_mount(void)
58507 * unixes. Our API is identical to OSF/1 to avoid making a mess of AMD
58508 */
58509
58510-SYSCALL_DEFINE2(umount, char __user *, name, int, flags)
58511+SYSCALL_DEFINE2(umount, const char __user *, name, int, flags)
58512 {
58513 struct path path;
58514 struct mount *mnt;
58515@@ -1347,7 +1353,7 @@ out:
58516 /*
58517 * The 2.0 compatible umount. No flags.
58518 */
58519-SYSCALL_DEFINE1(oldumount, char __user *, name)
58520+SYSCALL_DEFINE1(oldumount, const char __user *, name)
58521 {
58522 return sys_umount(name, 0);
58523 }
58524@@ -2358,6 +2364,16 @@ long do_mount(const char *dev_name, const char *dir_name,
58525 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
58526 MS_STRICTATIME);
58527
58528+ if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
58529+ retval = -EPERM;
58530+ goto dput_out;
58531+ }
58532+
58533+ if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
58534+ retval = -EPERM;
58535+ goto dput_out;
58536+ }
58537+
58538 if (flags & MS_REMOUNT)
58539 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
58540 data_page);
58541@@ -2372,6 +2388,9 @@ long do_mount(const char *dev_name, const char *dir_name,
58542 dev_name, data_page);
58543 dput_out:
58544 path_put(&path);
58545+
58546+ gr_log_mount(dev_name, dir_name, retval);
58547+
58548 return retval;
58549 }
58550
58551@@ -2389,7 +2408,7 @@ static void free_mnt_ns(struct mnt_namespace *ns)
58552 * number incrementing at 10Ghz will take 12,427 years to wrap which
58553 * is effectively never, so we can ignore the possibility.
58554 */
58555-static atomic64_t mnt_ns_seq = ATOMIC64_INIT(1);
58556+static atomic64_unchecked_t mnt_ns_seq = ATOMIC64_INIT(1);
58557
58558 static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
58559 {
58560@@ -2404,7 +2423,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
58561 kfree(new_ns);
58562 return ERR_PTR(ret);
58563 }
58564- new_ns->seq = atomic64_add_return(1, &mnt_ns_seq);
58565+ new_ns->seq = atomic64_inc_return_unchecked(&mnt_ns_seq);
58566 atomic_set(&new_ns->count, 1);
58567 new_ns->root = NULL;
58568 INIT_LIST_HEAD(&new_ns->list);
58569@@ -2418,7 +2437,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
58570 * Allocate a new namespace structure and populate it with contents
58571 * copied from the namespace of the passed in task structure.
58572 */
58573-static struct mnt_namespace *dup_mnt_ns(struct mnt_namespace *mnt_ns,
58574+static __latent_entropy struct mnt_namespace *dup_mnt_ns(struct mnt_namespace *mnt_ns,
58575 struct user_namespace *user_ns, struct fs_struct *fs)
58576 {
58577 struct mnt_namespace *new_ns;
58578@@ -2549,8 +2568,8 @@ struct dentry *mount_subtree(struct vfsmount *mnt, const char *name)
58579 }
58580 EXPORT_SYMBOL(mount_subtree);
58581
58582-SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,
58583- char __user *, type, unsigned long, flags, void __user *, data)
58584+SYSCALL_DEFINE5(mount, const char __user *, dev_name, const char __user *, dir_name,
58585+ const char __user *, type, unsigned long, flags, void __user *, data)
58586 {
58587 int ret;
58588 char *kernel_type;
58589@@ -2663,6 +2682,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
58590 if (error)
58591 goto out2;
58592
58593+ if (gr_handle_chroot_pivot()) {
58594+ error = -EPERM;
58595+ goto out2;
58596+ }
58597+
58598 get_fs_root(current->fs, &root);
58599 old_mp = lock_mount(&old);
58600 error = PTR_ERR(old_mp);
58601@@ -2932,7 +2956,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
58602 !ns_capable(current_user_ns(), CAP_SYS_ADMIN))
58603 return -EPERM;
58604
58605- if (fs->users != 1)
58606+ if (atomic_read(&fs->users) != 1)
58607 return -EINVAL;
58608
58609 get_mnt_ns(mnt_ns);
58610diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
58611index f4ccfe6..a5cf064 100644
58612--- a/fs/nfs/callback_xdr.c
58613+++ b/fs/nfs/callback_xdr.c
58614@@ -51,7 +51,7 @@ struct callback_op {
58615 callback_decode_arg_t decode_args;
58616 callback_encode_res_t encode_res;
58617 long res_maxsize;
58618-};
58619+} __do_const;
58620
58621 static struct callback_op callback_ops[];
58622
58623diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
58624index eda8879..bfc6837 100644
58625--- a/fs/nfs/inode.c
58626+++ b/fs/nfs/inode.c
58627@@ -1150,16 +1150,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
58628 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
58629 }
58630
58631-static atomic_long_t nfs_attr_generation_counter;
58632+static atomic_long_unchecked_t nfs_attr_generation_counter;
58633
58634 static unsigned long nfs_read_attr_generation_counter(void)
58635 {
58636- return atomic_long_read(&nfs_attr_generation_counter);
58637+ return atomic_long_read_unchecked(&nfs_attr_generation_counter);
58638 }
58639
58640 unsigned long nfs_inc_attr_generation_counter(void)
58641 {
58642- return atomic_long_inc_return(&nfs_attr_generation_counter);
58643+ return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
58644 }
58645
58646 void nfs_fattr_init(struct nfs_fattr *fattr)
58647diff --git a/fs/nfs/nfs4state.c b/fs/nfs/nfs4state.c
58648index cc14cbb..6021bb6 100644
58649--- a/fs/nfs/nfs4state.c
58650+++ b/fs/nfs/nfs4state.c
58651@@ -1881,10 +1881,15 @@ again:
58652 nfs4_root_machine_cred(clp);
58653 goto again;
58654 }
58655- if (i > 2)
58656+ if (clnt->cl_auth->au_flavor == RPC_AUTH_UNIX)
58657 break;
58658 case -NFS4ERR_CLID_INUSE:
58659 case -NFS4ERR_WRONGSEC:
58660+ /* No point in retrying if we already used RPC_AUTH_UNIX */
58661+ if (clnt->cl_auth->au_flavor == RPC_AUTH_UNIX) {
58662+ status = -EPERM;
58663+ break;
58664+ }
58665 clnt = rpc_clone_client_set_auth(clnt, RPC_AUTH_UNIX);
58666 if (IS_ERR(clnt)) {
58667 status = PTR_ERR(clnt);
58668diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
58669index 419572f..5414a23 100644
58670--- a/fs/nfsd/nfs4proc.c
58671+++ b/fs/nfsd/nfs4proc.c
58672@@ -1168,7 +1168,7 @@ struct nfsd4_operation {
58673 nfsd4op_rsize op_rsize_bop;
58674 stateid_getter op_get_currentstateid;
58675 stateid_setter op_set_currentstateid;
58676-};
58677+} __do_const;
58678
58679 static struct nfsd4_operation nfsd4_ops[];
58680
58681diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
58682index d9454fe..855c9d1 100644
58683--- a/fs/nfsd/nfs4xdr.c
58684+++ b/fs/nfsd/nfs4xdr.c
58685@@ -1498,7 +1498,7 @@ nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
58686
58687 typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
58688
58689-static nfsd4_dec nfsd4_dec_ops[] = {
58690+static const nfsd4_dec nfsd4_dec_ops[] = {
58691 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
58692 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
58693 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
58694@@ -1538,7 +1538,7 @@ static nfsd4_dec nfsd4_dec_ops[] = {
58695 [OP_RELEASE_LOCKOWNER] = (nfsd4_dec)nfsd4_decode_release_lockowner,
58696 };
58697
58698-static nfsd4_dec nfsd41_dec_ops[] = {
58699+static const nfsd4_dec nfsd41_dec_ops[] = {
58700 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
58701 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
58702 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
58703@@ -1600,7 +1600,7 @@ static nfsd4_dec nfsd41_dec_ops[] = {
58704 };
58705
58706 struct nfsd4_minorversion_ops {
58707- nfsd4_dec *decoders;
58708+ const nfsd4_dec *decoders;
58709 int nops;
58710 };
58711
58712diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
58713index 9186c7c..3fdde3e 100644
58714--- a/fs/nfsd/nfscache.c
58715+++ b/fs/nfsd/nfscache.c
58716@@ -540,14 +540,17 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
58717 {
58718 struct svc_cacherep *rp = rqstp->rq_cacherep;
58719 struct kvec *resv = &rqstp->rq_res.head[0], *cachv;
58720- int len;
58721+ long len;
58722 size_t bufsize = 0;
58723
58724 if (!rp)
58725 return;
58726
58727- len = resv->iov_len - ((char*)statp - (char*)resv->iov_base);
58728- len >>= 2;
58729+ if (statp) {
58730+ len = (char*)statp - (char*)resv->iov_base;
58731+ len = resv->iov_len - len;
58732+ len >>= 2;
58733+ }
58734
58735 /* Don't cache excessive amounts of data and XDR failures */
58736 if (!statp || len > (256 >> 2)) {
58737diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
58738index c827acb..b253b77 100644
58739--- a/fs/nfsd/vfs.c
58740+++ b/fs/nfsd/vfs.c
58741@@ -968,7 +968,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
58742 } else {
58743 oldfs = get_fs();
58744 set_fs(KERNEL_DS);
58745- host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
58746+ host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
58747 set_fs(oldfs);
58748 }
58749
58750@@ -1055,7 +1055,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
58751
58752 /* Write the data. */
58753 oldfs = get_fs(); set_fs(KERNEL_DS);
58754- host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &pos);
58755+ host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &pos);
58756 set_fs(oldfs);
58757 if (host_err < 0)
58758 goto out_nfserr;
58759@@ -1601,7 +1601,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
58760 */
58761
58762 oldfs = get_fs(); set_fs(KERNEL_DS);
58763- host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
58764+ host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
58765 set_fs(oldfs);
58766
58767 if (host_err < 0)
58768diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c
58769index fea6bd5..8ee9d81 100644
58770--- a/fs/nls/nls_base.c
58771+++ b/fs/nls/nls_base.c
58772@@ -234,20 +234,22 @@ EXPORT_SYMBOL(utf16s_to_utf8s);
58773
58774 int register_nls(struct nls_table * nls)
58775 {
58776- struct nls_table ** tmp = &tables;
58777+ struct nls_table *tmp = tables;
58778
58779 if (nls->next)
58780 return -EBUSY;
58781
58782 spin_lock(&nls_lock);
58783- while (*tmp) {
58784- if (nls == *tmp) {
58785+ while (tmp) {
58786+ if (nls == tmp) {
58787 spin_unlock(&nls_lock);
58788 return -EBUSY;
58789 }
58790- tmp = &(*tmp)->next;
58791+ tmp = tmp->next;
58792 }
58793- nls->next = tables;
58794+ pax_open_kernel();
58795+ *(struct nls_table **)&nls->next = tables;
58796+ pax_close_kernel();
58797 tables = nls;
58798 spin_unlock(&nls_lock);
58799 return 0;
58800@@ -255,12 +257,14 @@ int register_nls(struct nls_table * nls)
58801
58802 int unregister_nls(struct nls_table * nls)
58803 {
58804- struct nls_table ** tmp = &tables;
58805+ struct nls_table * const * tmp = &tables;
58806
58807 spin_lock(&nls_lock);
58808 while (*tmp) {
58809 if (nls == *tmp) {
58810- *tmp = nls->next;
58811+ pax_open_kernel();
58812+ *(struct nls_table **)tmp = nls->next;
58813+ pax_close_kernel();
58814 spin_unlock(&nls_lock);
58815 return 0;
58816 }
58817diff --git a/fs/nls/nls_euc-jp.c b/fs/nls/nls_euc-jp.c
58818index 7424929..35f6be5 100644
58819--- a/fs/nls/nls_euc-jp.c
58820+++ b/fs/nls/nls_euc-jp.c
58821@@ -561,8 +561,10 @@ static int __init init_nls_euc_jp(void)
58822 p_nls = load_nls("cp932");
58823
58824 if (p_nls) {
58825- table.charset2upper = p_nls->charset2upper;
58826- table.charset2lower = p_nls->charset2lower;
58827+ pax_open_kernel();
58828+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
58829+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
58830+ pax_close_kernel();
58831 return register_nls(&table);
58832 }
58833
58834diff --git a/fs/nls/nls_koi8-ru.c b/fs/nls/nls_koi8-ru.c
58835index e7bc1d7..06bd4bb 100644
58836--- a/fs/nls/nls_koi8-ru.c
58837+++ b/fs/nls/nls_koi8-ru.c
58838@@ -63,8 +63,10 @@ static int __init init_nls_koi8_ru(void)
58839 p_nls = load_nls("koi8-u");
58840
58841 if (p_nls) {
58842- table.charset2upper = p_nls->charset2upper;
58843- table.charset2lower = p_nls->charset2lower;
58844+ pax_open_kernel();
58845+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
58846+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
58847+ pax_close_kernel();
58848 return register_nls(&table);
58849 }
58850
58851diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
58852index e44cb64..4807084 100644
58853--- a/fs/notify/fanotify/fanotify_user.c
58854+++ b/fs/notify/fanotify/fanotify_user.c
58855@@ -253,8 +253,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
58856
58857 fd = fanotify_event_metadata.fd;
58858 ret = -EFAULT;
58859- if (copy_to_user(buf, &fanotify_event_metadata,
58860- fanotify_event_metadata.event_len))
58861+ if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
58862+ copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
58863 goto out_close_fd;
58864
58865 ret = prepare_for_access_response(group, event, fd);
58866diff --git a/fs/notify/notification.c b/fs/notify/notification.c
58867index 7b51b05..5ea5ef6 100644
58868--- a/fs/notify/notification.c
58869+++ b/fs/notify/notification.c
58870@@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
58871 * get set to 0 so it will never get 'freed'
58872 */
58873 static struct fsnotify_event *q_overflow_event;
58874-static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
58875+static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
58876
58877 /**
58878 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
58879@@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
58880 */
58881 u32 fsnotify_get_cookie(void)
58882 {
58883- return atomic_inc_return(&fsnotify_sync_cookie);
58884+ return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
58885 }
58886 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
58887
58888diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
58889index 9e38daf..5727cae 100644
58890--- a/fs/ntfs/dir.c
58891+++ b/fs/ntfs/dir.c
58892@@ -1310,7 +1310,7 @@ find_next_index_buffer:
58893 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
58894 ~(s64)(ndir->itype.index.block_size - 1)));
58895 /* Bounds checks. */
58896- if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
58897+ if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
58898 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
58899 "inode 0x%lx or driver bug.", vdir->i_ino);
58900 goto err_out;
58901diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
58902index ea4ba9d..1e13d34 100644
58903--- a/fs/ntfs/file.c
58904+++ b/fs/ntfs/file.c
58905@@ -1282,7 +1282,7 @@ static inline size_t ntfs_copy_from_user(struct page **pages,
58906 char *addr;
58907 size_t total = 0;
58908 unsigned len;
58909- int left;
58910+ unsigned left;
58911
58912 do {
58913 len = PAGE_CACHE_SIZE - ofs;
58914diff --git a/fs/ntfs/super.c b/fs/ntfs/super.c
58915index 82650d5..db37dcf 100644
58916--- a/fs/ntfs/super.c
58917+++ b/fs/ntfs/super.c
58918@@ -685,7 +685,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
58919 if (!silent)
58920 ntfs_error(sb, "Primary boot sector is invalid.");
58921 } else if (!silent)
58922- ntfs_error(sb, read_err_str, "primary");
58923+ ntfs_error(sb, read_err_str, "%s", "primary");
58924 if (!(NTFS_SB(sb)->on_errors & ON_ERRORS_RECOVER)) {
58925 if (bh_primary)
58926 brelse(bh_primary);
58927@@ -701,7 +701,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
58928 goto hotfix_primary_boot_sector;
58929 brelse(bh_backup);
58930 } else if (!silent)
58931- ntfs_error(sb, read_err_str, "backup");
58932+ ntfs_error(sb, read_err_str, "%s", "backup");
58933 /* Try to read NT3.51- backup boot sector. */
58934 if ((bh_backup = sb_bread(sb, nr_blocks >> 1))) {
58935 if (is_boot_sector_ntfs(sb, (NTFS_BOOT_SECTOR*)
58936@@ -712,7 +712,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
58937 "sector.");
58938 brelse(bh_backup);
58939 } else if (!silent)
58940- ntfs_error(sb, read_err_str, "backup");
58941+ ntfs_error(sb, read_err_str, "%s", "backup");
58942 /* We failed. Cleanup and return. */
58943 if (bh_primary)
58944 brelse(bh_primary);
58945diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
58946index cd5496b..26a1055 100644
58947--- a/fs/ocfs2/localalloc.c
58948+++ b/fs/ocfs2/localalloc.c
58949@@ -1278,7 +1278,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
58950 goto bail;
58951 }
58952
58953- atomic_inc(&osb->alloc_stats.moves);
58954+ atomic_inc_unchecked(&osb->alloc_stats.moves);
58955
58956 bail:
58957 if (handle)
58958diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
58959index 3a90347..c40bef8 100644
58960--- a/fs/ocfs2/ocfs2.h
58961+++ b/fs/ocfs2/ocfs2.h
58962@@ -235,11 +235,11 @@ enum ocfs2_vol_state
58963
58964 struct ocfs2_alloc_stats
58965 {
58966- atomic_t moves;
58967- atomic_t local_data;
58968- atomic_t bitmap_data;
58969- atomic_t bg_allocs;
58970- atomic_t bg_extends;
58971+ atomic_unchecked_t moves;
58972+ atomic_unchecked_t local_data;
58973+ atomic_unchecked_t bitmap_data;
58974+ atomic_unchecked_t bg_allocs;
58975+ atomic_unchecked_t bg_extends;
58976 };
58977
58978 enum ocfs2_local_alloc_state
58979diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
58980index 5397c07..54afc55 100644
58981--- a/fs/ocfs2/suballoc.c
58982+++ b/fs/ocfs2/suballoc.c
58983@@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
58984 mlog_errno(status);
58985 goto bail;
58986 }
58987- atomic_inc(&osb->alloc_stats.bg_extends);
58988+ atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
58989
58990 /* You should never ask for this much metadata */
58991 BUG_ON(bits_wanted >
58992@@ -2000,7 +2000,7 @@ int ocfs2_claim_metadata(handle_t *handle,
58993 mlog_errno(status);
58994 goto bail;
58995 }
58996- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
58997+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
58998
58999 *suballoc_loc = res.sr_bg_blkno;
59000 *suballoc_bit_start = res.sr_bit_offset;
59001@@ -2164,7 +2164,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
59002 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
59003 res->sr_bits);
59004
59005- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
59006+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
59007
59008 BUG_ON(res->sr_bits != 1);
59009
59010@@ -2206,7 +2206,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
59011 mlog_errno(status);
59012 goto bail;
59013 }
59014- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
59015+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
59016
59017 BUG_ON(res.sr_bits != 1);
59018
59019@@ -2310,7 +2310,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
59020 cluster_start,
59021 num_clusters);
59022 if (!status)
59023- atomic_inc(&osb->alloc_stats.local_data);
59024+ atomic_inc_unchecked(&osb->alloc_stats.local_data);
59025 } else {
59026 if (min_clusters > (osb->bitmap_cpg - 1)) {
59027 /* The only paths asking for contiguousness
59028@@ -2336,7 +2336,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
59029 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
59030 res.sr_bg_blkno,
59031 res.sr_bit_offset);
59032- atomic_inc(&osb->alloc_stats.bitmap_data);
59033+ atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
59034 *num_clusters = res.sr_bits;
59035 }
59036 }
59037diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
59038index d4e81e4..ad89f5f 100644
59039--- a/fs/ocfs2/super.c
59040+++ b/fs/ocfs2/super.c
59041@@ -300,11 +300,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
59042 "%10s => GlobalAllocs: %d LocalAllocs: %d "
59043 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
59044 "Stats",
59045- atomic_read(&osb->alloc_stats.bitmap_data),
59046- atomic_read(&osb->alloc_stats.local_data),
59047- atomic_read(&osb->alloc_stats.bg_allocs),
59048- atomic_read(&osb->alloc_stats.moves),
59049- atomic_read(&osb->alloc_stats.bg_extends));
59050+ atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
59051+ atomic_read_unchecked(&osb->alloc_stats.local_data),
59052+ atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
59053+ atomic_read_unchecked(&osb->alloc_stats.moves),
59054+ atomic_read_unchecked(&osb->alloc_stats.bg_extends));
59055
59056 out += snprintf(buf + out, len - out,
59057 "%10s => State: %u Descriptor: %llu Size: %u bits "
59058@@ -2121,11 +2121,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
59059 spin_lock_init(&osb->osb_xattr_lock);
59060 ocfs2_init_steal_slots(osb);
59061
59062- atomic_set(&osb->alloc_stats.moves, 0);
59063- atomic_set(&osb->alloc_stats.local_data, 0);
59064- atomic_set(&osb->alloc_stats.bitmap_data, 0);
59065- atomic_set(&osb->alloc_stats.bg_allocs, 0);
59066- atomic_set(&osb->alloc_stats.bg_extends, 0);
59067+ atomic_set_unchecked(&osb->alloc_stats.moves, 0);
59068+ atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
59069+ atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
59070+ atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
59071+ atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
59072
59073 /* Copy the blockcheck stats from the superblock probe */
59074 osb->osb_ecc_stats = *stats;
59075diff --git a/fs/open.c b/fs/open.c
59076index d420331..2dbb3fd 100644
59077--- a/fs/open.c
59078+++ b/fs/open.c
59079@@ -32,6 +32,8 @@
59080 #include <linux/dnotify.h>
59081 #include <linux/compat.h>
59082
59083+#define CREATE_TRACE_POINTS
59084+#include <trace/events/fs.h>
59085 #include "internal.h"
59086
59087 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
59088@@ -102,6 +104,8 @@ long vfs_truncate(struct path *path, loff_t length)
59089 error = locks_verify_truncate(inode, NULL, length);
59090 if (!error)
59091 error = security_path_truncate(path);
59092+ if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
59093+ error = -EACCES;
59094 if (!error)
59095 error = do_truncate(path->dentry, length, 0, NULL);
59096
59097@@ -186,6 +190,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
59098 error = locks_verify_truncate(inode, f.file, length);
59099 if (!error)
59100 error = security_path_truncate(&f.file->f_path);
59101+ if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
59102+ error = -EACCES;
59103 if (!error)
59104 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
59105 sb_end_write(inode->i_sb);
59106@@ -360,6 +366,9 @@ retry:
59107 if (__mnt_is_readonly(path.mnt))
59108 res = -EROFS;
59109
59110+ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
59111+ res = -EACCES;
59112+
59113 out_path_release:
59114 path_put(&path);
59115 if (retry_estale(res, lookup_flags)) {
59116@@ -391,6 +400,8 @@ retry:
59117 if (error)
59118 goto dput_and_out;
59119
59120+ gr_log_chdir(path.dentry, path.mnt);
59121+
59122 set_fs_pwd(current->fs, &path);
59123
59124 dput_and_out:
59125@@ -420,6 +431,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
59126 goto out_putf;
59127
59128 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
59129+
59130+ if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
59131+ error = -EPERM;
59132+
59133+ if (!error)
59134+ gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
59135+
59136 if (!error)
59137 set_fs_pwd(current->fs, &f.file->f_path);
59138 out_putf:
59139@@ -449,7 +467,13 @@ retry:
59140 if (error)
59141 goto dput_and_out;
59142
59143+ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
59144+ goto dput_and_out;
59145+
59146 set_fs_root(current->fs, &path);
59147+
59148+ gr_handle_chroot_chdir(&path);
59149+
59150 error = 0;
59151 dput_and_out:
59152 path_put(&path);
59153@@ -471,6 +495,16 @@ static int chmod_common(struct path *path, umode_t mode)
59154 if (error)
59155 return error;
59156 mutex_lock(&inode->i_mutex);
59157+
59158+ if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
59159+ error = -EACCES;
59160+ goto out_unlock;
59161+ }
59162+ if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
59163+ error = -EACCES;
59164+ goto out_unlock;
59165+ }
59166+
59167 error = security_path_chmod(path, mode);
59168 if (error)
59169 goto out_unlock;
59170@@ -530,6 +564,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
59171 uid = make_kuid(current_user_ns(), user);
59172 gid = make_kgid(current_user_ns(), group);
59173
59174+ if (!gr_acl_handle_chown(path->dentry, path->mnt))
59175+ return -EACCES;
59176+
59177 newattrs.ia_valid = ATTR_CTIME;
59178 if (user != (uid_t) -1) {
59179 if (!uid_valid(uid))
59180@@ -974,6 +1011,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
59181 } else {
59182 fsnotify_open(f);
59183 fd_install(fd, f);
59184+ trace_do_sys_open(tmp->name, flags, mode);
59185 }
59186 }
59187 putname(tmp);
59188diff --git a/fs/pipe.c b/fs/pipe.c
59189index d2c45e1..009fe1c 100644
59190--- a/fs/pipe.c
59191+++ b/fs/pipe.c
59192@@ -56,7 +56,7 @@ unsigned int pipe_min_size = PAGE_SIZE;
59193
59194 static void pipe_lock_nested(struct pipe_inode_info *pipe, int subclass)
59195 {
59196- if (pipe->files)
59197+ if (atomic_read(&pipe->files))
59198 mutex_lock_nested(&pipe->mutex, subclass);
59199 }
59200
59201@@ -71,7 +71,7 @@ EXPORT_SYMBOL(pipe_lock);
59202
59203 void pipe_unlock(struct pipe_inode_info *pipe)
59204 {
59205- if (pipe->files)
59206+ if (atomic_read(&pipe->files))
59207 mutex_unlock(&pipe->mutex);
59208 }
59209 EXPORT_SYMBOL(pipe_unlock);
59210@@ -449,9 +449,9 @@ redo:
59211 }
59212 if (bufs) /* More to do? */
59213 continue;
59214- if (!pipe->writers)
59215+ if (!atomic_read(&pipe->writers))
59216 break;
59217- if (!pipe->waiting_writers) {
59218+ if (!atomic_read(&pipe->waiting_writers)) {
59219 /* syscall merging: Usually we must not sleep
59220 * if O_NONBLOCK is set, or if we got some data.
59221 * But if a writer sleeps in kernel space, then
59222@@ -513,7 +513,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
59223 ret = 0;
59224 __pipe_lock(pipe);
59225
59226- if (!pipe->readers) {
59227+ if (!atomic_read(&pipe->readers)) {
59228 send_sig(SIGPIPE, current, 0);
59229 ret = -EPIPE;
59230 goto out;
59231@@ -562,7 +562,7 @@ redo1:
59232 for (;;) {
59233 int bufs;
59234
59235- if (!pipe->readers) {
59236+ if (!atomic_read(&pipe->readers)) {
59237 send_sig(SIGPIPE, current, 0);
59238 if (!ret)
59239 ret = -EPIPE;
59240@@ -653,9 +653,9 @@ redo2:
59241 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
59242 do_wakeup = 0;
59243 }
59244- pipe->waiting_writers++;
59245+ atomic_inc(&pipe->waiting_writers);
59246 pipe_wait(pipe);
59247- pipe->waiting_writers--;
59248+ atomic_dec(&pipe->waiting_writers);
59249 }
59250 out:
59251 __pipe_unlock(pipe);
59252@@ -709,7 +709,7 @@ pipe_poll(struct file *filp, poll_table *wait)
59253 mask = 0;
59254 if (filp->f_mode & FMODE_READ) {
59255 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
59256- if (!pipe->writers && filp->f_version != pipe->w_counter)
59257+ if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
59258 mask |= POLLHUP;
59259 }
59260
59261@@ -719,7 +719,7 @@ pipe_poll(struct file *filp, poll_table *wait)
59262 * Most Unices do not set POLLERR for FIFOs but on Linux they
59263 * behave exactly like pipes for poll().
59264 */
59265- if (!pipe->readers)
59266+ if (!atomic_read(&pipe->readers))
59267 mask |= POLLERR;
59268 }
59269
59270@@ -734,17 +734,17 @@ pipe_release(struct inode *inode, struct file *file)
59271
59272 __pipe_lock(pipe);
59273 if (file->f_mode & FMODE_READ)
59274- pipe->readers--;
59275+ atomic_dec(&pipe->readers);
59276 if (file->f_mode & FMODE_WRITE)
59277- pipe->writers--;
59278+ atomic_dec(&pipe->writers);
59279
59280- if (pipe->readers || pipe->writers) {
59281+ if (atomic_read(&pipe->readers) || atomic_read(&pipe->writers)) {
59282 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
59283 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
59284 kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT);
59285 }
59286 spin_lock(&inode->i_lock);
59287- if (!--pipe->files) {
59288+ if (atomic_dec_and_test(&pipe->files)) {
59289 inode->i_pipe = NULL;
59290 kill = 1;
59291 }
59292@@ -811,7 +811,7 @@ void free_pipe_info(struct pipe_inode_info *pipe)
59293 kfree(pipe);
59294 }
59295
59296-static struct vfsmount *pipe_mnt __read_mostly;
59297+struct vfsmount *pipe_mnt __read_mostly;
59298
59299 /*
59300 * pipefs_dname() is called from d_path().
59301@@ -841,8 +841,9 @@ static struct inode * get_pipe_inode(void)
59302 goto fail_iput;
59303
59304 inode->i_pipe = pipe;
59305- pipe->files = 2;
59306- pipe->readers = pipe->writers = 1;
59307+ atomic_set(&pipe->files, 2);
59308+ atomic_set(&pipe->readers, 1);
59309+ atomic_set(&pipe->writers, 1);
59310 inode->i_fop = &pipefifo_fops;
59311
59312 /*
59313@@ -1022,17 +1023,17 @@ static int fifo_open(struct inode *inode, struct file *filp)
59314 spin_lock(&inode->i_lock);
59315 if (inode->i_pipe) {
59316 pipe = inode->i_pipe;
59317- pipe->files++;
59318+ atomic_inc(&pipe->files);
59319 spin_unlock(&inode->i_lock);
59320 } else {
59321 spin_unlock(&inode->i_lock);
59322 pipe = alloc_pipe_info();
59323 if (!pipe)
59324 return -ENOMEM;
59325- pipe->files = 1;
59326+ atomic_set(&pipe->files, 1);
59327 spin_lock(&inode->i_lock);
59328 if (unlikely(inode->i_pipe)) {
59329- inode->i_pipe->files++;
59330+ atomic_inc(&inode->i_pipe->files);
59331 spin_unlock(&inode->i_lock);
59332 free_pipe_info(pipe);
59333 pipe = inode->i_pipe;
59334@@ -1057,10 +1058,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
59335 * opened, even when there is no process writing the FIFO.
59336 */
59337 pipe->r_counter++;
59338- if (pipe->readers++ == 0)
59339+ if (atomic_inc_return(&pipe->readers) == 1)
59340 wake_up_partner(pipe);
59341
59342- if (!is_pipe && !pipe->writers) {
59343+ if (!is_pipe && !atomic_read(&pipe->writers)) {
59344 if ((filp->f_flags & O_NONBLOCK)) {
59345 /* suppress POLLHUP until we have
59346 * seen a writer */
59347@@ -1079,14 +1080,14 @@ static int fifo_open(struct inode *inode, struct file *filp)
59348 * errno=ENXIO when there is no process reading the FIFO.
59349 */
59350 ret = -ENXIO;
59351- if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !pipe->readers)
59352+ if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
59353 goto err;
59354
59355 pipe->w_counter++;
59356- if (!pipe->writers++)
59357+ if (atomic_inc_return(&pipe->writers) == 1)
59358 wake_up_partner(pipe);
59359
59360- if (!is_pipe && !pipe->readers) {
59361+ if (!is_pipe && !atomic_read(&pipe->readers)) {
59362 if (wait_for_partner(pipe, &pipe->r_counter))
59363 goto err_wr;
59364 }
59365@@ -1100,11 +1101,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
59366 * the process can at least talk to itself.
59367 */
59368
59369- pipe->readers++;
59370- pipe->writers++;
59371+ atomic_inc(&pipe->readers);
59372+ atomic_inc(&pipe->writers);
59373 pipe->r_counter++;
59374 pipe->w_counter++;
59375- if (pipe->readers == 1 || pipe->writers == 1)
59376+ if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
59377 wake_up_partner(pipe);
59378 break;
59379
59380@@ -1118,20 +1119,20 @@ static int fifo_open(struct inode *inode, struct file *filp)
59381 return 0;
59382
59383 err_rd:
59384- if (!--pipe->readers)
59385+ if (atomic_dec_and_test(&pipe->readers))
59386 wake_up_interruptible(&pipe->wait);
59387 ret = -ERESTARTSYS;
59388 goto err;
59389
59390 err_wr:
59391- if (!--pipe->writers)
59392+ if (atomic_dec_and_test(&pipe->writers))
59393 wake_up_interruptible(&pipe->wait);
59394 ret = -ERESTARTSYS;
59395 goto err;
59396
59397 err:
59398 spin_lock(&inode->i_lock);
59399- if (!--pipe->files) {
59400+ if (atomic_dec_and_test(&pipe->files)) {
59401 inode->i_pipe = NULL;
59402 kill = 1;
59403 }
59404diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
59405index 15af622..0e9f4467 100644
59406--- a/fs/proc/Kconfig
59407+++ b/fs/proc/Kconfig
59408@@ -30,12 +30,12 @@ config PROC_FS
59409
59410 config PROC_KCORE
59411 bool "/proc/kcore support" if !ARM
59412- depends on PROC_FS && MMU
59413+ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
59414
59415 config PROC_VMCORE
59416 bool "/proc/vmcore support"
59417- depends on PROC_FS && CRASH_DUMP
59418- default y
59419+ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
59420+ default n
59421 help
59422 Exports the dump image of crashed kernel in ELF format.
59423
59424@@ -59,8 +59,8 @@ config PROC_SYSCTL
59425 limited in memory.
59426
59427 config PROC_PAGE_MONITOR
59428- default y
59429- depends on PROC_FS && MMU
59430+ default n
59431+ depends on PROC_FS && MMU && !GRKERNSEC
59432 bool "Enable /proc page monitoring" if EXPERT
59433 help
59434 Various /proc files exist to monitor process memory utilization:
59435diff --git a/fs/proc/array.c b/fs/proc/array.c
59436index cbd0f1b..adec3f0 100644
59437--- a/fs/proc/array.c
59438+++ b/fs/proc/array.c
59439@@ -60,6 +60,7 @@
59440 #include <linux/tty.h>
59441 #include <linux/string.h>
59442 #include <linux/mman.h>
59443+#include <linux/grsecurity.h>
59444 #include <linux/proc_fs.h>
59445 #include <linux/ioport.h>
59446 #include <linux/uaccess.h>
59447@@ -363,6 +364,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
59448 seq_putc(m, '\n');
59449 }
59450
59451+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
59452+static inline void task_pax(struct seq_file *m, struct task_struct *p)
59453+{
59454+ if (p->mm)
59455+ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
59456+ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
59457+ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
59458+ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
59459+ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
59460+ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
59461+ else
59462+ seq_printf(m, "PaX:\t-----\n");
59463+}
59464+#endif
59465+
59466 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
59467 struct pid *pid, struct task_struct *task)
59468 {
59469@@ -381,9 +397,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
59470 task_cpus_allowed(m, task);
59471 cpuset_task_status_allowed(m, task);
59472 task_context_switch_counts(m, task);
59473+
59474+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
59475+ task_pax(m, task);
59476+#endif
59477+
59478+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
59479+ task_grsec_rbac(m, task);
59480+#endif
59481+
59482 return 0;
59483 }
59484
59485+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59486+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
59487+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
59488+ _mm->pax_flags & MF_PAX_SEGMEXEC))
59489+#endif
59490+
59491 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
59492 struct pid *pid, struct task_struct *task, int whole)
59493 {
59494@@ -405,6 +436,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
59495 char tcomm[sizeof(task->comm)];
59496 unsigned long flags;
59497
59498+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59499+ if (current->exec_id != m->exec_id) {
59500+ gr_log_badprocpid("stat");
59501+ return 0;
59502+ }
59503+#endif
59504+
59505 state = *get_task_state(task);
59506 vsize = eip = esp = 0;
59507 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
59508@@ -476,6 +514,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
59509 gtime = task_gtime(task);
59510 }
59511
59512+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59513+ if (PAX_RAND_FLAGS(mm)) {
59514+ eip = 0;
59515+ esp = 0;
59516+ wchan = 0;
59517+ }
59518+#endif
59519+#ifdef CONFIG_GRKERNSEC_HIDESYM
59520+ wchan = 0;
59521+ eip =0;
59522+ esp =0;
59523+#endif
59524+
59525 /* scale priority and nice values from timeslices to -20..20 */
59526 /* to make it look like a "normal" Unix priority/nice value */
59527 priority = task_prio(task);
59528@@ -512,9 +563,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
59529 seq_put_decimal_ull(m, ' ', vsize);
59530 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
59531 seq_put_decimal_ull(m, ' ', rsslim);
59532+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59533+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
59534+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
59535+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
59536+#else
59537 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
59538 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
59539 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
59540+#endif
59541 seq_put_decimal_ull(m, ' ', esp);
59542 seq_put_decimal_ull(m, ' ', eip);
59543 /* The signal information here is obsolete.
59544@@ -536,7 +593,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
59545 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
59546 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
59547
59548- if (mm && permitted) {
59549+ if (mm && permitted
59550+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59551+ && !PAX_RAND_FLAGS(mm)
59552+#endif
59553+ ) {
59554 seq_put_decimal_ull(m, ' ', mm->start_data);
59555 seq_put_decimal_ull(m, ' ', mm->end_data);
59556 seq_put_decimal_ull(m, ' ', mm->start_brk);
59557@@ -574,8 +635,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
59558 struct pid *pid, struct task_struct *task)
59559 {
59560 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
59561- struct mm_struct *mm = get_task_mm(task);
59562+ struct mm_struct *mm;
59563
59564+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59565+ if (current->exec_id != m->exec_id) {
59566+ gr_log_badprocpid("statm");
59567+ return 0;
59568+ }
59569+#endif
59570+ mm = get_task_mm(task);
59571 if (mm) {
59572 size = task_statm(mm, &shared, &text, &data, &resident);
59573 mmput(mm);
59574@@ -598,6 +666,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
59575 return 0;
59576 }
59577
59578+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
59579+int proc_pid_ipaddr(struct task_struct *task, char *buffer)
59580+{
59581+ return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
59582+}
59583+#endif
59584+
59585 #ifdef CONFIG_CHECKPOINT_RESTORE
59586 static struct pid *
59587 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
59588diff --git a/fs/proc/base.c b/fs/proc/base.c
59589index 1485e38..8ad4236 100644
59590--- a/fs/proc/base.c
59591+++ b/fs/proc/base.c
59592@@ -113,6 +113,14 @@ struct pid_entry {
59593 union proc_op op;
59594 };
59595
59596+struct getdents_callback {
59597+ struct linux_dirent __user * current_dir;
59598+ struct linux_dirent __user * previous;
59599+ struct file * file;
59600+ int count;
59601+ int error;
59602+};
59603+
59604 #define NOD(NAME, MODE, IOP, FOP, OP) { \
59605 .name = (NAME), \
59606 .len = sizeof(NAME) - 1, \
59607@@ -210,6 +218,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
59608 if (!mm->arg_end)
59609 goto out_mm; /* Shh! No looking before we're done */
59610
59611+ if (gr_acl_handle_procpidmem(task))
59612+ goto out_mm;
59613+
59614 len = mm->arg_end - mm->arg_start;
59615
59616 if (len > PAGE_SIZE)
59617@@ -237,12 +248,28 @@ out:
59618 return res;
59619 }
59620
59621+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59622+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
59623+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
59624+ _mm->pax_flags & MF_PAX_SEGMEXEC))
59625+#endif
59626+
59627 static int proc_pid_auxv(struct task_struct *task, char *buffer)
59628 {
59629 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
59630 int res = PTR_ERR(mm);
59631 if (mm && !IS_ERR(mm)) {
59632 unsigned int nwords = 0;
59633+
59634+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59635+ /* allow if we're currently ptracing this task */
59636+ if (PAX_RAND_FLAGS(mm) &&
59637+ (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
59638+ mmput(mm);
59639+ return 0;
59640+ }
59641+#endif
59642+
59643 do {
59644 nwords += 2;
59645 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
59646@@ -256,7 +283,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
59647 }
59648
59649
59650-#ifdef CONFIG_KALLSYMS
59651+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
59652 /*
59653 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
59654 * Returns the resolved symbol. If that fails, simply return the address.
59655@@ -295,7 +322,7 @@ static void unlock_trace(struct task_struct *task)
59656 mutex_unlock(&task->signal->cred_guard_mutex);
59657 }
59658
59659-#ifdef CONFIG_STACKTRACE
59660+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
59661
59662 #define MAX_STACK_TRACE_DEPTH 64
59663
59664@@ -518,7 +545,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
59665 return count;
59666 }
59667
59668-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
59669+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
59670 static int proc_pid_syscall(struct task_struct *task, char *buffer)
59671 {
59672 long nr;
59673@@ -547,7 +574,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
59674 /************************************************************************/
59675
59676 /* permission checks */
59677-static int proc_fd_access_allowed(struct inode *inode)
59678+static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
59679 {
59680 struct task_struct *task;
59681 int allowed = 0;
59682@@ -557,7 +584,10 @@ static int proc_fd_access_allowed(struct inode *inode)
59683 */
59684 task = get_proc_task(inode);
59685 if (task) {
59686- allowed = ptrace_may_access(task, PTRACE_MODE_READ);
59687+ if (log)
59688+ allowed = ptrace_may_access(task, PTRACE_MODE_READ);
59689+ else
59690+ allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
59691 put_task_struct(task);
59692 }
59693 return allowed;
59694@@ -588,10 +618,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
59695 struct task_struct *task,
59696 int hide_pid_min)
59697 {
59698+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
59699+ return false;
59700+
59701+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59702+ rcu_read_lock();
59703+ {
59704+ const struct cred *tmpcred = current_cred();
59705+ const struct cred *cred = __task_cred(task);
59706+
59707+ if (uid_eq(tmpcred->uid, GLOBAL_ROOT_UID) || uid_eq(tmpcred->uid, cred->uid)
59708+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
59709+ || in_group_p(grsec_proc_gid)
59710+#endif
59711+ ) {
59712+ rcu_read_unlock();
59713+ return true;
59714+ }
59715+ }
59716+ rcu_read_unlock();
59717+
59718+ if (!pid->hide_pid)
59719+ return false;
59720+#endif
59721+
59722 if (pid->hide_pid < hide_pid_min)
59723 return true;
59724 if (in_group_p(pid->pid_gid))
59725 return true;
59726+
59727 return ptrace_may_access(task, PTRACE_MODE_READ);
59728 }
59729
59730@@ -609,7 +664,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
59731 put_task_struct(task);
59732
59733 if (!has_perms) {
59734+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59735+ {
59736+#else
59737 if (pid->hide_pid == 2) {
59738+#endif
59739 /*
59740 * Let's make getdents(), stat(), and open()
59741 * consistent with each other. If a process
59742@@ -707,6 +766,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
59743 if (!task)
59744 return -ESRCH;
59745
59746+ if (gr_acl_handle_procpidmem(task)) {
59747+ put_task_struct(task);
59748+ return -EPERM;
59749+ }
59750+
59751 mm = mm_access(task, mode);
59752 put_task_struct(task);
59753
59754@@ -722,6 +786,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
59755
59756 file->private_data = mm;
59757
59758+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59759+ file->f_version = current->exec_id;
59760+#endif
59761+
59762 return 0;
59763 }
59764
59765@@ -743,6 +811,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
59766 ssize_t copied;
59767 char *page;
59768
59769+#ifdef CONFIG_GRKERNSEC
59770+ if (write)
59771+ return -EPERM;
59772+#endif
59773+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59774+ if (file->f_version != current->exec_id) {
59775+ gr_log_badprocpid("mem");
59776+ return 0;
59777+ }
59778+#endif
59779+
59780 if (!mm)
59781 return 0;
59782
59783@@ -755,7 +834,7 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
59784 goto free;
59785
59786 while (count > 0) {
59787- int this_len = min_t(int, count, PAGE_SIZE);
59788+ ssize_t this_len = min_t(ssize_t, count, PAGE_SIZE);
59789
59790 if (write && copy_from_user(page, buf, this_len)) {
59791 copied = -EFAULT;
59792@@ -847,6 +926,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
59793 if (!mm)
59794 return 0;
59795
59796+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59797+ if (file->f_version != current->exec_id) {
59798+ gr_log_badprocpid("environ");
59799+ return 0;
59800+ }
59801+#endif
59802+
59803 page = (char *)__get_free_page(GFP_TEMPORARY);
59804 if (!page)
59805 return -ENOMEM;
59806@@ -856,7 +942,7 @@ static ssize_t environ_read(struct file *file, char __user *buf,
59807 goto free;
59808 while (count > 0) {
59809 size_t this_len, max_len;
59810- int retval;
59811+ ssize_t retval;
59812
59813 if (src >= (mm->env_end - mm->env_start))
59814 break;
59815@@ -1461,7 +1547,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
59816 int error = -EACCES;
59817
59818 /* Are we allowed to snoop on the tasks file descriptors? */
59819- if (!proc_fd_access_allowed(inode))
59820+ if (!proc_fd_access_allowed(inode, 0))
59821 goto out;
59822
59823 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
59824@@ -1505,8 +1591,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
59825 struct path path;
59826
59827 /* Are we allowed to snoop on the tasks file descriptors? */
59828- if (!proc_fd_access_allowed(inode))
59829- goto out;
59830+ /* logging this is needed for learning on chromium to work properly,
59831+ but we don't want to flood the logs from 'ps' which does a readlink
59832+ on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
59833+ CAP_SYS_PTRACE as it's not necessary for its basic functionality
59834+ */
59835+ if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
59836+ if (!proc_fd_access_allowed(inode,0))
59837+ goto out;
59838+ } else {
59839+ if (!proc_fd_access_allowed(inode,1))
59840+ goto out;
59841+ }
59842
59843 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
59844 if (error)
59845@@ -1556,7 +1652,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
59846 rcu_read_lock();
59847 cred = __task_cred(task);
59848 inode->i_uid = cred->euid;
59849+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
59850+ inode->i_gid = grsec_proc_gid;
59851+#else
59852 inode->i_gid = cred->egid;
59853+#endif
59854 rcu_read_unlock();
59855 }
59856 security_task_to_inode(task, inode);
59857@@ -1592,10 +1692,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
59858 return -ENOENT;
59859 }
59860 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
59861+#ifdef CONFIG_GRKERNSEC_PROC_USER
59862+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
59863+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59864+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
59865+#endif
59866 task_dumpable(task)) {
59867 cred = __task_cred(task);
59868 stat->uid = cred->euid;
59869+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
59870+ stat->gid = grsec_proc_gid;
59871+#else
59872 stat->gid = cred->egid;
59873+#endif
59874 }
59875 }
59876 rcu_read_unlock();
59877@@ -1633,11 +1742,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
59878
59879 if (task) {
59880 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
59881+#ifdef CONFIG_GRKERNSEC_PROC_USER
59882+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
59883+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59884+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
59885+#endif
59886 task_dumpable(task)) {
59887 rcu_read_lock();
59888 cred = __task_cred(task);
59889 inode->i_uid = cred->euid;
59890+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
59891+ inode->i_gid = grsec_proc_gid;
59892+#else
59893 inode->i_gid = cred->egid;
59894+#endif
59895 rcu_read_unlock();
59896 } else {
59897 inode->i_uid = GLOBAL_ROOT_UID;
59898@@ -2166,6 +2284,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
59899 if (!task)
59900 goto out_no_task;
59901
59902+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
59903+ goto out;
59904+
59905 /*
59906 * Yes, it does not scale. And it should not. Don't add
59907 * new entries into /proc/<tgid>/ without very good reasons.
59908@@ -2196,6 +2317,9 @@ static int proc_pident_readdir(struct file *file, struct dir_context *ctx,
59909 if (!task)
59910 return -ENOENT;
59911
59912+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
59913+ goto out;
59914+
59915 if (!dir_emit_dots(file, ctx))
59916 goto out;
59917
59918@@ -2585,7 +2709,7 @@ static const struct pid_entry tgid_base_stuff[] = {
59919 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
59920 #endif
59921 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
59922-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
59923+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
59924 INF("syscall", S_IRUGO, proc_pid_syscall),
59925 #endif
59926 INF("cmdline", S_IRUGO, proc_pid_cmdline),
59927@@ -2610,10 +2734,10 @@ static const struct pid_entry tgid_base_stuff[] = {
59928 #ifdef CONFIG_SECURITY
59929 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
59930 #endif
59931-#ifdef CONFIG_KALLSYMS
59932+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
59933 INF("wchan", S_IRUGO, proc_pid_wchan),
59934 #endif
59935-#ifdef CONFIG_STACKTRACE
59936+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
59937 ONE("stack", S_IRUGO, proc_pid_stack),
59938 #endif
59939 #ifdef CONFIG_SCHEDSTATS
59940@@ -2647,6 +2771,9 @@ static const struct pid_entry tgid_base_stuff[] = {
59941 #ifdef CONFIG_HARDWALL
59942 INF("hardwall", S_IRUGO, proc_pid_hardwall),
59943 #endif
59944+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
59945+ INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
59946+#endif
59947 #ifdef CONFIG_USER_NS
59948 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
59949 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
59950@@ -2777,7 +2904,14 @@ static int proc_pid_instantiate(struct inode *dir,
59951 if (!inode)
59952 goto out;
59953
59954+#ifdef CONFIG_GRKERNSEC_PROC_USER
59955+ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
59956+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59957+ inode->i_gid = grsec_proc_gid;
59958+ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
59959+#else
59960 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
59961+#endif
59962 inode->i_op = &proc_tgid_base_inode_operations;
59963 inode->i_fop = &proc_tgid_base_operations;
59964 inode->i_flags|=S_IMMUTABLE;
59965@@ -2815,7 +2949,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
59966 if (!task)
59967 goto out;
59968
59969+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
59970+ goto out_put_task;
59971+
59972 result = proc_pid_instantiate(dir, dentry, task, NULL);
59973+out_put_task:
59974 put_task_struct(task);
59975 out:
59976 return ERR_PTR(result);
59977@@ -2921,7 +3059,7 @@ static const struct pid_entry tid_base_stuff[] = {
59978 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
59979 #endif
59980 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
59981-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
59982+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
59983 INF("syscall", S_IRUGO, proc_pid_syscall),
59984 #endif
59985 INF("cmdline", S_IRUGO, proc_pid_cmdline),
59986@@ -2948,10 +3086,10 @@ static const struct pid_entry tid_base_stuff[] = {
59987 #ifdef CONFIG_SECURITY
59988 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
59989 #endif
59990-#ifdef CONFIG_KALLSYMS
59991+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
59992 INF("wchan", S_IRUGO, proc_pid_wchan),
59993 #endif
59994-#ifdef CONFIG_STACKTRACE
59995+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
59996 ONE("stack", S_IRUGO, proc_pid_stack),
59997 #endif
59998 #ifdef CONFIG_SCHEDSTATS
59999diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
60000index 82676e3..5f8518a 100644
60001--- a/fs/proc/cmdline.c
60002+++ b/fs/proc/cmdline.c
60003@@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
60004
60005 static int __init proc_cmdline_init(void)
60006 {
60007+#ifdef CONFIG_GRKERNSEC_PROC_ADD
60008+ proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
60009+#else
60010 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
60011+#endif
60012 return 0;
60013 }
60014 module_init(proc_cmdline_init);
60015diff --git a/fs/proc/devices.c b/fs/proc/devices.c
60016index b143471..bb105e5 100644
60017--- a/fs/proc/devices.c
60018+++ b/fs/proc/devices.c
60019@@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
60020
60021 static int __init proc_devices_init(void)
60022 {
60023+#ifdef CONFIG_GRKERNSEC_PROC_ADD
60024+ proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
60025+#else
60026 proc_create("devices", 0, NULL, &proc_devinfo_operations);
60027+#endif
60028 return 0;
60029 }
60030 module_init(proc_devices_init);
60031diff --git a/fs/proc/fd.c b/fs/proc/fd.c
60032index 985ea88..d118a0a 100644
60033--- a/fs/proc/fd.c
60034+++ b/fs/proc/fd.c
60035@@ -25,7 +25,8 @@ static int seq_show(struct seq_file *m, void *v)
60036 if (!task)
60037 return -ENOENT;
60038
60039- files = get_files_struct(task);
60040+ if (!gr_acl_handle_procpidmem(task))
60041+ files = get_files_struct(task);
60042 put_task_struct(task);
60043
60044 if (files) {
60045@@ -283,11 +284,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
60046 */
60047 int proc_fd_permission(struct inode *inode, int mask)
60048 {
60049+ struct task_struct *task;
60050 int rv = generic_permission(inode, mask);
60051- if (rv == 0)
60052- return 0;
60053+
60054 if (task_tgid(current) == proc_pid(inode))
60055 rv = 0;
60056+
60057+ task = get_proc_task(inode);
60058+ if (task == NULL)
60059+ return rv;
60060+
60061+ if (gr_acl_handle_procpidmem(task))
60062+ rv = -EACCES;
60063+
60064+ put_task_struct(task);
60065+
60066 return rv;
60067 }
60068
60069diff --git a/fs/proc/inode.c b/fs/proc/inode.c
60070index 8eaa1ba..cc6ff42 100644
60071--- a/fs/proc/inode.c
60072+++ b/fs/proc/inode.c
60073@@ -23,11 +23,17 @@
60074 #include <linux/slab.h>
60075 #include <linux/mount.h>
60076 #include <linux/magic.h>
60077+#include <linux/grsecurity.h>
60078
60079 #include <asm/uaccess.h>
60080
60081 #include "internal.h"
60082
60083+#ifdef CONFIG_PROC_SYSCTL
60084+extern const struct inode_operations proc_sys_inode_operations;
60085+extern const struct inode_operations proc_sys_dir_operations;
60086+#endif
60087+
60088 static void proc_evict_inode(struct inode *inode)
60089 {
60090 struct proc_dir_entry *de;
60091@@ -55,6 +61,13 @@ static void proc_evict_inode(struct inode *inode)
60092 ns = PROC_I(inode)->ns.ns;
60093 if (ns_ops && ns)
60094 ns_ops->put(ns);
60095+
60096+#ifdef CONFIG_PROC_SYSCTL
60097+ if (inode->i_op == &proc_sys_inode_operations ||
60098+ inode->i_op == &proc_sys_dir_operations)
60099+ gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
60100+#endif
60101+
60102 }
60103
60104 static struct kmem_cache * proc_inode_cachep;
60105@@ -405,7 +418,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
60106 if (de->mode) {
60107 inode->i_mode = de->mode;
60108 inode->i_uid = de->uid;
60109+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
60110+ inode->i_gid = grsec_proc_gid;
60111+#else
60112 inode->i_gid = de->gid;
60113+#endif
60114 }
60115 if (de->size)
60116 inode->i_size = de->size;
60117diff --git a/fs/proc/internal.h b/fs/proc/internal.h
60118index 651d09a..60c73ae 100644
60119--- a/fs/proc/internal.h
60120+++ b/fs/proc/internal.h
60121@@ -155,6 +155,9 @@ extern int proc_pid_status(struct seq_file *, struct pid_namespace *,
60122 struct pid *, struct task_struct *);
60123 extern int proc_pid_statm(struct seq_file *, struct pid_namespace *,
60124 struct pid *, struct task_struct *);
60125+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
60126+extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
60127+#endif
60128
60129 /*
60130 * base.c
60131diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
60132index 06ea155..9a798c7 100644
60133--- a/fs/proc/kcore.c
60134+++ b/fs/proc/kcore.c
60135@@ -484,9 +484,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
60136 * the addresses in the elf_phdr on our list.
60137 */
60138 start = kc_offset_to_vaddr(*fpos - elf_buflen);
60139- if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
60140+ tsz = PAGE_SIZE - (start & ~PAGE_MASK);
60141+ if (tsz > buflen)
60142 tsz = buflen;
60143-
60144+
60145 while (buflen) {
60146 struct kcore_list *m;
60147
60148@@ -515,20 +516,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
60149 kfree(elf_buf);
60150 } else {
60151 if (kern_addr_valid(start)) {
60152- unsigned long n;
60153+ char *elf_buf;
60154+ mm_segment_t oldfs;
60155
60156- n = copy_to_user(buffer, (char *)start, tsz);
60157- /*
60158- * We cannot distinguish between fault on source
60159- * and fault on destination. When this happens
60160- * we clear too and hope it will trigger the
60161- * EFAULT again.
60162- */
60163- if (n) {
60164- if (clear_user(buffer + tsz - n,
60165- n))
60166+ elf_buf = kmalloc(tsz, GFP_KERNEL);
60167+ if (!elf_buf)
60168+ return -ENOMEM;
60169+ oldfs = get_fs();
60170+ set_fs(KERNEL_DS);
60171+ if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
60172+ set_fs(oldfs);
60173+ if (copy_to_user(buffer, elf_buf, tsz)) {
60174+ kfree(elf_buf);
60175 return -EFAULT;
60176+ }
60177 }
60178+ set_fs(oldfs);
60179+ kfree(elf_buf);
60180 } else {
60181 if (clear_user(buffer, tsz))
60182 return -EFAULT;
60183@@ -548,6 +552,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
60184
60185 static int open_kcore(struct inode *inode, struct file *filp)
60186 {
60187+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
60188+ return -EPERM;
60189+#endif
60190 if (!capable(CAP_SYS_RAWIO))
60191 return -EPERM;
60192 if (kcore_need_update)
60193diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
60194index 59d85d6..ac6fc05 100644
60195--- a/fs/proc/meminfo.c
60196+++ b/fs/proc/meminfo.c
60197@@ -153,7 +153,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
60198 vmi.used >> 10,
60199 vmi.largest_chunk >> 10
60200 #ifdef CONFIG_MEMORY_FAILURE
60201- ,atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10)
60202+ ,atomic_long_read_unchecked(&num_poisoned_pages) << (PAGE_SHIFT - 10)
60203 #endif
60204 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
60205 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
60206diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
60207index ccfd99b..1b7e255 100644
60208--- a/fs/proc/nommu.c
60209+++ b/fs/proc/nommu.c
60210@@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
60211 if (len < 1)
60212 len = 1;
60213 seq_printf(m, "%*c", len, ' ');
60214- seq_path(m, &file->f_path, "");
60215+ seq_path(m, &file->f_path, "\n\\");
60216 }
60217
60218 seq_putc(m, '\n');
60219diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
60220index 4677bb7..408e936 100644
60221--- a/fs/proc/proc_net.c
60222+++ b/fs/proc/proc_net.c
60223@@ -23,6 +23,7 @@
60224 #include <linux/nsproxy.h>
60225 #include <net/net_namespace.h>
60226 #include <linux/seq_file.h>
60227+#include <linux/grsecurity.h>
60228
60229 #include "internal.h"
60230
60231@@ -109,6 +110,17 @@ static struct net *get_proc_task_net(struct inode *dir)
60232 struct task_struct *task;
60233 struct nsproxy *ns;
60234 struct net *net = NULL;
60235+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
60236+ const struct cred *cred = current_cred();
60237+#endif
60238+
60239+#ifdef CONFIG_GRKERNSEC_PROC_USER
60240+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID))
60241+ return net;
60242+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
60243+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID) && !in_group_p(grsec_proc_gid))
60244+ return net;
60245+#endif
60246
60247 rcu_read_lock();
60248 task = pid_task(proc_pid(dir), PIDTYPE_PID);
60249diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
60250index 7129046..6914844 100644
60251--- a/fs/proc/proc_sysctl.c
60252+++ b/fs/proc/proc_sysctl.c
60253@@ -11,13 +11,21 @@
60254 #include <linux/namei.h>
60255 #include <linux/mm.h>
60256 #include <linux/module.h>
60257+#include <linux/nsproxy.h>
60258+#ifdef CONFIG_GRKERNSEC
60259+#include <net/net_namespace.h>
60260+#endif
60261 #include "internal.h"
60262
60263+extern int gr_handle_chroot_sysctl(const int op);
60264+extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
60265+ const int op);
60266+
60267 static const struct dentry_operations proc_sys_dentry_operations;
60268 static const struct file_operations proc_sys_file_operations;
60269-static const struct inode_operations proc_sys_inode_operations;
60270+const struct inode_operations proc_sys_inode_operations;
60271 static const struct file_operations proc_sys_dir_file_operations;
60272-static const struct inode_operations proc_sys_dir_operations;
60273+const struct inode_operations proc_sys_dir_operations;
60274
60275 void proc_sys_poll_notify(struct ctl_table_poll *poll)
60276 {
60277@@ -467,6 +475,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
60278
60279 err = NULL;
60280 d_set_d_op(dentry, &proc_sys_dentry_operations);
60281+
60282+ gr_handle_proc_create(dentry, inode);
60283+
60284 d_add(dentry, inode);
60285
60286 out:
60287@@ -482,6 +493,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
60288 struct inode *inode = file_inode(filp);
60289 struct ctl_table_header *head = grab_header(inode);
60290 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
60291+ int op = write ? MAY_WRITE : MAY_READ;
60292 ssize_t error;
60293 size_t res;
60294
60295@@ -493,7 +505,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
60296 * and won't be until we finish.
60297 */
60298 error = -EPERM;
60299- if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
60300+ if (sysctl_perm(head, table, op))
60301 goto out;
60302
60303 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
60304@@ -501,6 +513,27 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
60305 if (!table->proc_handler)
60306 goto out;
60307
60308+#ifdef CONFIG_GRKERNSEC
60309+ error = -EPERM;
60310+ if (gr_handle_chroot_sysctl(op))
60311+ goto out;
60312+ dget(filp->f_path.dentry);
60313+ if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
60314+ dput(filp->f_path.dentry);
60315+ goto out;
60316+ }
60317+ dput(filp->f_path.dentry);
60318+ if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
60319+ goto out;
60320+ if (write) {
60321+ if (current->nsproxy->net_ns != table->extra2) {
60322+ if (!capable(CAP_SYS_ADMIN))
60323+ goto out;
60324+ } else if (!ns_capable(current->nsproxy->net_ns->user_ns, CAP_NET_ADMIN))
60325+ goto out;
60326+ }
60327+#endif
60328+
60329 /* careful: calling conventions are nasty here */
60330 res = count;
60331 error = table->proc_handler(table, write, buf, &res, ppos);
60332@@ -598,6 +631,9 @@ static bool proc_sys_fill_cache(struct file *file,
60333 return false;
60334 } else {
60335 d_set_d_op(child, &proc_sys_dentry_operations);
60336+
60337+ gr_handle_proc_create(child, inode);
60338+
60339 d_add(child, inode);
60340 }
60341 } else {
60342@@ -641,6 +677,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
60343 if ((*pos)++ < ctx->pos)
60344 return true;
60345
60346+ if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
60347+ return 0;
60348+
60349 if (unlikely(S_ISLNK(table->mode)))
60350 res = proc_sys_link_fill_cache(file, ctx, head, table);
60351 else
60352@@ -734,6 +773,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
60353 if (IS_ERR(head))
60354 return PTR_ERR(head);
60355
60356+ if (table && !gr_acl_handle_hidden_file(dentry, mnt))
60357+ return -ENOENT;
60358+
60359 generic_fillattr(inode, stat);
60360 if (table)
60361 stat->mode = (stat->mode & S_IFMT) | table->mode;
60362@@ -756,13 +798,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
60363 .llseek = generic_file_llseek,
60364 };
60365
60366-static const struct inode_operations proc_sys_inode_operations = {
60367+const struct inode_operations proc_sys_inode_operations = {
60368 .permission = proc_sys_permission,
60369 .setattr = proc_sys_setattr,
60370 .getattr = proc_sys_getattr,
60371 };
60372
60373-static const struct inode_operations proc_sys_dir_operations = {
60374+const struct inode_operations proc_sys_dir_operations = {
60375 .lookup = proc_sys_lookup,
60376 .permission = proc_sys_permission,
60377 .setattr = proc_sys_setattr,
60378@@ -839,7 +881,7 @@ static struct ctl_dir *find_subdir(struct ctl_dir *dir,
60379 static struct ctl_dir *new_dir(struct ctl_table_set *set,
60380 const char *name, int namelen)
60381 {
60382- struct ctl_table *table;
60383+ ctl_table_no_const *table;
60384 struct ctl_dir *new;
60385 struct ctl_node *node;
60386 char *new_name;
60387@@ -851,7 +893,7 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
60388 return NULL;
60389
60390 node = (struct ctl_node *)(new + 1);
60391- table = (struct ctl_table *)(node + 1);
60392+ table = (ctl_table_no_const *)(node + 1);
60393 new_name = (char *)(table + 2);
60394 memcpy(new_name, name, namelen);
60395 new_name[namelen] = '\0';
60396@@ -1020,7 +1062,8 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
60397 static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table,
60398 struct ctl_table_root *link_root)
60399 {
60400- struct ctl_table *link_table, *entry, *link;
60401+ ctl_table_no_const *link_table, *link;
60402+ struct ctl_table *entry;
60403 struct ctl_table_header *links;
60404 struct ctl_node *node;
60405 char *link_name;
60406@@ -1043,7 +1086,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
60407 return NULL;
60408
60409 node = (struct ctl_node *)(links + 1);
60410- link_table = (struct ctl_table *)(node + nr_entries);
60411+ link_table = (ctl_table_no_const *)(node + nr_entries);
60412 link_name = (char *)&link_table[nr_entries + 1];
60413
60414 for (link = link_table, entry = table; entry->procname; link++, entry++) {
60415@@ -1291,8 +1334,8 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
60416 struct ctl_table_header ***subheader, struct ctl_table_set *set,
60417 struct ctl_table *table)
60418 {
60419- struct ctl_table *ctl_table_arg = NULL;
60420- struct ctl_table *entry, *files;
60421+ ctl_table_no_const *ctl_table_arg = NULL, *files = NULL;
60422+ struct ctl_table *entry;
60423 int nr_files = 0;
60424 int nr_dirs = 0;
60425 int err = -ENOMEM;
60426@@ -1304,10 +1347,9 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
60427 nr_files++;
60428 }
60429
60430- files = table;
60431 /* If there are mixed files and directories we need a new table */
60432 if (nr_dirs && nr_files) {
60433- struct ctl_table *new;
60434+ ctl_table_no_const *new;
60435 files = kzalloc(sizeof(struct ctl_table) * (nr_files + 1),
60436 GFP_KERNEL);
60437 if (!files)
60438@@ -1325,7 +1367,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
60439 /* Register everything except a directory full of subdirectories */
60440 if (nr_files || !nr_dirs) {
60441 struct ctl_table_header *header;
60442- header = __register_sysctl_table(set, path, files);
60443+ header = __register_sysctl_table(set, path, files ? files : table);
60444 if (!header) {
60445 kfree(ctl_table_arg);
60446 goto out;
60447diff --git a/fs/proc/root.c b/fs/proc/root.c
60448index 87dbcbe..55e1b4d 100644
60449--- a/fs/proc/root.c
60450+++ b/fs/proc/root.c
60451@@ -186,7 +186,15 @@ void __init proc_root_init(void)
60452 #ifdef CONFIG_PROC_DEVICETREE
60453 proc_device_tree_init();
60454 #endif
60455+#ifdef CONFIG_GRKERNSEC_PROC_ADD
60456+#ifdef CONFIG_GRKERNSEC_PROC_USER
60457+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
60458+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
60459+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
60460+#endif
60461+#else
60462 proc_mkdir("bus", NULL);
60463+#endif
60464 proc_sys_init();
60465 }
60466
60467diff --git a/fs/proc/self.c b/fs/proc/self.c
60468index 6b6a993..807cccc 100644
60469--- a/fs/proc/self.c
60470+++ b/fs/proc/self.c
60471@@ -39,7 +39,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
60472 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
60473 void *cookie)
60474 {
60475- char *s = nd_get_link(nd);
60476+ const char *s = nd_get_link(nd);
60477 if (!IS_ERR(s))
60478 kfree(s);
60479 }
60480diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
60481index 390bdab..83c1e8a 100644
60482--- a/fs/proc/task_mmu.c
60483+++ b/fs/proc/task_mmu.c
60484@@ -12,12 +12,19 @@
60485 #include <linux/swap.h>
60486 #include <linux/swapops.h>
60487 #include <linux/mmu_notifier.h>
60488+#include <linux/grsecurity.h>
60489
60490 #include <asm/elf.h>
60491 #include <asm/uaccess.h>
60492 #include <asm/tlbflush.h>
60493 #include "internal.h"
60494
60495+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60496+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
60497+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
60498+ _mm->pax_flags & MF_PAX_SEGMEXEC))
60499+#endif
60500+
60501 void task_mem(struct seq_file *m, struct mm_struct *mm)
60502 {
60503 unsigned long data, text, lib, swap;
60504@@ -53,8 +60,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
60505 "VmExe:\t%8lu kB\n"
60506 "VmLib:\t%8lu kB\n"
60507 "VmPTE:\t%8lu kB\n"
60508- "VmSwap:\t%8lu kB\n",
60509- hiwater_vm << (PAGE_SHIFT-10),
60510+ "VmSwap:\t%8lu kB\n"
60511+
60512+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
60513+ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
60514+#endif
60515+
60516+ ,hiwater_vm << (PAGE_SHIFT-10),
60517 total_vm << (PAGE_SHIFT-10),
60518 mm->locked_vm << (PAGE_SHIFT-10),
60519 mm->pinned_vm << (PAGE_SHIFT-10),
60520@@ -63,7 +75,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
60521 data << (PAGE_SHIFT-10),
60522 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
60523 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
60524- swap << (PAGE_SHIFT-10));
60525+ swap << (PAGE_SHIFT-10)
60526+
60527+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
60528+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60529+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
60530+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
60531+#else
60532+ , mm->context.user_cs_base
60533+ , mm->context.user_cs_limit
60534+#endif
60535+#endif
60536+
60537+ );
60538 }
60539
60540 unsigned long task_vsize(struct mm_struct *mm)
60541@@ -278,13 +302,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
60542 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
60543 }
60544
60545- /* We don't show the stack guard page in /proc/maps */
60546+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60547+ start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
60548+ end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
60549+#else
60550 start = vma->vm_start;
60551- if (stack_guard_page_start(vma, start))
60552- start += PAGE_SIZE;
60553 end = vma->vm_end;
60554- if (stack_guard_page_end(vma, end))
60555- end -= PAGE_SIZE;
60556+#endif
60557
60558 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
60559 start,
60560@@ -293,7 +317,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
60561 flags & VM_WRITE ? 'w' : '-',
60562 flags & VM_EXEC ? 'x' : '-',
60563 flags & VM_MAYSHARE ? 's' : 'p',
60564+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60565+ PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
60566+#else
60567 pgoff,
60568+#endif
60569 MAJOR(dev), MINOR(dev), ino, &len);
60570
60571 /*
60572@@ -302,7 +330,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
60573 */
60574 if (file) {
60575 pad_len_spaces(m, len);
60576- seq_path(m, &file->f_path, "\n");
60577+ seq_path(m, &file->f_path, "\n\\");
60578 goto done;
60579 }
60580
60581@@ -328,8 +356,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
60582 * Thread stack in /proc/PID/task/TID/maps or
60583 * the main process stack.
60584 */
60585- if (!is_pid || (vma->vm_start <= mm->start_stack &&
60586- vma->vm_end >= mm->start_stack)) {
60587+ if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
60588+ (vma->vm_start <= mm->start_stack &&
60589+ vma->vm_end >= mm->start_stack)) {
60590 name = "[stack]";
60591 } else {
60592 /* Thread stack in /proc/PID/maps */
60593@@ -353,6 +382,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
60594 struct proc_maps_private *priv = m->private;
60595 struct task_struct *task = priv->task;
60596
60597+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60598+ if (current->exec_id != m->exec_id) {
60599+ gr_log_badprocpid("maps");
60600+ return 0;
60601+ }
60602+#endif
60603+
60604 show_map_vma(m, vma, is_pid);
60605
60606 if (m->count < m->size) /* vma is copied successfully */
60607@@ -590,12 +626,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
60608 .private = &mss,
60609 };
60610
60611+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60612+ if (current->exec_id != m->exec_id) {
60613+ gr_log_badprocpid("smaps");
60614+ return 0;
60615+ }
60616+#endif
60617 memset(&mss, 0, sizeof mss);
60618- mss.vma = vma;
60619- /* mmap_sem is held in m_start */
60620- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
60621- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
60622-
60623+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60624+ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
60625+#endif
60626+ mss.vma = vma;
60627+ /* mmap_sem is held in m_start */
60628+ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
60629+ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
60630+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60631+ }
60632+#endif
60633 show_map_vma(m, vma, is_pid);
60634
60635 seq_printf(m,
60636@@ -613,7 +660,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
60637 "KernelPageSize: %8lu kB\n"
60638 "MMUPageSize: %8lu kB\n"
60639 "Locked: %8lu kB\n",
60640+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60641+ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
60642+#else
60643 (vma->vm_end - vma->vm_start) >> 10,
60644+#endif
60645 mss.resident >> 10,
60646 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
60647 mss.shared_clean >> 10,
60648@@ -1390,6 +1441,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
60649 int n;
60650 char buffer[50];
60651
60652+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60653+ if (current->exec_id != m->exec_id) {
60654+ gr_log_badprocpid("numa_maps");
60655+ return 0;
60656+ }
60657+#endif
60658+
60659 if (!mm)
60660 return 0;
60661
60662@@ -1409,11 +1467,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
60663 if (n < 0)
60664 return n;
60665
60666+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60667+ seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
60668+#else
60669 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
60670+#endif
60671
60672 if (file) {
60673 seq_printf(m, " file=");
60674- seq_path(m, &file->f_path, "\n\t= ");
60675+ seq_path(m, &file->f_path, "\n\t\\= ");
60676 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
60677 seq_printf(m, " heap");
60678 } else {
60679diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
60680index 56123a6..5a2f6ec 100644
60681--- a/fs/proc/task_nommu.c
60682+++ b/fs/proc/task_nommu.c
60683@@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
60684 else
60685 bytes += kobjsize(mm);
60686
60687- if (current->fs && current->fs->users > 1)
60688+ if (current->fs && atomic_read(&current->fs->users) > 1)
60689 sbytes += kobjsize(current->fs);
60690 else
60691 bytes += kobjsize(current->fs);
60692@@ -168,7 +168,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
60693
60694 if (file) {
60695 pad_len_spaces(m, len);
60696- seq_path(m, &file->f_path, "");
60697+ seq_path(m, &file->f_path, "\n\\");
60698 } else if (mm) {
60699 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
60700
60701diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
60702index 9100d69..f1f9fc9 100644
60703--- a/fs/proc/vmcore.c
60704+++ b/fs/proc/vmcore.c
60705@@ -105,9 +105,13 @@ static ssize_t read_from_oldmem(char *buf, size_t count,
60706 nr_bytes = count;
60707
60708 /* If pfn is not ram, return zeros for sparse dump files */
60709- if (pfn_is_ram(pfn) == 0)
60710- memset(buf, 0, nr_bytes);
60711- else {
60712+ if (pfn_is_ram(pfn) == 0) {
60713+ if (userbuf) {
60714+ if (clear_user((char __force_user *)buf, nr_bytes))
60715+ return -EFAULT;
60716+ } else
60717+ memset(buf, 0, nr_bytes);
60718+ } else {
60719 tmp = copy_oldmem_page(pfn, buf, nr_bytes,
60720 offset, userbuf);
60721 if (tmp < 0)
60722@@ -233,7 +237,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
60723 if (*fpos < m->offset + m->size) {
60724 tsz = min_t(size_t, m->offset + m->size - *fpos, buflen);
60725 start = m->paddr + *fpos - m->offset;
60726- tmp = read_from_oldmem(buffer, tsz, &start, userbuf);
60727+ tmp = read_from_oldmem((char __force_kernel *)buffer, tsz, &start, userbuf);
60728 if (tmp < 0)
60729 return tmp;
60730 buflen -= tsz;
60731diff --git a/fs/qnx6/qnx6.h b/fs/qnx6/qnx6.h
60732index b00fcc9..e0c6381 100644
60733--- a/fs/qnx6/qnx6.h
60734+++ b/fs/qnx6/qnx6.h
60735@@ -74,7 +74,7 @@ enum {
60736 BYTESEX_BE,
60737 };
60738
60739-static inline __u64 fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
60740+static inline __u64 __intentional_overflow(-1) fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
60741 {
60742 if (sbi->s_bytesex == BYTESEX_LE)
60743 return le64_to_cpu((__force __le64)n);
60744@@ -90,7 +90,7 @@ static inline __fs64 cpu_to_fs64(struct qnx6_sb_info *sbi, __u64 n)
60745 return (__force __fs64)cpu_to_be64(n);
60746 }
60747
60748-static inline __u32 fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
60749+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
60750 {
60751 if (sbi->s_bytesex == BYTESEX_LE)
60752 return le32_to_cpu((__force __le32)n);
60753diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
60754index 16e8abb..2dcf914 100644
60755--- a/fs/quota/netlink.c
60756+++ b/fs/quota/netlink.c
60757@@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
60758 void quota_send_warning(struct kqid qid, dev_t dev,
60759 const char warntype)
60760 {
60761- static atomic_t seq;
60762+ static atomic_unchecked_t seq;
60763 struct sk_buff *skb;
60764 void *msg_head;
60765 int ret;
60766@@ -49,7 +49,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
60767 "VFS: Not enough memory to send quota warning.\n");
60768 return;
60769 }
60770- msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
60771+ msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
60772 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
60773 if (!msg_head) {
60774 printk(KERN_ERR
60775diff --git a/fs/read_write.c b/fs/read_write.c
60776index e3cd280..a378473 100644
60777--- a/fs/read_write.c
60778+++ b/fs/read_write.c
60779@@ -438,7 +438,7 @@ ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t
60780
60781 old_fs = get_fs();
60782 set_fs(get_ds());
60783- p = (__force const char __user *)buf;
60784+ p = (const char __force_user *)buf;
60785 if (count > MAX_RW_COUNT)
60786 count = MAX_RW_COUNT;
60787 if (file->f_op->write)
60788diff --git a/fs/readdir.c b/fs/readdir.c
60789index 93d71e5..6a14be8 100644
60790--- a/fs/readdir.c
60791+++ b/fs/readdir.c
60792@@ -17,6 +17,7 @@
60793 #include <linux/security.h>
60794 #include <linux/syscalls.h>
60795 #include <linux/unistd.h>
60796+#include <linux/namei.h>
60797
60798 #include <asm/uaccess.h>
60799
60800@@ -69,6 +70,7 @@ struct old_linux_dirent {
60801 struct readdir_callback {
60802 struct dir_context ctx;
60803 struct old_linux_dirent __user * dirent;
60804+ struct file * file;
60805 int result;
60806 };
60807
60808@@ -86,6 +88,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
60809 buf->result = -EOVERFLOW;
60810 return -EOVERFLOW;
60811 }
60812+
60813+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
60814+ return 0;
60815+
60816 buf->result++;
60817 dirent = buf->dirent;
60818 if (!access_ok(VERIFY_WRITE, dirent,
60819@@ -117,6 +123,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
60820 if (!f.file)
60821 return -EBADF;
60822
60823+ buf.file = f.file;
60824 error = iterate_dir(f.file, &buf.ctx);
60825 if (buf.result)
60826 error = buf.result;
60827@@ -142,6 +149,7 @@ struct getdents_callback {
60828 struct dir_context ctx;
60829 struct linux_dirent __user * current_dir;
60830 struct linux_dirent __user * previous;
60831+ struct file * file;
60832 int count;
60833 int error;
60834 };
60835@@ -163,6 +171,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
60836 buf->error = -EOVERFLOW;
60837 return -EOVERFLOW;
60838 }
60839+
60840+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
60841+ return 0;
60842+
60843 dirent = buf->previous;
60844 if (dirent) {
60845 if (__put_user(offset, &dirent->d_off))
60846@@ -208,6 +220,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
60847 if (!f.file)
60848 return -EBADF;
60849
60850+ buf.file = f.file;
60851 error = iterate_dir(f.file, &buf.ctx);
60852 if (error >= 0)
60853 error = buf.error;
60854@@ -226,6 +239,7 @@ struct getdents_callback64 {
60855 struct dir_context ctx;
60856 struct linux_dirent64 __user * current_dir;
60857 struct linux_dirent64 __user * previous;
60858+ struct file *file;
60859 int count;
60860 int error;
60861 };
60862@@ -241,6 +255,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
60863 buf->error = -EINVAL; /* only used if we fail.. */
60864 if (reclen > buf->count)
60865 return -EINVAL;
60866+
60867+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
60868+ return 0;
60869+
60870 dirent = buf->previous;
60871 if (dirent) {
60872 if (__put_user(offset, &dirent->d_off))
60873@@ -288,6 +306,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
60874 if (!f.file)
60875 return -EBADF;
60876
60877+ buf.file = f.file;
60878 error = iterate_dir(f.file, &buf.ctx);
60879 if (error >= 0)
60880 error = buf.error;
60881diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
60882index 2b7882b..1c5ef48 100644
60883--- a/fs/reiserfs/do_balan.c
60884+++ b/fs/reiserfs/do_balan.c
60885@@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
60886 return;
60887 }
60888
60889- atomic_inc(&(fs_generation(tb->tb_sb)));
60890+ atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
60891 do_balance_starts(tb);
60892
60893 /* balance leaf returns 0 except if combining L R and S into
60894diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
60895index a958444..42b2323 100644
60896--- a/fs/reiserfs/procfs.c
60897+++ b/fs/reiserfs/procfs.c
60898@@ -114,7 +114,7 @@ static int show_super(struct seq_file *m, void *unused)
60899 "SMALL_TAILS " : "NO_TAILS ",
60900 replay_only(sb) ? "REPLAY_ONLY " : "",
60901 convert_reiserfs(sb) ? "CONV " : "",
60902- atomic_read(&r->s_generation_counter),
60903+ atomic_read_unchecked(&r->s_generation_counter),
60904 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
60905 SF(s_do_balance), SF(s_unneeded_left_neighbor),
60906 SF(s_good_search_by_key_reada), SF(s_bmaps),
60907diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
60908index f8adaee..0eeeeca 100644
60909--- a/fs/reiserfs/reiserfs.h
60910+++ b/fs/reiserfs/reiserfs.h
60911@@ -453,7 +453,7 @@ struct reiserfs_sb_info {
60912 /* Comment? -Hans */
60913 wait_queue_head_t s_wait;
60914 /* To be obsoleted soon by per buffer seals.. -Hans */
60915- atomic_t s_generation_counter; // increased by one every time the
60916+ atomic_unchecked_t s_generation_counter; // increased by one every time the
60917 // tree gets re-balanced
60918 unsigned long s_properties; /* File system properties. Currently holds
60919 on-disk FS format */
60920@@ -1982,7 +1982,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
60921 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
60922
60923 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
60924-#define get_generation(s) atomic_read (&fs_generation(s))
60925+#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
60926 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
60927 #define __fs_changed(gen,s) (gen != get_generation (s))
60928 #define fs_changed(gen,s) \
60929diff --git a/fs/select.c b/fs/select.c
60930index dfd5cb1..1754d57 100644
60931--- a/fs/select.c
60932+++ b/fs/select.c
60933@@ -20,6 +20,7 @@
60934 #include <linux/export.h>
60935 #include <linux/slab.h>
60936 #include <linux/poll.h>
60937+#include <linux/security.h>
60938 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
60939 #include <linux/file.h>
60940 #include <linux/fdtable.h>
60941@@ -880,6 +881,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
60942 struct poll_list *walk = head;
60943 unsigned long todo = nfds;
60944
60945+ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
60946 if (nfds > rlimit(RLIMIT_NOFILE))
60947 return -EINVAL;
60948
60949diff --git a/fs/seq_file.c b/fs/seq_file.c
60950index a290157..ec3211a 100644
60951--- a/fs/seq_file.c
60952+++ b/fs/seq_file.c
60953@@ -10,6 +10,7 @@
60954 #include <linux/seq_file.h>
60955 #include <linux/slab.h>
60956 #include <linux/cred.h>
60957+#include <linux/sched.h>
60958
60959 #include <asm/uaccess.h>
60960 #include <asm/page.h>
60961@@ -60,6 +61,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
60962 #ifdef CONFIG_USER_NS
60963 p->user_ns = file->f_cred->user_ns;
60964 #endif
60965+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60966+ p->exec_id = current->exec_id;
60967+#endif
60968
60969 /*
60970 * Wrappers around seq_open(e.g. swaps_open) need to be
60971@@ -96,7 +100,7 @@ static int traverse(struct seq_file *m, loff_t offset)
60972 return 0;
60973 }
60974 if (!m->buf) {
60975- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
60976+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
60977 if (!m->buf)
60978 return -ENOMEM;
60979 }
60980@@ -136,7 +140,7 @@ static int traverse(struct seq_file *m, loff_t offset)
60981 Eoverflow:
60982 m->op->stop(m, p);
60983 kfree(m->buf);
60984- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
60985+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
60986 return !m->buf ? -ENOMEM : -EAGAIN;
60987 }
60988
60989@@ -152,7 +156,7 @@ Eoverflow:
60990 ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
60991 {
60992 struct seq_file *m = file->private_data;
60993- size_t copied = 0;
60994+ ssize_t copied = 0;
60995 loff_t pos;
60996 size_t n;
60997 void *p;
60998@@ -191,7 +195,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
60999
61000 /* grab buffer if we didn't have one */
61001 if (!m->buf) {
61002- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
61003+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
61004 if (!m->buf)
61005 goto Enomem;
61006 }
61007@@ -232,7 +236,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
61008 goto Fill;
61009 m->op->stop(m, p);
61010 kfree(m->buf);
61011- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
61012+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
61013 if (!m->buf)
61014 goto Enomem;
61015 m->count = 0;
61016@@ -583,7 +587,7 @@ static void single_stop(struct seq_file *p, void *v)
61017 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
61018 void *data)
61019 {
61020- struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
61021+ seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
61022 int res = -ENOMEM;
61023
61024 if (op) {
61025diff --git a/fs/splice.c b/fs/splice.c
61026index 3b7ee65..87fc2e4 100644
61027--- a/fs/splice.c
61028+++ b/fs/splice.c
61029@@ -196,7 +196,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
61030 pipe_lock(pipe);
61031
61032 for (;;) {
61033- if (!pipe->readers) {
61034+ if (!atomic_read(&pipe->readers)) {
61035 send_sig(SIGPIPE, current, 0);
61036 if (!ret)
61037 ret = -EPIPE;
61038@@ -219,7 +219,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
61039 page_nr++;
61040 ret += buf->len;
61041
61042- if (pipe->files)
61043+ if (atomic_read(&pipe->files))
61044 do_wakeup = 1;
61045
61046 if (!--spd->nr_pages)
61047@@ -250,9 +250,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
61048 do_wakeup = 0;
61049 }
61050
61051- pipe->waiting_writers++;
61052+ atomic_inc(&pipe->waiting_writers);
61053 pipe_wait(pipe);
61054- pipe->waiting_writers--;
61055+ atomic_dec(&pipe->waiting_writers);
61056 }
61057
61058 pipe_unlock(pipe);
61059@@ -565,7 +565,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
61060 old_fs = get_fs();
61061 set_fs(get_ds());
61062 /* The cast to a user pointer is valid due to the set_fs() */
61063- res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
61064+ res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
61065 set_fs(old_fs);
61066
61067 return res;
61068@@ -580,7 +580,7 @@ ssize_t kernel_write(struct file *file, const char *buf, size_t count,
61069 old_fs = get_fs();
61070 set_fs(get_ds());
61071 /* The cast to a user pointer is valid due to the set_fs() */
61072- res = vfs_write(file, (__force const char __user *)buf, count, &pos);
61073+ res = vfs_write(file, (const char __force_user *)buf, count, &pos);
61074 set_fs(old_fs);
61075
61076 return res;
61077@@ -633,7 +633,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
61078 goto err;
61079
61080 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
61081- vec[i].iov_base = (void __user *) page_address(page);
61082+ vec[i].iov_base = (void __force_user *) page_address(page);
61083 vec[i].iov_len = this_len;
61084 spd.pages[i] = page;
61085 spd.nr_pages++;
61086@@ -829,7 +829,7 @@ int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_desc *sd,
61087 ops->release(pipe, buf);
61088 pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
61089 pipe->nrbufs--;
61090- if (pipe->files)
61091+ if (atomic_read(&pipe->files))
61092 sd->need_wakeup = true;
61093 }
61094
61095@@ -854,10 +854,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
61096 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
61097 {
61098 while (!pipe->nrbufs) {
61099- if (!pipe->writers)
61100+ if (!atomic_read(&pipe->writers))
61101 return 0;
61102
61103- if (!pipe->waiting_writers && sd->num_spliced)
61104+ if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
61105 return 0;
61106
61107 if (sd->flags & SPLICE_F_NONBLOCK)
61108@@ -1179,7 +1179,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
61109 * out of the pipe right after the splice_to_pipe(). So set
61110 * PIPE_READERS appropriately.
61111 */
61112- pipe->readers = 1;
61113+ atomic_set(&pipe->readers, 1);
61114
61115 current->splice_pipe = pipe;
61116 }
61117@@ -1475,6 +1475,7 @@ static int get_iovec_page_array(const struct iovec __user *iov,
61118
61119 partial[buffers].offset = off;
61120 partial[buffers].len = plen;
61121+ partial[buffers].private = 0;
61122
61123 off = 0;
61124 len -= plen;
61125@@ -1777,9 +1778,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
61126 ret = -ERESTARTSYS;
61127 break;
61128 }
61129- if (!pipe->writers)
61130+ if (!atomic_read(&pipe->writers))
61131 break;
61132- if (!pipe->waiting_writers) {
61133+ if (!atomic_read(&pipe->waiting_writers)) {
61134 if (flags & SPLICE_F_NONBLOCK) {
61135 ret = -EAGAIN;
61136 break;
61137@@ -1811,7 +1812,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
61138 pipe_lock(pipe);
61139
61140 while (pipe->nrbufs >= pipe->buffers) {
61141- if (!pipe->readers) {
61142+ if (!atomic_read(&pipe->readers)) {
61143 send_sig(SIGPIPE, current, 0);
61144 ret = -EPIPE;
61145 break;
61146@@ -1824,9 +1825,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
61147 ret = -ERESTARTSYS;
61148 break;
61149 }
61150- pipe->waiting_writers++;
61151+ atomic_inc(&pipe->waiting_writers);
61152 pipe_wait(pipe);
61153- pipe->waiting_writers--;
61154+ atomic_dec(&pipe->waiting_writers);
61155 }
61156
61157 pipe_unlock(pipe);
61158@@ -1862,14 +1863,14 @@ retry:
61159 pipe_double_lock(ipipe, opipe);
61160
61161 do {
61162- if (!opipe->readers) {
61163+ if (!atomic_read(&opipe->readers)) {
61164 send_sig(SIGPIPE, current, 0);
61165 if (!ret)
61166 ret = -EPIPE;
61167 break;
61168 }
61169
61170- if (!ipipe->nrbufs && !ipipe->writers)
61171+ if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
61172 break;
61173
61174 /*
61175@@ -1966,7 +1967,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
61176 pipe_double_lock(ipipe, opipe);
61177
61178 do {
61179- if (!opipe->readers) {
61180+ if (!atomic_read(&opipe->readers)) {
61181 send_sig(SIGPIPE, current, 0);
61182 if (!ret)
61183 ret = -EPIPE;
61184@@ -2011,7 +2012,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
61185 * return EAGAIN if we have the potential of some data in the
61186 * future, otherwise just return 0
61187 */
61188- if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
61189+ if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
61190 ret = -EAGAIN;
61191
61192 pipe_unlock(ipipe);
61193diff --git a/fs/stat.c b/fs/stat.c
61194index d0ea7ef..f463f9d 100644
61195--- a/fs/stat.c
61196+++ b/fs/stat.c
61197@@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
61198 stat->gid = inode->i_gid;
61199 stat->rdev = inode->i_rdev;
61200 stat->size = i_size_read(inode);
61201- stat->atime = inode->i_atime;
61202- stat->mtime = inode->i_mtime;
61203+ if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
61204+ stat->atime = inode->i_ctime;
61205+ stat->mtime = inode->i_ctime;
61206+ } else {
61207+ stat->atime = inode->i_atime;
61208+ stat->mtime = inode->i_mtime;
61209+ }
61210 stat->ctime = inode->i_ctime;
61211 stat->blksize = (1 << inode->i_blkbits);
61212 stat->blocks = inode->i_blocks;
61213@@ -46,8 +51,14 @@ int vfs_getattr(struct path *path, struct kstat *stat)
61214 if (retval)
61215 return retval;
61216
61217- if (inode->i_op->getattr)
61218- return inode->i_op->getattr(path->mnt, path->dentry, stat);
61219+ if (inode->i_op->getattr) {
61220+ retval = inode->i_op->getattr(path->mnt, path->dentry, stat);
61221+ if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
61222+ stat->atime = stat->ctime;
61223+ stat->mtime = stat->ctime;
61224+ }
61225+ return retval;
61226+ }
61227
61228 generic_fillattr(inode, stat);
61229 return 0;
61230diff --git a/fs/sysfs/bin.c b/fs/sysfs/bin.c
61231index c590cab..6dfd6fc 100644
61232--- a/fs/sysfs/bin.c
61233+++ b/fs/sysfs/bin.c
61234@@ -234,13 +234,13 @@ static int bin_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
61235 return ret;
61236 }
61237
61238-static int bin_access(struct vm_area_struct *vma, unsigned long addr,
61239- void *buf, int len, int write)
61240+static ssize_t bin_access(struct vm_area_struct *vma, unsigned long addr,
61241+ void *buf, size_t len, int write)
61242 {
61243 struct file *file = vma->vm_file;
61244 struct bin_buffer *bb = file->private_data;
61245 struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata;
61246- int ret;
61247+ ssize_t ret;
61248
61249 if (!bb->vm_ops)
61250 return -EINVAL;
61251diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
61252index 4d83ced..049dc45 100644
61253--- a/fs/sysfs/dir.c
61254+++ b/fs/sysfs/dir.c
61255@@ -40,7 +40,7 @@ static DEFINE_IDA(sysfs_ino_ida);
61256 *
61257 * Returns 31 bit hash of ns + name (so it fits in an off_t )
61258 */
61259-static unsigned int sysfs_name_hash(const void *ns, const char *name)
61260+static unsigned int sysfs_name_hash(const void *ns, const unsigned char *name)
61261 {
61262 unsigned long hash = init_name_hash();
61263 unsigned int len = strlen(name);
61264@@ -675,6 +675,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
61265 struct sysfs_dirent *sd;
61266 int rc;
61267
61268+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
61269+ const char *parent_name = parent_sd->s_name;
61270+
61271+ mode = S_IFDIR | S_IRWXU;
61272+
61273+ if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
61274+ (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
61275+ (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse") || !strcmp(name, "ecryptfs"))) ||
61276+ (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
61277+ mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
61278+#endif
61279+
61280 /* allocate */
61281 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
61282 if (!sd)
61283diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
61284index 15ef5eb..e474372 100644
61285--- a/fs/sysfs/file.c
61286+++ b/fs/sysfs/file.c
61287@@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
61288
61289 struct sysfs_open_dirent {
61290 atomic_t refcnt;
61291- atomic_t event;
61292+ atomic_unchecked_t event;
61293 wait_queue_head_t poll;
61294 struct list_head buffers; /* goes through sysfs_buffer.list */
61295 };
61296@@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry *dentry, struct sysfs_buffer *buffer)
61297 if (!sysfs_get_active(attr_sd))
61298 return -ENODEV;
61299
61300- buffer->event = atomic_read(&attr_sd->s_attr.open->event);
61301+ buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
61302 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
61303
61304 sysfs_put_active(attr_sd);
61305@@ -284,7 +284,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
61306 return -ENOMEM;
61307
61308 atomic_set(&new_od->refcnt, 0);
61309- atomic_set(&new_od->event, 1);
61310+ atomic_set_unchecked(&new_od->event, 1);
61311 init_waitqueue_head(&new_od->poll);
61312 INIT_LIST_HEAD(&new_od->buffers);
61313 goto retry;
61314@@ -430,7 +430,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
61315
61316 sysfs_put_active(attr_sd);
61317
61318- if (buffer->event != atomic_read(&od->event))
61319+ if (buffer->event != atomic_read_unchecked(&od->event))
61320 goto trigger;
61321
61322 return DEFAULT_POLLMASK;
61323@@ -450,7 +450,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
61324 if (!WARN_ON(sysfs_type(sd) != SYSFS_KOBJ_ATTR)) {
61325 od = sd->s_attr.open;
61326 if (od) {
61327- atomic_inc(&od->event);
61328+ atomic_inc_unchecked(&od->event);
61329 wake_up_interruptible(&od->poll);
61330 }
61331 }
61332diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
61333index 2dd4507..62a215a 100644
61334--- a/fs/sysfs/symlink.c
61335+++ b/fs/sysfs/symlink.c
61336@@ -308,7 +308,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
61337 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd,
61338 void *cookie)
61339 {
61340- char *page = nd_get_link(nd);
61341+ const char *page = nd_get_link(nd);
61342 if (!IS_ERR(page))
61343 free_page((unsigned long)page);
61344 }
61345diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h
61346index 69d4889..a810bd4 100644
61347--- a/fs/sysv/sysv.h
61348+++ b/fs/sysv/sysv.h
61349@@ -188,7 +188,7 @@ static inline u32 PDP_swab(u32 x)
61350 #endif
61351 }
61352
61353-static inline __u32 fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
61354+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
61355 {
61356 if (sbi->s_bytesex == BYTESEX_PDP)
61357 return PDP_swab((__force __u32)n);
61358diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c
61359index e18b988..f1d4ad0f 100644
61360--- a/fs/ubifs/io.c
61361+++ b/fs/ubifs/io.c
61362@@ -155,7 +155,7 @@ int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len)
61363 return err;
61364 }
61365
61366-int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
61367+int __intentional_overflow(-1) ubifs_leb_unmap(struct ubifs_info *c, int lnum)
61368 {
61369 int err;
61370
61371diff --git a/fs/udf/misc.c b/fs/udf/misc.c
61372index c175b4d..8f36a16 100644
61373--- a/fs/udf/misc.c
61374+++ b/fs/udf/misc.c
61375@@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
61376
61377 u8 udf_tag_checksum(const struct tag *t)
61378 {
61379- u8 *data = (u8 *)t;
61380+ const u8 *data = (const u8 *)t;
61381 u8 checksum = 0;
61382 int i;
61383 for (i = 0; i < sizeof(struct tag); ++i)
61384diff --git a/fs/ufs/swab.h b/fs/ufs/swab.h
61385index 8d974c4..b82f6ec 100644
61386--- a/fs/ufs/swab.h
61387+++ b/fs/ufs/swab.h
61388@@ -22,7 +22,7 @@ enum {
61389 BYTESEX_BE
61390 };
61391
61392-static inline u64
61393+static inline u64 __intentional_overflow(-1)
61394 fs64_to_cpu(struct super_block *sbp, __fs64 n)
61395 {
61396 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
61397@@ -40,7 +40,7 @@ cpu_to_fs64(struct super_block *sbp, u64 n)
61398 return (__force __fs64)cpu_to_be64(n);
61399 }
61400
61401-static inline u32
61402+static inline u32 __intentional_overflow(-1)
61403 fs32_to_cpu(struct super_block *sbp, __fs32 n)
61404 {
61405 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
61406diff --git a/fs/utimes.c b/fs/utimes.c
61407index f4fb7ec..3fe03c0 100644
61408--- a/fs/utimes.c
61409+++ b/fs/utimes.c
61410@@ -1,6 +1,7 @@
61411 #include <linux/compiler.h>
61412 #include <linux/file.h>
61413 #include <linux/fs.h>
61414+#include <linux/security.h>
61415 #include <linux/linkage.h>
61416 #include <linux/mount.h>
61417 #include <linux/namei.h>
61418@@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
61419 goto mnt_drop_write_and_out;
61420 }
61421 }
61422+
61423+ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
61424+ error = -EACCES;
61425+ goto mnt_drop_write_and_out;
61426+ }
61427+
61428 mutex_lock(&inode->i_mutex);
61429 error = notify_change(path->dentry, &newattrs);
61430 mutex_unlock(&inode->i_mutex);
61431diff --git a/fs/xattr.c b/fs/xattr.c
61432index 3377dff..4d074d9 100644
61433--- a/fs/xattr.c
61434+++ b/fs/xattr.c
61435@@ -227,6 +227,27 @@ int vfs_xattr_cmp(struct dentry *dentry, const char *xattr_name,
61436 return rc;
61437 }
61438
61439+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
61440+ssize_t
61441+pax_getxattr(struct dentry *dentry, void *value, size_t size)
61442+{
61443+ struct inode *inode = dentry->d_inode;
61444+ ssize_t error;
61445+
61446+ error = inode_permission(inode, MAY_EXEC);
61447+ if (error)
61448+ return error;
61449+
61450+ if (inode->i_op->getxattr)
61451+ error = inode->i_op->getxattr(dentry, XATTR_NAME_PAX_FLAGS, value, size);
61452+ else
61453+ error = -EOPNOTSUPP;
61454+
61455+ return error;
61456+}
61457+EXPORT_SYMBOL(pax_getxattr);
61458+#endif
61459+
61460 ssize_t
61461 vfs_getxattr(struct dentry *dentry, const char *name, void *value, size_t size)
61462 {
61463@@ -319,7 +340,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
61464 * Extended attribute SET operations
61465 */
61466 static long
61467-setxattr(struct dentry *d, const char __user *name, const void __user *value,
61468+setxattr(struct path *path, const char __user *name, const void __user *value,
61469 size_t size, int flags)
61470 {
61471 int error;
61472@@ -355,7 +376,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
61473 posix_acl_fix_xattr_from_user(kvalue, size);
61474 }
61475
61476- error = vfs_setxattr(d, kname, kvalue, size, flags);
61477+ if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
61478+ error = -EACCES;
61479+ goto out;
61480+ }
61481+
61482+ error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
61483 out:
61484 if (vvalue)
61485 vfree(vvalue);
61486@@ -377,7 +403,7 @@ retry:
61487 return error;
61488 error = mnt_want_write(path.mnt);
61489 if (!error) {
61490- error = setxattr(path.dentry, name, value, size, flags);
61491+ error = setxattr(&path, name, value, size, flags);
61492 mnt_drop_write(path.mnt);
61493 }
61494 path_put(&path);
61495@@ -401,7 +427,7 @@ retry:
61496 return error;
61497 error = mnt_want_write(path.mnt);
61498 if (!error) {
61499- error = setxattr(path.dentry, name, value, size, flags);
61500+ error = setxattr(&path, name, value, size, flags);
61501 mnt_drop_write(path.mnt);
61502 }
61503 path_put(&path);
61504@@ -416,16 +442,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
61505 const void __user *,value, size_t, size, int, flags)
61506 {
61507 struct fd f = fdget(fd);
61508- struct dentry *dentry;
61509 int error = -EBADF;
61510
61511 if (!f.file)
61512 return error;
61513- dentry = f.file->f_path.dentry;
61514- audit_inode(NULL, dentry, 0);
61515+ audit_inode(NULL, f.file->f_path.dentry, 0);
61516 error = mnt_want_write_file(f.file);
61517 if (!error) {
61518- error = setxattr(dentry, name, value, size, flags);
61519+ error = setxattr(&f.file->f_path, name, value, size, flags);
61520 mnt_drop_write_file(f.file);
61521 }
61522 fdput(f);
61523diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
61524index 9fbea87..6b19972 100644
61525--- a/fs/xattr_acl.c
61526+++ b/fs/xattr_acl.c
61527@@ -76,8 +76,8 @@ struct posix_acl *
61528 posix_acl_from_xattr(struct user_namespace *user_ns,
61529 const void *value, size_t size)
61530 {
61531- posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
61532- posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
61533+ const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
61534+ const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
61535 int count;
61536 struct posix_acl *acl;
61537 struct posix_acl_entry *acl_e;
61538diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
61539index f47e65c..e7125d9 100644
61540--- a/fs/xfs/xfs_bmap.c
61541+++ b/fs/xfs/xfs_bmap.c
61542@@ -586,7 +586,7 @@ xfs_bmap_validate_ret(
61543
61544 #else
61545 #define xfs_bmap_check_leaf_extents(cur, ip, whichfork) do { } while (0)
61546-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
61547+#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do { } while (0)
61548 #endif /* DEBUG */
61549
61550 /*
61551diff --git a/fs/xfs/xfs_dir2_readdir.c b/fs/xfs/xfs_dir2_readdir.c
61552index 8f84153..7ce60d0 100644
61553--- a/fs/xfs/xfs_dir2_readdir.c
61554+++ b/fs/xfs/xfs_dir2_readdir.c
61555@@ -160,7 +160,12 @@ xfs_dir2_sf_getdents(
61556 ino = xfs_dir3_sfe_get_ino(mp, sfp, sfep);
61557 filetype = xfs_dir3_sfe_get_ftype(mp, sfp, sfep);
61558 ctx->pos = off & 0x7fffffff;
61559- if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
61560+ if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
61561+ char name[sfep->namelen];
61562+ memcpy(name, sfep->name, sfep->namelen);
61563+ if (!dir_emit(ctx, name, sfep->namelen, ino, xfs_dir3_get_dtype(mp, filetype)))
61564+ return 0;
61565+ } else if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
61566 xfs_dir3_get_dtype(mp, filetype)))
61567 return 0;
61568 sfep = xfs_dir3_sf_nextentry(mp, sfp, sfep);
61569diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
61570index 668e8f4..9d38104 100644
61571--- a/fs/xfs/xfs_ioctl.c
61572+++ b/fs/xfs/xfs_ioctl.c
61573@@ -127,7 +127,7 @@ xfs_find_handle(
61574 }
61575
61576 error = -EFAULT;
61577- if (copy_to_user(hreq->ohandle, &handle, hsize) ||
61578+ if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
61579 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
61580 goto out_put;
61581
61582diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
61583index 2b8952d..a60c6be 100644
61584--- a/fs/xfs/xfs_iops.c
61585+++ b/fs/xfs/xfs_iops.c
61586@@ -401,7 +401,7 @@ xfs_vn_put_link(
61587 struct nameidata *nd,
61588 void *p)
61589 {
61590- char *s = nd_get_link(nd);
61591+ const char *s = nd_get_link(nd);
61592
61593 if (!IS_ERR(s))
61594 kfree(s);
61595diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
61596new file mode 100644
61597index 0000000..6d22fbe
61598--- /dev/null
61599+++ b/grsecurity/Kconfig
61600@@ -0,0 +1,1112 @@
61601+#
61602+# grecurity configuration
61603+#
61604+menu "Memory Protections"
61605+depends on GRKERNSEC
61606+
61607+config GRKERNSEC_KMEM
61608+ bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
61609+ default y if GRKERNSEC_CONFIG_AUTO
61610+ select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
61611+ help
61612+ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
61613+ be written to or read from to modify or leak the contents of the running
61614+ kernel. /dev/port will also not be allowed to be opened and support
61615+ for /dev/cpu/*/msr will be removed. If you have module
61616+ support disabled, enabling this will close up five ways that are
61617+ currently used to insert malicious code into the running kernel.
61618+
61619+ Even with all these features enabled, we still highly recommend that
61620+ you use the RBAC system, as it is still possible for an attacker to
61621+ modify the running kernel through privileged I/O granted by ioperm/iopl.
61622+
61623+ If you are not using XFree86, you may be able to stop this additional
61624+ case by enabling the 'Disable privileged I/O' option. Though nothing
61625+ legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
61626+ but only to video memory, which is the only writing we allow in this
61627+ case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
61628+ not be allowed to mprotect it with PROT_WRITE later.
61629+ Enabling this feature will prevent the "cpupower" and "powertop" tools
61630+ from working.
61631+
61632+ It is highly recommended that you say Y here if you meet all the
61633+ conditions above.
61634+
61635+config GRKERNSEC_VM86
61636+ bool "Restrict VM86 mode"
61637+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
61638+ depends on X86_32
61639+
61640+ help
61641+ If you say Y here, only processes with CAP_SYS_RAWIO will be able to
61642+ make use of a special execution mode on 32bit x86 processors called
61643+ Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
61644+ video cards and will still work with this option enabled. The purpose
61645+ of the option is to prevent exploitation of emulation errors in
61646+ virtualization of vm86 mode like the one discovered in VMWare in 2009.
61647+ Nearly all users should be able to enable this option.
61648+
61649+config GRKERNSEC_IO
61650+ bool "Disable privileged I/O"
61651+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
61652+ depends on X86
61653+ select RTC_CLASS
61654+ select RTC_INTF_DEV
61655+ select RTC_DRV_CMOS
61656+
61657+ help
61658+ If you say Y here, all ioperm and iopl calls will return an error.
61659+ Ioperm and iopl can be used to modify the running kernel.
61660+ Unfortunately, some programs need this access to operate properly,
61661+ the most notable of which are XFree86 and hwclock. hwclock can be
61662+ remedied by having RTC support in the kernel, so real-time
61663+ clock support is enabled if this option is enabled, to ensure
61664+ that hwclock operates correctly. XFree86 still will not
61665+ operate correctly with this option enabled, so DO NOT CHOOSE Y
61666+ IF YOU USE XFree86. If you use XFree86 and you still want to
61667+ protect your kernel against modification, use the RBAC system.
61668+
61669+config GRKERNSEC_JIT_HARDEN
61670+ bool "Harden BPF JIT against spray attacks"
61671+ default y if GRKERNSEC_CONFIG_AUTO
61672+ depends on BPF_JIT
61673+ help
61674+ If you say Y here, the native code generated by the kernel's Berkeley
61675+ Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
61676+ attacks that attempt to fit attacker-beneficial instructions in
61677+ 32bit immediate fields of JIT-generated native instructions. The
61678+ attacker will generally aim to cause an unintended instruction sequence
61679+ of JIT-generated native code to execute by jumping into the middle of
61680+ a generated instruction. This feature effectively randomizes the 32bit
61681+ immediate constants present in the generated code to thwart such attacks.
61682+
61683+ If you're using KERNEXEC, it's recommended that you enable this option
61684+ to supplement the hardening of the kernel.
61685+
61686+config GRKERNSEC_PERF_HARDEN
61687+ bool "Disable unprivileged PERF_EVENTS usage by default"
61688+ default y if GRKERNSEC_CONFIG_AUTO
61689+ depends on PERF_EVENTS
61690+ help
61691+ If you say Y here, the range of acceptable values for the
61692+ /proc/sys/kernel/perf_event_paranoid sysctl will be expanded to allow and
61693+ default to a new value: 3. When the sysctl is set to this value, no
61694+ unprivileged use of the PERF_EVENTS syscall interface will be permitted.
61695+
61696+ Though PERF_EVENTS can be used legitimately for performance monitoring
61697+ and low-level application profiling, it is forced on regardless of
61698+ configuration, has been at fault for several vulnerabilities, and
61699+ creates new opportunities for side channels and other information leaks.
61700+
61701+ This feature puts PERF_EVENTS into a secure default state and permits
61702+ the administrator to change out of it temporarily if unprivileged
61703+ application profiling is needed.
61704+
61705+config GRKERNSEC_RAND_THREADSTACK
61706+ bool "Insert random gaps between thread stacks"
61707+ default y if GRKERNSEC_CONFIG_AUTO
61708+ depends on PAX_RANDMMAP && !PPC
61709+ help
61710+ If you say Y here, a random-sized gap will be enforced between allocated
61711+ thread stacks. Glibc's NPTL and other threading libraries that
61712+ pass MAP_STACK to the kernel for thread stack allocation are supported.
61713+ The implementation currently provides 8 bits of entropy for the gap.
61714+
61715+ Many distributions do not compile threaded remote services with the
61716+ -fstack-check argument to GCC, causing the variable-sized stack-based
61717+ allocator, alloca(), to not probe the stack on allocation. This
61718+ permits an unbounded alloca() to skip over any guard page and potentially
61719+ modify another thread's stack reliably. An enforced random gap
61720+ reduces the reliability of such an attack and increases the chance
61721+ that such a read/write to another thread's stack instead lands in
61722+ an unmapped area, causing a crash and triggering grsecurity's
61723+ anti-bruteforcing logic.
61724+
61725+config GRKERNSEC_PROC_MEMMAP
61726+ bool "Harden ASLR against information leaks and entropy reduction"
61727+ default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
61728+ depends on PAX_NOEXEC || PAX_ASLR
61729+ help
61730+ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
61731+ give no information about the addresses of its mappings if
61732+ PaX features that rely on random addresses are enabled on the task.
61733+ In addition to sanitizing this information and disabling other
61734+ dangerous sources of information, this option causes reads of sensitive
61735+ /proc/<pid> entries where the file descriptor was opened in a different
61736+ task than the one performing the read. Such attempts are logged.
61737+ This option also limits argv/env strings for suid/sgid binaries
61738+ to 512KB to prevent a complete exhaustion of the stack entropy provided
61739+ by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
61740+ binaries to prevent alternative mmap layouts from being abused.
61741+
61742+ If you use PaX it is essential that you say Y here as it closes up
61743+ several holes that make full ASLR useless locally.
61744+
61745+config GRKERNSEC_BRUTE
61746+ bool "Deter exploit bruteforcing"
61747+ default y if GRKERNSEC_CONFIG_AUTO
61748+ help
61749+ If you say Y here, attempts to bruteforce exploits against forking
61750+ daemons such as apache or sshd, as well as against suid/sgid binaries
61751+ will be deterred. When a child of a forking daemon is killed by PaX
61752+ or crashes due to an illegal instruction or other suspicious signal,
61753+ the parent process will be delayed 30 seconds upon every subsequent
61754+ fork until the administrator is able to assess the situation and
61755+ restart the daemon.
61756+ In the suid/sgid case, the attempt is logged, the user has all their
61757+ existing instances of the suid/sgid binary terminated and will
61758+ be unable to execute any suid/sgid binaries for 15 minutes.
61759+
61760+ It is recommended that you also enable signal logging in the auditing
61761+ section so that logs are generated when a process triggers a suspicious
61762+ signal.
61763+ If the sysctl option is enabled, a sysctl option with name
61764+ "deter_bruteforce" is created.
61765+
61766+
61767+config GRKERNSEC_MODHARDEN
61768+ bool "Harden module auto-loading"
61769+ default y if GRKERNSEC_CONFIG_AUTO
61770+ depends on MODULES
61771+ help
61772+ If you say Y here, module auto-loading in response to use of some
61773+ feature implemented by an unloaded module will be restricted to
61774+ root users. Enabling this option helps defend against attacks
61775+ by unprivileged users who abuse the auto-loading behavior to
61776+ cause a vulnerable module to load that is then exploited.
61777+
61778+ If this option prevents a legitimate use of auto-loading for a
61779+ non-root user, the administrator can execute modprobe manually
61780+ with the exact name of the module mentioned in the alert log.
61781+ Alternatively, the administrator can add the module to the list
61782+ of modules loaded at boot by modifying init scripts.
61783+
61784+ Modification of init scripts will most likely be needed on
61785+ Ubuntu servers with encrypted home directory support enabled,
61786+ as the first non-root user logging in will cause the ecb(aes),
61787+ ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
61788+
61789+config GRKERNSEC_HIDESYM
61790+ bool "Hide kernel symbols"
61791+ default y if GRKERNSEC_CONFIG_AUTO
61792+ select PAX_USERCOPY_SLABS
61793+ help
61794+ If you say Y here, getting information on loaded modules, and
61795+ displaying all kernel symbols through a syscall will be restricted
61796+ to users with CAP_SYS_MODULE. For software compatibility reasons,
61797+ /proc/kallsyms will be restricted to the root user. The RBAC
61798+ system can hide that entry even from root.
61799+
61800+ This option also prevents leaking of kernel addresses through
61801+ several /proc entries.
61802+
61803+ Note that this option is only effective provided the following
61804+ conditions are met:
61805+ 1) The kernel using grsecurity is not precompiled by some distribution
61806+ 2) You have also enabled GRKERNSEC_DMESG
61807+ 3) You are using the RBAC system and hiding other files such as your
61808+ kernel image and System.map. Alternatively, enabling this option
61809+ causes the permissions on /boot, /lib/modules, and the kernel
61810+ source directory to change at compile time to prevent
61811+ reading by non-root users.
61812+ If the above conditions are met, this option will aid in providing a
61813+ useful protection against local kernel exploitation of overflows
61814+ and arbitrary read/write vulnerabilities.
61815+
61816+ It is highly recommended that you enable GRKERNSEC_PERF_HARDEN
61817+ in addition to this feature.
61818+
61819+config GRKERNSEC_KERN_LOCKOUT
61820+ bool "Active kernel exploit response"
61821+ default y if GRKERNSEC_CONFIG_AUTO
61822+ depends on X86 || ARM || PPC || SPARC
61823+ help
61824+ If you say Y here, when a PaX alert is triggered due to suspicious
61825+ activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
61826+ or an OOPS occurs due to bad memory accesses, instead of just
61827+ terminating the offending process (and potentially allowing
61828+ a subsequent exploit from the same user), we will take one of two
61829+ actions:
61830+ If the user was root, we will panic the system
61831+ If the user was non-root, we will log the attempt, terminate
61832+ all processes owned by the user, then prevent them from creating
61833+ any new processes until the system is restarted
61834+ This deters repeated kernel exploitation/bruteforcing attempts
61835+ and is useful for later forensics.
61836+
61837+config GRKERNSEC_OLD_ARM_USERLAND
61838+ bool "Old ARM userland compatibility"
61839+ depends on ARM && (CPU_V6 || CPU_V6K || CPU_V7)
61840+ help
61841+ If you say Y here, stubs of executable code to perform such operations
61842+ as "compare-exchange" will be placed at fixed locations in the ARM vector
61843+ table. This is unfortunately needed for old ARM userland meant to run
61844+ across a wide range of processors. Without this option enabled,
61845+ the get_tls and data memory barrier stubs will be emulated by the kernel,
61846+ which is enough for Linaro userlands or other userlands designed for v6
61847+ and newer ARM CPUs. It's recommended that you try without this option enabled
61848+ first, and only enable it if your userland does not boot (it will likely fail
61849+ at init time).
61850+
61851+endmenu
61852+menu "Role Based Access Control Options"
61853+depends on GRKERNSEC
61854+
61855+config GRKERNSEC_RBAC_DEBUG
61856+ bool
61857+
61858+config GRKERNSEC_NO_RBAC
61859+ bool "Disable RBAC system"
61860+ help
61861+ If you say Y here, the /dev/grsec device will be removed from the kernel,
61862+ preventing the RBAC system from being enabled. You should only say Y
61863+ here if you have no intention of using the RBAC system, so as to prevent
61864+ an attacker with root access from misusing the RBAC system to hide files
61865+ and processes when loadable module support and /dev/[k]mem have been
61866+ locked down.
61867+
61868+config GRKERNSEC_ACL_HIDEKERN
61869+ bool "Hide kernel processes"
61870+ help
61871+ If you say Y here, all kernel threads will be hidden to all
61872+ processes but those whose subject has the "view hidden processes"
61873+ flag.
61874+
61875+config GRKERNSEC_ACL_MAXTRIES
61876+ int "Maximum tries before password lockout"
61877+ default 3
61878+ help
61879+ This option enforces the maximum number of times a user can attempt
61880+ to authorize themselves with the grsecurity RBAC system before being
61881+ denied the ability to attempt authorization again for a specified time.
61882+ The lower the number, the harder it will be to brute-force a password.
61883+
61884+config GRKERNSEC_ACL_TIMEOUT
61885+ int "Time to wait after max password tries, in seconds"
61886+ default 30
61887+ help
61888+ This option specifies the time the user must wait after attempting to
61889+ authorize to the RBAC system with the maximum number of invalid
61890+ passwords. The higher the number, the harder it will be to brute-force
61891+ a password.
61892+
61893+endmenu
61894+menu "Filesystem Protections"
61895+depends on GRKERNSEC
61896+
61897+config GRKERNSEC_PROC
61898+ bool "Proc restrictions"
61899+ default y if GRKERNSEC_CONFIG_AUTO
61900+ help
61901+ If you say Y here, the permissions of the /proc filesystem
61902+ will be altered to enhance system security and privacy. You MUST
61903+ choose either a user only restriction or a user and group restriction.
61904+ Depending upon the option you choose, you can either restrict users to
61905+ see only the processes they themselves run, or choose a group that can
61906+ view all processes and files normally restricted to root if you choose
61907+ the "restrict to user only" option. NOTE: If you're running identd or
61908+ ntpd as a non-root user, you will have to run it as the group you
61909+ specify here.
61910+
61911+config GRKERNSEC_PROC_USER
61912+ bool "Restrict /proc to user only"
61913+ depends on GRKERNSEC_PROC
61914+ help
61915+ If you say Y here, non-root users will only be able to view their own
61916+ processes, and restricts them from viewing network-related information,
61917+ and viewing kernel symbol and module information.
61918+
61919+config GRKERNSEC_PROC_USERGROUP
61920+ bool "Allow special group"
61921+ default y if GRKERNSEC_CONFIG_AUTO
61922+ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
61923+ help
61924+ If you say Y here, you will be able to select a group that will be
61925+ able to view all processes and network-related information. If you've
61926+ enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
61927+ remain hidden. This option is useful if you want to run identd as
61928+ a non-root user. The group you select may also be chosen at boot time
61929+ via "grsec_proc_gid=" on the kernel commandline.
61930+
61931+config GRKERNSEC_PROC_GID
61932+ int "GID for special group"
61933+ depends on GRKERNSEC_PROC_USERGROUP
61934+ default 1001
61935+
61936+config GRKERNSEC_PROC_ADD
61937+ bool "Additional restrictions"
61938+ default y if GRKERNSEC_CONFIG_AUTO
61939+ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
61940+ help
61941+ If you say Y here, additional restrictions will be placed on
61942+ /proc that keep normal users from viewing device information and
61943+ slabinfo information that could be useful for exploits.
61944+
61945+config GRKERNSEC_LINK
61946+ bool "Linking restrictions"
61947+ default y if GRKERNSEC_CONFIG_AUTO
61948+ help
61949+ If you say Y here, /tmp race exploits will be prevented, since users
61950+ will no longer be able to follow symlinks owned by other users in
61951+ world-writable +t directories (e.g. /tmp), unless the owner of the
61952+ symlink is the owner of the directory. users will also not be
61953+ able to hardlink to files they do not own. If the sysctl option is
61954+ enabled, a sysctl option with name "linking_restrictions" is created.
61955+
61956+config GRKERNSEC_SYMLINKOWN
61957+ bool "Kernel-enforced SymlinksIfOwnerMatch"
61958+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
61959+ help
61960+ Apache's SymlinksIfOwnerMatch option has an inherent race condition
61961+ that prevents it from being used as a security feature. As Apache
61962+ verifies the symlink by performing a stat() against the target of
61963+ the symlink before it is followed, an attacker can setup a symlink
61964+ to point to a same-owned file, then replace the symlink with one
61965+ that targets another user's file just after Apache "validates" the
61966+ symlink -- a classic TOCTOU race. If you say Y here, a complete,
61967+ race-free replacement for Apache's "SymlinksIfOwnerMatch" option
61968+ will be in place for the group you specify. If the sysctl option
61969+ is enabled, a sysctl option with name "enforce_symlinksifowner" is
61970+ created.
61971+
61972+config GRKERNSEC_SYMLINKOWN_GID
61973+ int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
61974+ depends on GRKERNSEC_SYMLINKOWN
61975+ default 1006
61976+ help
61977+ Setting this GID determines what group kernel-enforced
61978+ SymlinksIfOwnerMatch will be enabled for. If the sysctl option
61979+ is enabled, a sysctl option with name "symlinkown_gid" is created.
61980+
61981+config GRKERNSEC_FIFO
61982+ bool "FIFO restrictions"
61983+ default y if GRKERNSEC_CONFIG_AUTO
61984+ help
61985+ If you say Y here, users will not be able to write to FIFOs they don't
61986+ own in world-writable +t directories (e.g. /tmp), unless the owner of
61987+ the FIFO is the same owner of the directory it's held in. If the sysctl
61988+ option is enabled, a sysctl option with name "fifo_restrictions" is
61989+ created.
61990+
61991+config GRKERNSEC_SYSFS_RESTRICT
61992+ bool "Sysfs/debugfs restriction"
61993+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
61994+ depends on SYSFS
61995+ help
61996+ If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
61997+ any filesystem normally mounted under it (e.g. debugfs) will be
61998+ mostly accessible only by root. These filesystems generally provide access
61999+ to hardware and debug information that isn't appropriate for unprivileged
62000+ users of the system. Sysfs and debugfs have also become a large source
62001+ of new vulnerabilities, ranging from infoleaks to local compromise.
62002+ There has been very little oversight with an eye toward security involved
62003+ in adding new exporters of information to these filesystems, so their
62004+ use is discouraged.
62005+ For reasons of compatibility, a few directories have been whitelisted
62006+ for access by non-root users:
62007+ /sys/fs/selinux
62008+ /sys/fs/fuse
62009+ /sys/devices/system/cpu
62010+
62011+config GRKERNSEC_ROFS
62012+ bool "Runtime read-only mount protection"
62013+ depends on SYSCTL
62014+ help
62015+ If you say Y here, a sysctl option with name "romount_protect" will
62016+ be created. By setting this option to 1 at runtime, filesystems
62017+ will be protected in the following ways:
62018+ * No new writable mounts will be allowed
62019+ * Existing read-only mounts won't be able to be remounted read/write
62020+ * Write operations will be denied on all block devices
62021+ This option acts independently of grsec_lock: once it is set to 1,
62022+ it cannot be turned off. Therefore, please be mindful of the resulting
62023+ behavior if this option is enabled in an init script on a read-only
62024+ filesystem. This feature is mainly intended for secure embedded systems.
62025+
62026+config GRKERNSEC_DEVICE_SIDECHANNEL
62027+ bool "Eliminate stat/notify-based device sidechannels"
62028+ default y if GRKERNSEC_CONFIG_AUTO
62029+ help
62030+ If you say Y here, timing analyses on block or character
62031+ devices like /dev/ptmx using stat or inotify/dnotify/fanotify
62032+ will be thwarted for unprivileged users. If a process without
62033+ CAP_MKNOD stats such a device, the last access and last modify times
62034+ will match the device's create time. No access or modify events
62035+ will be triggered through inotify/dnotify/fanotify for such devices.
62036+ This feature will prevent attacks that may at a minimum
62037+ allow an attacker to determine the administrator's password length.
62038+
62039+config GRKERNSEC_CHROOT
62040+ bool "Chroot jail restrictions"
62041+ default y if GRKERNSEC_CONFIG_AUTO
62042+ help
62043+ If you say Y here, you will be able to choose several options that will
62044+ make breaking out of a chrooted jail much more difficult. If you
62045+ encounter no software incompatibilities with the following options, it
62046+ is recommended that you enable each one.
62047+
62048+config GRKERNSEC_CHROOT_MOUNT
62049+ bool "Deny mounts"
62050+ default y if GRKERNSEC_CONFIG_AUTO
62051+ depends on GRKERNSEC_CHROOT
62052+ help
62053+ If you say Y here, processes inside a chroot will not be able to
62054+ mount or remount filesystems. If the sysctl option is enabled, a
62055+ sysctl option with name "chroot_deny_mount" is created.
62056+
62057+config GRKERNSEC_CHROOT_DOUBLE
62058+ bool "Deny double-chroots"
62059+ default y if GRKERNSEC_CONFIG_AUTO
62060+ depends on GRKERNSEC_CHROOT
62061+ help
62062+ If you say Y here, processes inside a chroot will not be able to chroot
62063+ again outside the chroot. This is a widely used method of breaking
62064+ out of a chroot jail and should not be allowed. If the sysctl
62065+ option is enabled, a sysctl option with name
62066+ "chroot_deny_chroot" is created.
62067+
62068+config GRKERNSEC_CHROOT_PIVOT
62069+ bool "Deny pivot_root in chroot"
62070+ default y if GRKERNSEC_CONFIG_AUTO
62071+ depends on GRKERNSEC_CHROOT
62072+ help
62073+ If you say Y here, processes inside a chroot will not be able to use
62074+ a function called pivot_root() that was introduced in Linux 2.3.41. It
62075+ works similar to chroot in that it changes the root filesystem. This
62076+ function could be misused in a chrooted process to attempt to break out
62077+ of the chroot, and therefore should not be allowed. If the sysctl
62078+ option is enabled, a sysctl option with name "chroot_deny_pivot" is
62079+ created.
62080+
62081+config GRKERNSEC_CHROOT_CHDIR
62082+ bool "Enforce chdir(\"/\") on all chroots"
62083+ default y if GRKERNSEC_CONFIG_AUTO
62084+ depends on GRKERNSEC_CHROOT
62085+ help
62086+ If you say Y here, the current working directory of all newly-chrooted
62087+ applications will be set to the the root directory of the chroot.
62088+ The man page on chroot(2) states:
62089+ Note that this call does not change the current working
62090+ directory, so that `.' can be outside the tree rooted at
62091+ `/'. In particular, the super-user can escape from a
62092+ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
62093+
62094+ It is recommended that you say Y here, since it's not known to break
62095+ any software. If the sysctl option is enabled, a sysctl option with
62096+ name "chroot_enforce_chdir" is created.
62097+
62098+config GRKERNSEC_CHROOT_CHMOD
62099+ bool "Deny (f)chmod +s"
62100+ default y if GRKERNSEC_CONFIG_AUTO
62101+ depends on GRKERNSEC_CHROOT
62102+ help
62103+ If you say Y here, processes inside a chroot will not be able to chmod
62104+ or fchmod files to make them have suid or sgid bits. This protects
62105+ against another published method of breaking a chroot. If the sysctl
62106+ option is enabled, a sysctl option with name "chroot_deny_chmod" is
62107+ created.
62108+
62109+config GRKERNSEC_CHROOT_FCHDIR
62110+ bool "Deny fchdir out of chroot"
62111+ default y if GRKERNSEC_CONFIG_AUTO
62112+ depends on GRKERNSEC_CHROOT
62113+ help
62114+ If you say Y here, a well-known method of breaking chroots by fchdir'ing
62115+ to a file descriptor of the chrooting process that points to a directory
62116+ outside the filesystem will be stopped. If the sysctl option
62117+ is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
62118+
62119+config GRKERNSEC_CHROOT_MKNOD
62120+ bool "Deny mknod"
62121+ default y if GRKERNSEC_CONFIG_AUTO
62122+ depends on GRKERNSEC_CHROOT
62123+ help
62124+ If you say Y here, processes inside a chroot will not be allowed to
62125+ mknod. The problem with using mknod inside a chroot is that it
62126+ would allow an attacker to create a device entry that is the same
62127+ as one on the physical root of your system, which could range from
62128+ anything from the console device to a device for your harddrive (which
62129+ they could then use to wipe the drive or steal data). It is recommended
62130+ that you say Y here, unless you run into software incompatibilities.
62131+ If the sysctl option is enabled, a sysctl option with name
62132+ "chroot_deny_mknod" is created.
62133+
62134+config GRKERNSEC_CHROOT_SHMAT
62135+ bool "Deny shmat() out of chroot"
62136+ default y if GRKERNSEC_CONFIG_AUTO
62137+ depends on GRKERNSEC_CHROOT
62138+ help
62139+ If you say Y here, processes inside a chroot will not be able to attach
62140+ to shared memory segments that were created outside of the chroot jail.
62141+ It is recommended that you say Y here. If the sysctl option is enabled,
62142+ a sysctl option with name "chroot_deny_shmat" is created.
62143+
62144+config GRKERNSEC_CHROOT_UNIX
62145+ bool "Deny access to abstract AF_UNIX sockets out of chroot"
62146+ default y if GRKERNSEC_CONFIG_AUTO
62147+ depends on GRKERNSEC_CHROOT
62148+ help
62149+ If you say Y here, processes inside a chroot will not be able to
62150+ connect to abstract (meaning not belonging to a filesystem) Unix
62151+ domain sockets that were bound outside of a chroot. It is recommended
62152+ that you say Y here. If the sysctl option is enabled, a sysctl option
62153+ with name "chroot_deny_unix" is created.
62154+
62155+config GRKERNSEC_CHROOT_FINDTASK
62156+ bool "Protect outside processes"
62157+ default y if GRKERNSEC_CONFIG_AUTO
62158+ depends on GRKERNSEC_CHROOT
62159+ help
62160+ If you say Y here, processes inside a chroot will not be able to
62161+ kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
62162+ getsid, or view any process outside of the chroot. If the sysctl
62163+ option is enabled, a sysctl option with name "chroot_findtask" is
62164+ created.
62165+
62166+config GRKERNSEC_CHROOT_NICE
62167+ bool "Restrict priority changes"
62168+ default y if GRKERNSEC_CONFIG_AUTO
62169+ depends on GRKERNSEC_CHROOT
62170+ help
62171+ If you say Y here, processes inside a chroot will not be able to raise
62172+ the priority of processes in the chroot, or alter the priority of
62173+ processes outside the chroot. This provides more security than simply
62174+ removing CAP_SYS_NICE from the process' capability set. If the
62175+ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
62176+ is created.
62177+
62178+config GRKERNSEC_CHROOT_SYSCTL
62179+ bool "Deny sysctl writes"
62180+ default y if GRKERNSEC_CONFIG_AUTO
62181+ depends on GRKERNSEC_CHROOT
62182+ help
62183+ If you say Y here, an attacker in a chroot will not be able to
62184+ write to sysctl entries, either by sysctl(2) or through a /proc
62185+ interface. It is strongly recommended that you say Y here. If the
62186+ sysctl option is enabled, a sysctl option with name
62187+ "chroot_deny_sysctl" is created.
62188+
62189+config GRKERNSEC_CHROOT_CAPS
62190+ bool "Capability restrictions"
62191+ default y if GRKERNSEC_CONFIG_AUTO
62192+ depends on GRKERNSEC_CHROOT
62193+ help
62194+ If you say Y here, the capabilities on all processes within a
62195+ chroot jail will be lowered to stop module insertion, raw i/o,
62196+ system and net admin tasks, rebooting the system, modifying immutable
62197+ files, modifying IPC owned by another, and changing the system time.
62198+ This is left an option because it can break some apps. Disable this
62199+ if your chrooted apps are having problems performing those kinds of
62200+ tasks. If the sysctl option is enabled, a sysctl option with
62201+ name "chroot_caps" is created.
62202+
62203+config GRKERNSEC_CHROOT_INITRD
62204+ bool "Exempt initrd tasks from restrictions"
62205+ default y if GRKERNSEC_CONFIG_AUTO
62206+ depends on GRKERNSEC_CHROOT && BLK_DEV_INITRD
62207+ help
62208+ If you say Y here, tasks started prior to init will be exempted from
62209+ grsecurity's chroot restrictions. This option is mainly meant to
62210+ resolve Plymouth's performing privileged operations unnecessarily
62211+ in a chroot.
62212+
62213+endmenu
62214+menu "Kernel Auditing"
62215+depends on GRKERNSEC
62216+
62217+config GRKERNSEC_AUDIT_GROUP
62218+ bool "Single group for auditing"
62219+ help
62220+ If you say Y here, the exec and chdir logging features will only operate
62221+ on a group you specify. This option is recommended if you only want to
62222+ watch certain users instead of having a large amount of logs from the
62223+ entire system. If the sysctl option is enabled, a sysctl option with
62224+ name "audit_group" is created.
62225+
62226+config GRKERNSEC_AUDIT_GID
62227+ int "GID for auditing"
62228+ depends on GRKERNSEC_AUDIT_GROUP
62229+ default 1007
62230+
62231+config GRKERNSEC_EXECLOG
62232+ bool "Exec logging"
62233+ help
62234+ If you say Y here, all execve() calls will be logged (since the
62235+ other exec*() calls are frontends to execve(), all execution
62236+ will be logged). Useful for shell-servers that like to keep track
62237+ of their users. If the sysctl option is enabled, a sysctl option with
62238+ name "exec_logging" is created.
62239+ WARNING: This option when enabled will produce a LOT of logs, especially
62240+ on an active system.
62241+
62242+config GRKERNSEC_RESLOG
62243+ bool "Resource logging"
62244+ default y if GRKERNSEC_CONFIG_AUTO
62245+ help
62246+ If you say Y here, all attempts to overstep resource limits will
62247+ be logged with the resource name, the requested size, and the current
62248+ limit. It is highly recommended that you say Y here. If the sysctl
62249+ option is enabled, a sysctl option with name "resource_logging" is
62250+ created. If the RBAC system is enabled, the sysctl value is ignored.
62251+
62252+config GRKERNSEC_CHROOT_EXECLOG
62253+ bool "Log execs within chroot"
62254+ help
62255+ If you say Y here, all executions inside a chroot jail will be logged
62256+ to syslog. This can cause a large amount of logs if certain
62257+ applications (eg. djb's daemontools) are installed on the system, and
62258+ is therefore left as an option. If the sysctl option is enabled, a
62259+ sysctl option with name "chroot_execlog" is created.
62260+
62261+config GRKERNSEC_AUDIT_PTRACE
62262+ bool "Ptrace logging"
62263+ help
62264+ If you say Y here, all attempts to attach to a process via ptrace
62265+ will be logged. If the sysctl option is enabled, a sysctl option
62266+ with name "audit_ptrace" is created.
62267+
62268+config GRKERNSEC_AUDIT_CHDIR
62269+ bool "Chdir logging"
62270+ help
62271+ If you say Y here, all chdir() calls will be logged. If the sysctl
62272+ option is enabled, a sysctl option with name "audit_chdir" is created.
62273+
62274+config GRKERNSEC_AUDIT_MOUNT
62275+ bool "(Un)Mount logging"
62276+ help
62277+ If you say Y here, all mounts and unmounts will be logged. If the
62278+ sysctl option is enabled, a sysctl option with name "audit_mount" is
62279+ created.
62280+
62281+config GRKERNSEC_SIGNAL
62282+ bool "Signal logging"
62283+ default y if GRKERNSEC_CONFIG_AUTO
62284+ help
62285+ If you say Y here, certain important signals will be logged, such as
62286+ SIGSEGV, which will as a result inform you of when a error in a program
62287+ occurred, which in some cases could mean a possible exploit attempt.
62288+ If the sysctl option is enabled, a sysctl option with name
62289+ "signal_logging" is created.
62290+
62291+config GRKERNSEC_FORKFAIL
62292+ bool "Fork failure logging"
62293+ help
62294+ If you say Y here, all failed fork() attempts will be logged.
62295+ This could suggest a fork bomb, or someone attempting to overstep
62296+ their process limit. If the sysctl option is enabled, a sysctl option
62297+ with name "forkfail_logging" is created.
62298+
62299+config GRKERNSEC_TIME
62300+ bool "Time change logging"
62301+ default y if GRKERNSEC_CONFIG_AUTO
62302+ help
62303+ If you say Y here, any changes of the system clock will be logged.
62304+ If the sysctl option is enabled, a sysctl option with name
62305+ "timechange_logging" is created.
62306+
62307+config GRKERNSEC_PROC_IPADDR
62308+ bool "/proc/<pid>/ipaddr support"
62309+ default y if GRKERNSEC_CONFIG_AUTO
62310+ help
62311+ If you say Y here, a new entry will be added to each /proc/<pid>
62312+ directory that contains the IP address of the person using the task.
62313+ The IP is carried across local TCP and AF_UNIX stream sockets.
62314+ This information can be useful for IDS/IPSes to perform remote response
62315+ to a local attack. The entry is readable by only the owner of the
62316+ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
62317+ the RBAC system), and thus does not create privacy concerns.
62318+
62319+config GRKERNSEC_RWXMAP_LOG
62320+ bool 'Denied RWX mmap/mprotect logging'
62321+ default y if GRKERNSEC_CONFIG_AUTO
62322+ depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
62323+ help
62324+ If you say Y here, calls to mmap() and mprotect() with explicit
62325+ usage of PROT_WRITE and PROT_EXEC together will be logged when
62326+ denied by the PAX_MPROTECT feature. This feature will also
62327+ log other problematic scenarios that can occur when PAX_MPROTECT
62328+ is enabled on a binary, like textrels and PT_GNU_STACK. If the
62329+ sysctl option is enabled, a sysctl option with name "rwxmap_logging"
62330+ is created.
62331+
62332+endmenu
62333+
62334+menu "Executable Protections"
62335+depends on GRKERNSEC
62336+
62337+config GRKERNSEC_DMESG
62338+ bool "Dmesg(8) restriction"
62339+ default y if GRKERNSEC_CONFIG_AUTO
62340+ help
62341+ If you say Y here, non-root users will not be able to use dmesg(8)
62342+ to view the contents of the kernel's circular log buffer.
62343+ The kernel's log buffer often contains kernel addresses and other
62344+ identifying information useful to an attacker in fingerprinting a
62345+ system for a targeted exploit.
62346+ If the sysctl option is enabled, a sysctl option with name "dmesg" is
62347+ created.
62348+
62349+config GRKERNSEC_HARDEN_PTRACE
62350+ bool "Deter ptrace-based process snooping"
62351+ default y if GRKERNSEC_CONFIG_AUTO
62352+ help
62353+ If you say Y here, TTY sniffers and other malicious monitoring
62354+ programs implemented through ptrace will be defeated. If you
62355+ have been using the RBAC system, this option has already been
62356+ enabled for several years for all users, with the ability to make
62357+ fine-grained exceptions.
62358+
62359+ This option only affects the ability of non-root users to ptrace
62360+ processes that are not a descendent of the ptracing process.
62361+ This means that strace ./binary and gdb ./binary will still work,
62362+ but attaching to arbitrary processes will not. If the sysctl
62363+ option is enabled, a sysctl option with name "harden_ptrace" is
62364+ created.
62365+
62366+config GRKERNSEC_PTRACE_READEXEC
62367+ bool "Require read access to ptrace sensitive binaries"
62368+ default y if GRKERNSEC_CONFIG_AUTO
62369+ help
62370+ If you say Y here, unprivileged users will not be able to ptrace unreadable
62371+ binaries. This option is useful in environments that
62372+ remove the read bits (e.g. file mode 4711) from suid binaries to
62373+ prevent infoleaking of their contents. This option adds
62374+ consistency to the use of that file mode, as the binary could normally
62375+ be read out when run without privileges while ptracing.
62376+
62377+ If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
62378+ is created.
62379+
62380+config GRKERNSEC_SETXID
62381+ bool "Enforce consistent multithreaded privileges"
62382+ default y if GRKERNSEC_CONFIG_AUTO
62383+ depends on (X86 || SPARC64 || PPC || ARM || MIPS)
62384+ help
62385+ If you say Y here, a change from a root uid to a non-root uid
62386+ in a multithreaded application will cause the resulting uids,
62387+ gids, supplementary groups, and capabilities in that thread
62388+ to be propagated to the other threads of the process. In most
62389+ cases this is unnecessary, as glibc will emulate this behavior
62390+ on behalf of the application. Other libcs do not act in the
62391+ same way, allowing the other threads of the process to continue
62392+ running with root privileges. If the sysctl option is enabled,
62393+ a sysctl option with name "consistent_setxid" is created.
62394+
62395+config GRKERNSEC_HARDEN_IPC
62396+ bool "Disallow access to world-accessible IPC objects"
62397+ default y if GRKERNSEC_CONFIG_AUTO
62398+ depends on SYSVIPC
62399+ help
62400+ If you say Y here, access to overly-permissive IPC (shared memory,
62401+ message queues, and semaphores) will be denied for processes whose
62402+ effective user or group would not grant them permission. It's a
62403+ common error to grant too much permission to these objects, with
62404+ impact ranging from denial of service and information leaking to
62405+ privilege escalation. This feature was developed in response to
62406+ research by Tim Brown:
62407+ http://labs.portcullis.co.uk/whitepapers/memory-squatting-attacks-on-system-v-shared-memory/
62408+ who found hundreds of such insecure usages. Processes with
62409+ CAP_IPC_OWNER are still permitted to access these IPC objects.
62410+ If the sysctl option is enabled, a sysctl option with name
62411+ "harden_ipc" is created.
62412+
62413+config GRKERNSEC_TPE
62414+ bool "Trusted Path Execution (TPE)"
62415+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
62416+ help
62417+ If you say Y here, you will be able to choose a gid to add to the
62418+ supplementary groups of users you want to mark as "untrusted."
62419+ These users will not be able to execute any files that are not in
62420+ root-owned directories writable only by root. If the sysctl option
62421+ is enabled, a sysctl option with name "tpe" is created.
62422+
62423+config GRKERNSEC_TPE_ALL
62424+ bool "Partially restrict all non-root users"
62425+ depends on GRKERNSEC_TPE
62426+ help
62427+ If you say Y here, all non-root users will be covered under
62428+ a weaker TPE restriction. This is separate from, and in addition to,
62429+ the main TPE options that you have selected elsewhere. Thus, if a
62430+ "trusted" GID is chosen, this restriction applies to even that GID.
62431+ Under this restriction, all non-root users will only be allowed to
62432+ execute files in directories they own that are not group or
62433+ world-writable, or in directories owned by root and writable only by
62434+ root. If the sysctl option is enabled, a sysctl option with name
62435+ "tpe_restrict_all" is created.
62436+
62437+config GRKERNSEC_TPE_INVERT
62438+ bool "Invert GID option"
62439+ depends on GRKERNSEC_TPE
62440+ help
62441+ If you say Y here, the group you specify in the TPE configuration will
62442+ decide what group TPE restrictions will be *disabled* for. This
62443+ option is useful if you want TPE restrictions to be applied to most
62444+ users on the system. If the sysctl option is enabled, a sysctl option
62445+ with name "tpe_invert" is created. Unlike other sysctl options, this
62446+ entry will default to on for backward-compatibility.
62447+
62448+config GRKERNSEC_TPE_GID
62449+ int
62450+ default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
62451+ default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
62452+
62453+config GRKERNSEC_TPE_UNTRUSTED_GID
62454+ int "GID for TPE-untrusted users"
62455+ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
62456+ default 1005
62457+ help
62458+ Setting this GID determines what group TPE restrictions will be
62459+ *enabled* for. If the sysctl option is enabled, a sysctl option
62460+ with name "tpe_gid" is created.
62461+
62462+config GRKERNSEC_TPE_TRUSTED_GID
62463+ int "GID for TPE-trusted users"
62464+ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
62465+ default 1005
62466+ help
62467+ Setting this GID determines what group TPE restrictions will be
62468+ *disabled* for. If the sysctl option is enabled, a sysctl option
62469+ with name "tpe_gid" is created.
62470+
62471+endmenu
62472+menu "Network Protections"
62473+depends on GRKERNSEC
62474+
62475+config GRKERNSEC_RANDNET
62476+ bool "Larger entropy pools"
62477+ default y if GRKERNSEC_CONFIG_AUTO
62478+ help
62479+ If you say Y here, the entropy pools used for many features of Linux
62480+ and grsecurity will be doubled in size. Since several grsecurity
62481+ features use additional randomness, it is recommended that you say Y
62482+ here. Saying Y here has a similar effect as modifying
62483+ /proc/sys/kernel/random/poolsize.
62484+
62485+config GRKERNSEC_BLACKHOLE
62486+ bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
62487+ default y if GRKERNSEC_CONFIG_AUTO
62488+ depends on NET
62489+ help
62490+ If you say Y here, neither TCP resets nor ICMP
62491+ destination-unreachable packets will be sent in response to packets
62492+ sent to ports for which no associated listening process exists.
62493+ This feature supports both IPV4 and IPV6 and exempts the
62494+ loopback interface from blackholing. Enabling this feature
62495+ makes a host more resilient to DoS attacks and reduces network
62496+ visibility against scanners.
62497+
62498+ The blackhole feature as-implemented is equivalent to the FreeBSD
62499+ blackhole feature, as it prevents RST responses to all packets, not
62500+ just SYNs. Under most application behavior this causes no
62501+ problems, but applications (like haproxy) may not close certain
62502+ connections in a way that cleanly terminates them on the remote
62503+ end, leaving the remote host in LAST_ACK state. Because of this
62504+ side-effect and to prevent intentional LAST_ACK DoSes, this
62505+ feature also adds automatic mitigation against such attacks.
62506+ The mitigation drastically reduces the amount of time a socket
62507+ can spend in LAST_ACK state. If you're using haproxy and not
62508+ all servers it connects to have this option enabled, consider
62509+ disabling this feature on the haproxy host.
62510+
62511+ If the sysctl option is enabled, two sysctl options with names
62512+ "ip_blackhole" and "lastack_retries" will be created.
62513+ While "ip_blackhole" takes the standard zero/non-zero on/off
62514+ toggle, "lastack_retries" uses the same kinds of values as
62515+ "tcp_retries1" and "tcp_retries2". The default value of 4
62516+ prevents a socket from lasting more than 45 seconds in LAST_ACK
62517+ state.
62518+
62519+config GRKERNSEC_NO_SIMULT_CONNECT
62520+ bool "Disable TCP Simultaneous Connect"
62521+ default y if GRKERNSEC_CONFIG_AUTO
62522+ depends on NET
62523+ help
62524+ If you say Y here, a feature by Willy Tarreau will be enabled that
62525+ removes a weakness in Linux's strict implementation of TCP that
62526+ allows two clients to connect to each other without either entering
62527+ a listening state. The weakness allows an attacker to easily prevent
62528+ a client from connecting to a known server provided the source port
62529+ for the connection is guessed correctly.
62530+
62531+ As the weakness could be used to prevent an antivirus or IPS from
62532+ fetching updates, or prevent an SSL gateway from fetching a CRL,
62533+ it should be eliminated by enabling this option. Though Linux is
62534+ one of few operating systems supporting simultaneous connect, it
62535+ has no legitimate use in practice and is rarely supported by firewalls.
62536+
62537+config GRKERNSEC_SOCKET
62538+ bool "Socket restrictions"
62539+ depends on NET
62540+ help
62541+ If you say Y here, you will be able to choose from several options.
62542+ If you assign a GID on your system and add it to the supplementary
62543+ groups of users you want to restrict socket access to, this patch
62544+ will perform up to three things, based on the option(s) you choose.
62545+
62546+config GRKERNSEC_SOCKET_ALL
62547+ bool "Deny any sockets to group"
62548+ depends on GRKERNSEC_SOCKET
62549+ help
62550+ If you say Y here, you will be able to choose a GID of whose users will
62551+ be unable to connect to other hosts from your machine or run server
62552+ applications from your machine. If the sysctl option is enabled, a
62553+ sysctl option with name "socket_all" is created.
62554+
62555+config GRKERNSEC_SOCKET_ALL_GID
62556+ int "GID to deny all sockets for"
62557+ depends on GRKERNSEC_SOCKET_ALL
62558+ default 1004
62559+ help
62560+ Here you can choose the GID to disable socket access for. Remember to
62561+ add the users you want socket access disabled for to the GID
62562+ specified here. If the sysctl option is enabled, a sysctl option
62563+ with name "socket_all_gid" is created.
62564+
62565+config GRKERNSEC_SOCKET_CLIENT
62566+ bool "Deny client sockets to group"
62567+ depends on GRKERNSEC_SOCKET
62568+ help
62569+ If you say Y here, you will be able to choose a GID of whose users will
62570+ be unable to connect to other hosts from your machine, but will be
62571+ able to run servers. If this option is enabled, all users in the group
62572+ you specify will have to use passive mode when initiating ftp transfers
62573+ from the shell on your machine. If the sysctl option is enabled, a
62574+ sysctl option with name "socket_client" is created.
62575+
62576+config GRKERNSEC_SOCKET_CLIENT_GID
62577+ int "GID to deny client sockets for"
62578+ depends on GRKERNSEC_SOCKET_CLIENT
62579+ default 1003
62580+ help
62581+ Here you can choose the GID to disable client socket access for.
62582+ Remember to add the users you want client socket access disabled for to
62583+ the GID specified here. If the sysctl option is enabled, a sysctl
62584+ option with name "socket_client_gid" is created.
62585+
62586+config GRKERNSEC_SOCKET_SERVER
62587+ bool "Deny server sockets to group"
62588+ depends on GRKERNSEC_SOCKET
62589+ help
62590+ If you say Y here, you will be able to choose a GID of whose users will
62591+ be unable to run server applications from your machine. If the sysctl
62592+ option is enabled, a sysctl option with name "socket_server" is created.
62593+
62594+config GRKERNSEC_SOCKET_SERVER_GID
62595+ int "GID to deny server sockets for"
62596+ depends on GRKERNSEC_SOCKET_SERVER
62597+ default 1002
62598+ help
62599+ Here you can choose the GID to disable server socket access for.
62600+ Remember to add the users you want server socket access disabled for to
62601+ the GID specified here. If the sysctl option is enabled, a sysctl
62602+ option with name "socket_server_gid" is created.
62603+
62604+endmenu
62605+
62606+menu "Physical Protections"
62607+depends on GRKERNSEC
62608+
62609+config GRKERNSEC_DENYUSB
62610+ bool "Deny new USB connections after toggle"
62611+ default y if GRKERNSEC_CONFIG_AUTO
62612+ depends on SYSCTL && USB_SUPPORT
62613+ help
62614+ If you say Y here, a new sysctl option with name "deny_new_usb"
62615+ will be created. Setting its value to 1 will prevent any new
62616+ USB devices from being recognized by the OS. Any attempted USB
62617+ device insertion will be logged. This option is intended to be
62618+ used against custom USB devices designed to exploit vulnerabilities
62619+ in various USB device drivers.
62620+
62621+ For greatest effectiveness, this sysctl should be set after any
62622+ relevant init scripts. This option is safe to enable in distros
62623+ as each user can choose whether or not to toggle the sysctl.
62624+
62625+config GRKERNSEC_DENYUSB_FORCE
62626+ bool "Reject all USB devices not connected at boot"
62627+ select USB
62628+ depends on GRKERNSEC_DENYUSB
62629+ help
62630+ If you say Y here, a variant of GRKERNSEC_DENYUSB will be enabled
62631+ that doesn't involve a sysctl entry. This option should only be
62632+ enabled if you're sure you want to deny all new USB connections
62633+ at runtime and don't want to modify init scripts. This should not
62634+ be enabled by distros. It forces the core USB code to be built
62635+ into the kernel image so that all devices connected at boot time
62636+ can be recognized and new USB device connections can be prevented
62637+ prior to init running.
62638+
62639+endmenu
62640+
62641+menu "Sysctl Support"
62642+depends on GRKERNSEC && SYSCTL
62643+
62644+config GRKERNSEC_SYSCTL
62645+ bool "Sysctl support"
62646+ default y if GRKERNSEC_CONFIG_AUTO
62647+ help
62648+ If you say Y here, you will be able to change the options that
62649+ grsecurity runs with at bootup, without having to recompile your
62650+ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
62651+ to enable (1) or disable (0) various features. All the sysctl entries
62652+ are mutable until the "grsec_lock" entry is set to a non-zero value.
62653+ All features enabled in the kernel configuration are disabled at boot
62654+ if you do not say Y to the "Turn on features by default" option.
62655+ All options should be set at startup, and the grsec_lock entry should
62656+ be set to a non-zero value after all the options are set.
62657+ *THIS IS EXTREMELY IMPORTANT*
62658+
62659+config GRKERNSEC_SYSCTL_DISTRO
62660+ bool "Extra sysctl support for distro makers (READ HELP)"
62661+ depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
62662+ help
62663+ If you say Y here, additional sysctl options will be created
62664+ for features that affect processes running as root. Therefore,
62665+ it is critical when using this option that the grsec_lock entry be
62666+ enabled after boot. Only distros with prebuilt kernel packages
62667+ with this option enabled that can ensure grsec_lock is enabled
62668+ after boot should use this option.
62669+ *Failure to set grsec_lock after boot makes all grsec features
62670+ this option covers useless*
62671+
62672+ Currently this option creates the following sysctl entries:
62673+ "Disable Privileged I/O": "disable_priv_io"
62674+
62675+config GRKERNSEC_SYSCTL_ON
62676+ bool "Turn on features by default"
62677+ default y if GRKERNSEC_CONFIG_AUTO
62678+ depends on GRKERNSEC_SYSCTL
62679+ help
62680+ If you say Y here, instead of having all features enabled in the
62681+ kernel configuration disabled at boot time, the features will be
62682+ enabled at boot time. It is recommended you say Y here unless
62683+ there is some reason you would want all sysctl-tunable features to
62684+ be disabled by default. As mentioned elsewhere, it is important
62685+ to enable the grsec_lock entry once you have finished modifying
62686+ the sysctl entries.
62687+
62688+endmenu
62689+menu "Logging Options"
62690+depends on GRKERNSEC
62691+
62692+config GRKERNSEC_FLOODTIME
62693+ int "Seconds in between log messages (minimum)"
62694+ default 10
62695+ help
62696+ This option allows you to enforce the number of seconds between
62697+ grsecurity log messages. The default should be suitable for most
62698+ people, however, if you choose to change it, choose a value small enough
62699+ to allow informative logs to be produced, but large enough to
62700+ prevent flooding.
62701+
62702+config GRKERNSEC_FLOODBURST
62703+ int "Number of messages in a burst (maximum)"
62704+ default 6
62705+ help
62706+ This option allows you to choose the maximum number of messages allowed
62707+ within the flood time interval you chose in a separate option. The
62708+ default should be suitable for most people, however if you find that
62709+ many of your logs are being interpreted as flooding, you may want to
62710+ raise this value.
62711+
62712+endmenu
62713diff --git a/grsecurity/Makefile b/grsecurity/Makefile
62714new file mode 100644
62715index 0000000..85beb79
62716--- /dev/null
62717+++ b/grsecurity/Makefile
62718@@ -0,0 +1,43 @@
62719+# grsecurity's ACL system was originally written in 2001 by Michael Dalton
62720+# during 2001-2009 it has been completely redesigned by Brad Spengler
62721+# into an RBAC system
62722+#
62723+# All code in this directory and various hooks inserted throughout the kernel
62724+# are copyright Brad Spengler - Open Source Security, Inc., and released
62725+# under the GPL v2 or higher
62726+
62727+KBUILD_CFLAGS += -Werror
62728+
62729+obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
62730+ grsec_mount.o grsec_sig.o grsec_sysctl.o \
62731+ grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o \
62732+ grsec_usb.o grsec_ipc.o
62733+
62734+obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
62735+ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
62736+ gracl_learn.o grsec_log.o gracl_policy.o
62737+ifdef CONFIG_COMPAT
62738+obj-$(CONFIG_GRKERNSEC) += gracl_compat.o
62739+endif
62740+
62741+obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
62742+
62743+ifdef CONFIG_NET
62744+obj-y += grsec_sock.o
62745+obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
62746+endif
62747+
62748+ifndef CONFIG_GRKERNSEC
62749+obj-y += grsec_disabled.o
62750+endif
62751+
62752+ifdef CONFIG_GRKERNSEC_HIDESYM
62753+extra-y := grsec_hidesym.o
62754+$(obj)/grsec_hidesym.o:
62755+ @-chmod -f 500 /boot
62756+ @-chmod -f 500 /lib/modules
62757+ @-chmod -f 500 /lib64/modules
62758+ @-chmod -f 500 /lib32/modules
62759+ @-chmod -f 700 .
62760+ @echo ' grsec: protected kernel image paths'
62761+endif
62762diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
62763new file mode 100644
62764index 0000000..857c960
62765--- /dev/null
62766+++ b/grsecurity/gracl.c
62767@@ -0,0 +1,2623 @@
62768+#include <linux/kernel.h>
62769+#include <linux/module.h>
62770+#include <linux/sched.h>
62771+#include <linux/mm.h>
62772+#include <linux/file.h>
62773+#include <linux/fs.h>
62774+#include <linux/namei.h>
62775+#include <linux/mount.h>
62776+#include <linux/tty.h>
62777+#include <linux/proc_fs.h>
62778+#include <linux/lglock.h>
62779+#include <linux/slab.h>
62780+#include <linux/vmalloc.h>
62781+#include <linux/types.h>
62782+#include <linux/sysctl.h>
62783+#include <linux/netdevice.h>
62784+#include <linux/ptrace.h>
62785+#include <linux/gracl.h>
62786+#include <linux/gralloc.h>
62787+#include <linux/security.h>
62788+#include <linux/grinternal.h>
62789+#include <linux/pid_namespace.h>
62790+#include <linux/stop_machine.h>
62791+#include <linux/fdtable.h>
62792+#include <linux/percpu.h>
62793+#include <linux/lglock.h>
62794+#include <linux/hugetlb.h>
62795+#include <linux/posix-timers.h>
62796+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
62797+#include <linux/magic.h>
62798+#include <linux/pagemap.h>
62799+#include "../fs/btrfs/async-thread.h"
62800+#include "../fs/btrfs/ctree.h"
62801+#include "../fs/btrfs/btrfs_inode.h"
62802+#endif
62803+#include "../fs/mount.h"
62804+
62805+#include <asm/uaccess.h>
62806+#include <asm/errno.h>
62807+#include <asm/mman.h>
62808+
62809+#define FOR_EACH_ROLE_START(role) \
62810+ role = running_polstate.role_list; \
62811+ while (role) {
62812+
62813+#define FOR_EACH_ROLE_END(role) \
62814+ role = role->prev; \
62815+ }
62816+
62817+extern struct lglock vfsmount_lock;
62818+
62819+extern struct path gr_real_root;
62820+
62821+static struct gr_policy_state running_polstate;
62822+struct gr_policy_state *polstate = &running_polstate;
62823+extern struct gr_alloc_state *current_alloc_state;
62824+
62825+extern char *gr_shared_page[4];
62826+DEFINE_RWLOCK(gr_inode_lock);
62827+
62828+static unsigned int gr_status __read_only = GR_STATUS_INIT;
62829+
62830+#ifdef CONFIG_NET
62831+extern struct vfsmount *sock_mnt;
62832+#endif
62833+
62834+extern struct vfsmount *pipe_mnt;
62835+extern struct vfsmount *shm_mnt;
62836+
62837+#ifdef CONFIG_HUGETLBFS
62838+extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
62839+#endif
62840+
62841+extern u16 acl_sp_role_value;
62842+extern struct acl_object_label *fakefs_obj_rw;
62843+extern struct acl_object_label *fakefs_obj_rwx;
62844+
62845+int gr_acl_is_enabled(void)
62846+{
62847+ return (gr_status & GR_READY);
62848+}
62849+
62850+void gr_enable_rbac_system(void)
62851+{
62852+ pax_open_kernel();
62853+ gr_status |= GR_READY;
62854+ pax_close_kernel();
62855+}
62856+
62857+int gr_rbac_disable(void *unused)
62858+{
62859+ pax_open_kernel();
62860+ gr_status &= ~GR_READY;
62861+ pax_close_kernel();
62862+
62863+ return 0;
62864+}
62865+
62866+static inline dev_t __get_dev(const struct dentry *dentry)
62867+{
62868+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
62869+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
62870+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
62871+ else
62872+#endif
62873+ return dentry->d_sb->s_dev;
62874+}
62875+
62876+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
62877+{
62878+ return __get_dev(dentry);
62879+}
62880+
62881+static char gr_task_roletype_to_char(struct task_struct *task)
62882+{
62883+ switch (task->role->roletype &
62884+ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
62885+ GR_ROLE_SPECIAL)) {
62886+ case GR_ROLE_DEFAULT:
62887+ return 'D';
62888+ case GR_ROLE_USER:
62889+ return 'U';
62890+ case GR_ROLE_GROUP:
62891+ return 'G';
62892+ case GR_ROLE_SPECIAL:
62893+ return 'S';
62894+ }
62895+
62896+ return 'X';
62897+}
62898+
62899+char gr_roletype_to_char(void)
62900+{
62901+ return gr_task_roletype_to_char(current);
62902+}
62903+
62904+__inline__ int
62905+gr_acl_tpe_check(void)
62906+{
62907+ if (unlikely(!(gr_status & GR_READY)))
62908+ return 0;
62909+ if (current->role->roletype & GR_ROLE_TPE)
62910+ return 1;
62911+ else
62912+ return 0;
62913+}
62914+
62915+int
62916+gr_handle_rawio(const struct inode *inode)
62917+{
62918+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
62919+ if (inode && S_ISBLK(inode->i_mode) &&
62920+ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
62921+ !capable(CAP_SYS_RAWIO))
62922+ return 1;
62923+#endif
62924+ return 0;
62925+}
62926+
62927+int
62928+gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
62929+{
62930+ if (likely(lena != lenb))
62931+ return 0;
62932+
62933+ return !memcmp(a, b, lena);
62934+}
62935+
62936+static int prepend(char **buffer, int *buflen, const char *str, int namelen)
62937+{
62938+ *buflen -= namelen;
62939+ if (*buflen < 0)
62940+ return -ENAMETOOLONG;
62941+ *buffer -= namelen;
62942+ memcpy(*buffer, str, namelen);
62943+ return 0;
62944+}
62945+
62946+static int prepend_name(char **buffer, int *buflen, struct qstr *name)
62947+{
62948+ return prepend(buffer, buflen, name->name, name->len);
62949+}
62950+
62951+static int prepend_path(const struct path *path, struct path *root,
62952+ char **buffer, int *buflen)
62953+{
62954+ struct dentry *dentry = path->dentry;
62955+ struct vfsmount *vfsmnt = path->mnt;
62956+ struct mount *mnt = real_mount(vfsmnt);
62957+ bool slash = false;
62958+ int error = 0;
62959+
62960+ while (dentry != root->dentry || vfsmnt != root->mnt) {
62961+ struct dentry * parent;
62962+
62963+ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
62964+ /* Global root? */
62965+ if (!mnt_has_parent(mnt)) {
62966+ goto out;
62967+ }
62968+ dentry = mnt->mnt_mountpoint;
62969+ mnt = mnt->mnt_parent;
62970+ vfsmnt = &mnt->mnt;
62971+ continue;
62972+ }
62973+ parent = dentry->d_parent;
62974+ prefetch(parent);
62975+ spin_lock(&dentry->d_lock);
62976+ error = prepend_name(buffer, buflen, &dentry->d_name);
62977+ spin_unlock(&dentry->d_lock);
62978+ if (!error)
62979+ error = prepend(buffer, buflen, "/", 1);
62980+ if (error)
62981+ break;
62982+
62983+ slash = true;
62984+ dentry = parent;
62985+ }
62986+
62987+out:
62988+ if (!error && !slash)
62989+ error = prepend(buffer, buflen, "/", 1);
62990+
62991+ return error;
62992+}
62993+
62994+/* this must be called with vfsmount_lock and rename_lock held */
62995+
62996+static char *__our_d_path(const struct path *path, struct path *root,
62997+ char *buf, int buflen)
62998+{
62999+ char *res = buf + buflen;
63000+ int error;
63001+
63002+ prepend(&res, &buflen, "\0", 1);
63003+ error = prepend_path(path, root, &res, &buflen);
63004+ if (error)
63005+ return ERR_PTR(error);
63006+
63007+ return res;
63008+}
63009+
63010+static char *
63011+gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
63012+{
63013+ char *retval;
63014+
63015+ retval = __our_d_path(path, root, buf, buflen);
63016+ if (unlikely(IS_ERR(retval)))
63017+ retval = strcpy(buf, "<path too long>");
63018+ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
63019+ retval[1] = '\0';
63020+
63021+ return retval;
63022+}
63023+
63024+static char *
63025+__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
63026+ char *buf, int buflen)
63027+{
63028+ struct path path;
63029+ char *res;
63030+
63031+ path.dentry = (struct dentry *)dentry;
63032+ path.mnt = (struct vfsmount *)vfsmnt;
63033+
63034+ /* we can use gr_real_root.dentry, gr_real_root.mnt, because this is only called
63035+ by the RBAC system */
63036+ res = gen_full_path(&path, &gr_real_root, buf, buflen);
63037+
63038+ return res;
63039+}
63040+
63041+static char *
63042+d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
63043+ char *buf, int buflen)
63044+{
63045+ char *res;
63046+ struct path path;
63047+ struct path root;
63048+ struct task_struct *reaper = init_pid_ns.child_reaper;
63049+
63050+ path.dentry = (struct dentry *)dentry;
63051+ path.mnt = (struct vfsmount *)vfsmnt;
63052+
63053+ /* we can't use gr_real_root.dentry, gr_real_root.mnt, because they belong only to the RBAC system */
63054+ get_fs_root(reaper->fs, &root);
63055+
63056+ br_read_lock(&vfsmount_lock);
63057+ write_seqlock(&rename_lock);
63058+ res = gen_full_path(&path, &root, buf, buflen);
63059+ write_sequnlock(&rename_lock);
63060+ br_read_unlock(&vfsmount_lock);
63061+
63062+ path_put(&root);
63063+ return res;
63064+}
63065+
63066+char *
63067+gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
63068+{
63069+ char *ret;
63070+ br_read_lock(&vfsmount_lock);
63071+ write_seqlock(&rename_lock);
63072+ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
63073+ PAGE_SIZE);
63074+ write_sequnlock(&rename_lock);
63075+ br_read_unlock(&vfsmount_lock);
63076+ return ret;
63077+}
63078+
63079+static char *
63080+gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
63081+{
63082+ char *ret;
63083+ char *buf;
63084+ int buflen;
63085+
63086+ br_read_lock(&vfsmount_lock);
63087+ write_seqlock(&rename_lock);
63088+ buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
63089+ ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
63090+ buflen = (int)(ret - buf);
63091+ if (buflen >= 5)
63092+ prepend(&ret, &buflen, "/proc", 5);
63093+ else
63094+ ret = strcpy(buf, "<path too long>");
63095+ write_sequnlock(&rename_lock);
63096+ br_read_unlock(&vfsmount_lock);
63097+ return ret;
63098+}
63099+
63100+char *
63101+gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
63102+{
63103+ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
63104+ PAGE_SIZE);
63105+}
63106+
63107+char *
63108+gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
63109+{
63110+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
63111+ PAGE_SIZE);
63112+}
63113+
63114+char *
63115+gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
63116+{
63117+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
63118+ PAGE_SIZE);
63119+}
63120+
63121+char *
63122+gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
63123+{
63124+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
63125+ PAGE_SIZE);
63126+}
63127+
63128+char *
63129+gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
63130+{
63131+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
63132+ PAGE_SIZE);
63133+}
63134+
63135+__inline__ __u32
63136+to_gr_audit(const __u32 reqmode)
63137+{
63138+ /* masks off auditable permission flags, then shifts them to create
63139+ auditing flags, and adds the special case of append auditing if
63140+ we're requesting write */
63141+ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
63142+}
63143+
63144+struct acl_role_label *
63145+__lookup_acl_role_label(const struct gr_policy_state *state, const struct task_struct *task, const uid_t uid,
63146+ const gid_t gid)
63147+{
63148+ unsigned int index = gr_rhash(uid, GR_ROLE_USER, state->acl_role_set.r_size);
63149+ struct acl_role_label *match;
63150+ struct role_allowed_ip *ipp;
63151+ unsigned int x;
63152+ u32 curr_ip = task->signal->saved_ip;
63153+
63154+ match = state->acl_role_set.r_hash[index];
63155+
63156+ while (match) {
63157+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
63158+ for (x = 0; x < match->domain_child_num; x++) {
63159+ if (match->domain_children[x] == uid)
63160+ goto found;
63161+ }
63162+ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
63163+ break;
63164+ match = match->next;
63165+ }
63166+found:
63167+ if (match == NULL) {
63168+ try_group:
63169+ index = gr_rhash(gid, GR_ROLE_GROUP, state->acl_role_set.r_size);
63170+ match = state->acl_role_set.r_hash[index];
63171+
63172+ while (match) {
63173+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
63174+ for (x = 0; x < match->domain_child_num; x++) {
63175+ if (match->domain_children[x] == gid)
63176+ goto found2;
63177+ }
63178+ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
63179+ break;
63180+ match = match->next;
63181+ }
63182+found2:
63183+ if (match == NULL)
63184+ match = state->default_role;
63185+ if (match->allowed_ips == NULL)
63186+ return match;
63187+ else {
63188+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
63189+ if (likely
63190+ ((ntohl(curr_ip) & ipp->netmask) ==
63191+ (ntohl(ipp->addr) & ipp->netmask)))
63192+ return match;
63193+ }
63194+ match = state->default_role;
63195+ }
63196+ } else if (match->allowed_ips == NULL) {
63197+ return match;
63198+ } else {
63199+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
63200+ if (likely
63201+ ((ntohl(curr_ip) & ipp->netmask) ==
63202+ (ntohl(ipp->addr) & ipp->netmask)))
63203+ return match;
63204+ }
63205+ goto try_group;
63206+ }
63207+
63208+ return match;
63209+}
63210+
63211+static struct acl_role_label *
63212+lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
63213+ const gid_t gid)
63214+{
63215+ return __lookup_acl_role_label(&running_polstate, task, uid, gid);
63216+}
63217+
63218+struct acl_subject_label *
63219+lookup_acl_subj_label(const ino_t ino, const dev_t dev,
63220+ const struct acl_role_label *role)
63221+{
63222+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
63223+ struct acl_subject_label *match;
63224+
63225+ match = role->subj_hash[index];
63226+
63227+ while (match && (match->inode != ino || match->device != dev ||
63228+ (match->mode & GR_DELETED))) {
63229+ match = match->next;
63230+ }
63231+
63232+ if (match && !(match->mode & GR_DELETED))
63233+ return match;
63234+ else
63235+ return NULL;
63236+}
63237+
63238+struct acl_subject_label *
63239+lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
63240+ const struct acl_role_label *role)
63241+{
63242+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
63243+ struct acl_subject_label *match;
63244+
63245+ match = role->subj_hash[index];
63246+
63247+ while (match && (match->inode != ino || match->device != dev ||
63248+ !(match->mode & GR_DELETED))) {
63249+ match = match->next;
63250+ }
63251+
63252+ if (match && (match->mode & GR_DELETED))
63253+ return match;
63254+ else
63255+ return NULL;
63256+}
63257+
63258+static struct acl_object_label *
63259+lookup_acl_obj_label(const ino_t ino, const dev_t dev,
63260+ const struct acl_subject_label *subj)
63261+{
63262+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
63263+ struct acl_object_label *match;
63264+
63265+ match = subj->obj_hash[index];
63266+
63267+ while (match && (match->inode != ino || match->device != dev ||
63268+ (match->mode & GR_DELETED))) {
63269+ match = match->next;
63270+ }
63271+
63272+ if (match && !(match->mode & GR_DELETED))
63273+ return match;
63274+ else
63275+ return NULL;
63276+}
63277+
63278+static struct acl_object_label *
63279+lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
63280+ const struct acl_subject_label *subj)
63281+{
63282+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
63283+ struct acl_object_label *match;
63284+
63285+ match = subj->obj_hash[index];
63286+
63287+ while (match && (match->inode != ino || match->device != dev ||
63288+ !(match->mode & GR_DELETED))) {
63289+ match = match->next;
63290+ }
63291+
63292+ if (match && (match->mode & GR_DELETED))
63293+ return match;
63294+
63295+ match = subj->obj_hash[index];
63296+
63297+ while (match && (match->inode != ino || match->device != dev ||
63298+ (match->mode & GR_DELETED))) {
63299+ match = match->next;
63300+ }
63301+
63302+ if (match && !(match->mode & GR_DELETED))
63303+ return match;
63304+ else
63305+ return NULL;
63306+}
63307+
63308+struct name_entry *
63309+__lookup_name_entry(const struct gr_policy_state *state, const char *name)
63310+{
63311+ unsigned int len = strlen(name);
63312+ unsigned int key = full_name_hash(name, len);
63313+ unsigned int index = key % state->name_set.n_size;
63314+ struct name_entry *match;
63315+
63316+ match = state->name_set.n_hash[index];
63317+
63318+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
63319+ match = match->next;
63320+
63321+ return match;
63322+}
63323+
63324+static struct name_entry *
63325+lookup_name_entry(const char *name)
63326+{
63327+ return __lookup_name_entry(&running_polstate, name);
63328+}
63329+
63330+static struct name_entry *
63331+lookup_name_entry_create(const char *name)
63332+{
63333+ unsigned int len = strlen(name);
63334+ unsigned int key = full_name_hash(name, len);
63335+ unsigned int index = key % running_polstate.name_set.n_size;
63336+ struct name_entry *match;
63337+
63338+ match = running_polstate.name_set.n_hash[index];
63339+
63340+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
63341+ !match->deleted))
63342+ match = match->next;
63343+
63344+ if (match && match->deleted)
63345+ return match;
63346+
63347+ match = running_polstate.name_set.n_hash[index];
63348+
63349+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
63350+ match->deleted))
63351+ match = match->next;
63352+
63353+ if (match && !match->deleted)
63354+ return match;
63355+ else
63356+ return NULL;
63357+}
63358+
63359+static struct inodev_entry *
63360+lookup_inodev_entry(const ino_t ino, const dev_t dev)
63361+{
63362+ unsigned int index = gr_fhash(ino, dev, running_polstate.inodev_set.i_size);
63363+ struct inodev_entry *match;
63364+
63365+ match = running_polstate.inodev_set.i_hash[index];
63366+
63367+ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
63368+ match = match->next;
63369+
63370+ return match;
63371+}
63372+
63373+void
63374+__insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry)
63375+{
63376+ unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
63377+ state->inodev_set.i_size);
63378+ struct inodev_entry **curr;
63379+
63380+ entry->prev = NULL;
63381+
63382+ curr = &state->inodev_set.i_hash[index];
63383+ if (*curr != NULL)
63384+ (*curr)->prev = entry;
63385+
63386+ entry->next = *curr;
63387+ *curr = entry;
63388+
63389+ return;
63390+}
63391+
63392+static void
63393+insert_inodev_entry(struct inodev_entry *entry)
63394+{
63395+ __insert_inodev_entry(&running_polstate, entry);
63396+}
63397+
63398+void
63399+insert_acl_obj_label(struct acl_object_label *obj,
63400+ struct acl_subject_label *subj)
63401+{
63402+ unsigned int index =
63403+ gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
63404+ struct acl_object_label **curr;
63405+
63406+ obj->prev = NULL;
63407+
63408+ curr = &subj->obj_hash[index];
63409+ if (*curr != NULL)
63410+ (*curr)->prev = obj;
63411+
63412+ obj->next = *curr;
63413+ *curr = obj;
63414+
63415+ return;
63416+}
63417+
63418+void
63419+insert_acl_subj_label(struct acl_subject_label *obj,
63420+ struct acl_role_label *role)
63421+{
63422+ unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
63423+ struct acl_subject_label **curr;
63424+
63425+ obj->prev = NULL;
63426+
63427+ curr = &role->subj_hash[index];
63428+ if (*curr != NULL)
63429+ (*curr)->prev = obj;
63430+
63431+ obj->next = *curr;
63432+ *curr = obj;
63433+
63434+ return;
63435+}
63436+
63437+/* derived from glibc fnmatch() 0: match, 1: no match*/
63438+
63439+static int
63440+glob_match(const char *p, const char *n)
63441+{
63442+ char c;
63443+
63444+ while ((c = *p++) != '\0') {
63445+ switch (c) {
63446+ case '?':
63447+ if (*n == '\0')
63448+ return 1;
63449+ else if (*n == '/')
63450+ return 1;
63451+ break;
63452+ case '\\':
63453+ if (*n != c)
63454+ return 1;
63455+ break;
63456+ case '*':
63457+ for (c = *p++; c == '?' || c == '*'; c = *p++) {
63458+ if (*n == '/')
63459+ return 1;
63460+ else if (c == '?') {
63461+ if (*n == '\0')
63462+ return 1;
63463+ else
63464+ ++n;
63465+ }
63466+ }
63467+ if (c == '\0') {
63468+ return 0;
63469+ } else {
63470+ const char *endp;
63471+
63472+ if ((endp = strchr(n, '/')) == NULL)
63473+ endp = n + strlen(n);
63474+
63475+ if (c == '[') {
63476+ for (--p; n < endp; ++n)
63477+ if (!glob_match(p, n))
63478+ return 0;
63479+ } else if (c == '/') {
63480+ while (*n != '\0' && *n != '/')
63481+ ++n;
63482+ if (*n == '/' && !glob_match(p, n + 1))
63483+ return 0;
63484+ } else {
63485+ for (--p; n < endp; ++n)
63486+ if (*n == c && !glob_match(p, n))
63487+ return 0;
63488+ }
63489+
63490+ return 1;
63491+ }
63492+ case '[':
63493+ {
63494+ int not;
63495+ char cold;
63496+
63497+ if (*n == '\0' || *n == '/')
63498+ return 1;
63499+
63500+ not = (*p == '!' || *p == '^');
63501+ if (not)
63502+ ++p;
63503+
63504+ c = *p++;
63505+ for (;;) {
63506+ unsigned char fn = (unsigned char)*n;
63507+
63508+ if (c == '\0')
63509+ return 1;
63510+ else {
63511+ if (c == fn)
63512+ goto matched;
63513+ cold = c;
63514+ c = *p++;
63515+
63516+ if (c == '-' && *p != ']') {
63517+ unsigned char cend = *p++;
63518+
63519+ if (cend == '\0')
63520+ return 1;
63521+
63522+ if (cold <= fn && fn <= cend)
63523+ goto matched;
63524+
63525+ c = *p++;
63526+ }
63527+ }
63528+
63529+ if (c == ']')
63530+ break;
63531+ }
63532+ if (!not)
63533+ return 1;
63534+ break;
63535+ matched:
63536+ while (c != ']') {
63537+ if (c == '\0')
63538+ return 1;
63539+
63540+ c = *p++;
63541+ }
63542+ if (not)
63543+ return 1;
63544+ }
63545+ break;
63546+ default:
63547+ if (c != *n)
63548+ return 1;
63549+ }
63550+
63551+ ++n;
63552+ }
63553+
63554+ if (*n == '\0')
63555+ return 0;
63556+
63557+ if (*n == '/')
63558+ return 0;
63559+
63560+ return 1;
63561+}
63562+
63563+static struct acl_object_label *
63564+chk_glob_label(struct acl_object_label *globbed,
63565+ const struct dentry *dentry, const struct vfsmount *mnt, char **path)
63566+{
63567+ struct acl_object_label *tmp;
63568+
63569+ if (*path == NULL)
63570+ *path = gr_to_filename_nolock(dentry, mnt);
63571+
63572+ tmp = globbed;
63573+
63574+ while (tmp) {
63575+ if (!glob_match(tmp->filename, *path))
63576+ return tmp;
63577+ tmp = tmp->next;
63578+ }
63579+
63580+ return NULL;
63581+}
63582+
63583+static struct acl_object_label *
63584+__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
63585+ const ino_t curr_ino, const dev_t curr_dev,
63586+ const struct acl_subject_label *subj, char **path, const int checkglob)
63587+{
63588+ struct acl_subject_label *tmpsubj;
63589+ struct acl_object_label *retval;
63590+ struct acl_object_label *retval2;
63591+
63592+ tmpsubj = (struct acl_subject_label *) subj;
63593+ read_lock(&gr_inode_lock);
63594+ do {
63595+ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
63596+ if (retval) {
63597+ if (checkglob && retval->globbed) {
63598+ retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
63599+ if (retval2)
63600+ retval = retval2;
63601+ }
63602+ break;
63603+ }
63604+ } while ((tmpsubj = tmpsubj->parent_subject));
63605+ read_unlock(&gr_inode_lock);
63606+
63607+ return retval;
63608+}
63609+
63610+static __inline__ struct acl_object_label *
63611+full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
63612+ struct dentry *curr_dentry,
63613+ const struct acl_subject_label *subj, char **path, const int checkglob)
63614+{
63615+ int newglob = checkglob;
63616+ ino_t inode;
63617+ dev_t device;
63618+
63619+ /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
63620+ as we don't want a / * rule to match instead of the / object
63621+ don't do this for create lookups that call this function though, since they're looking up
63622+ on the parent and thus need globbing checks on all paths
63623+ */
63624+ if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
63625+ newglob = GR_NO_GLOB;
63626+
63627+ spin_lock(&curr_dentry->d_lock);
63628+ inode = curr_dentry->d_inode->i_ino;
63629+ device = __get_dev(curr_dentry);
63630+ spin_unlock(&curr_dentry->d_lock);
63631+
63632+ return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
63633+}
63634+
63635+#ifdef CONFIG_HUGETLBFS
63636+static inline bool
63637+is_hugetlbfs_mnt(const struct vfsmount *mnt)
63638+{
63639+ int i;
63640+ for (i = 0; i < HUGE_MAX_HSTATE; i++) {
63641+ if (unlikely(hugetlbfs_vfsmount[i] == mnt))
63642+ return true;
63643+ }
63644+
63645+ return false;
63646+}
63647+#endif
63648+
63649+static struct acl_object_label *
63650+__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
63651+ const struct acl_subject_label *subj, char *path, const int checkglob)
63652+{
63653+ struct dentry *dentry = (struct dentry *) l_dentry;
63654+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
63655+ struct mount *real_mnt = real_mount(mnt);
63656+ struct acl_object_label *retval;
63657+ struct dentry *parent;
63658+
63659+ br_read_lock(&vfsmount_lock);
63660+ write_seqlock(&rename_lock);
63661+
63662+ if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
63663+#ifdef CONFIG_NET
63664+ mnt == sock_mnt ||
63665+#endif
63666+#ifdef CONFIG_HUGETLBFS
63667+ (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
63668+#endif
63669+ /* ignore Eric Biederman */
63670+ IS_PRIVATE(l_dentry->d_inode))) {
63671+ retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
63672+ goto out;
63673+ }
63674+
63675+ for (;;) {
63676+ if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
63677+ break;
63678+
63679+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
63680+ if (!mnt_has_parent(real_mnt))
63681+ break;
63682+
63683+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
63684+ if (retval != NULL)
63685+ goto out;
63686+
63687+ dentry = real_mnt->mnt_mountpoint;
63688+ real_mnt = real_mnt->mnt_parent;
63689+ mnt = &real_mnt->mnt;
63690+ continue;
63691+ }
63692+
63693+ parent = dentry->d_parent;
63694+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
63695+ if (retval != NULL)
63696+ goto out;
63697+
63698+ dentry = parent;
63699+ }
63700+
63701+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
63702+
63703+ /* gr_real_root is pinned so we don't have to hold a reference */
63704+ if (retval == NULL)
63705+ retval = full_lookup(l_dentry, l_mnt, gr_real_root.dentry, subj, &path, checkglob);
63706+out:
63707+ write_sequnlock(&rename_lock);
63708+ br_read_unlock(&vfsmount_lock);
63709+
63710+ BUG_ON(retval == NULL);
63711+
63712+ return retval;
63713+}
63714+
63715+static __inline__ struct acl_object_label *
63716+chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
63717+ const struct acl_subject_label *subj)
63718+{
63719+ char *path = NULL;
63720+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
63721+}
63722+
63723+static __inline__ struct acl_object_label *
63724+chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
63725+ const struct acl_subject_label *subj)
63726+{
63727+ char *path = NULL;
63728+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
63729+}
63730+
63731+static __inline__ struct acl_object_label *
63732+chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
63733+ const struct acl_subject_label *subj, char *path)
63734+{
63735+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
63736+}
63737+
63738+struct acl_subject_label *
63739+chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
63740+ const struct acl_role_label *role)
63741+{
63742+ struct dentry *dentry = (struct dentry *) l_dentry;
63743+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
63744+ struct mount *real_mnt = real_mount(mnt);
63745+ struct acl_subject_label *retval;
63746+ struct dentry *parent;
63747+
63748+ br_read_lock(&vfsmount_lock);
63749+ write_seqlock(&rename_lock);
63750+
63751+ for (;;) {
63752+ if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
63753+ break;
63754+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
63755+ if (!mnt_has_parent(real_mnt))
63756+ break;
63757+
63758+ spin_lock(&dentry->d_lock);
63759+ read_lock(&gr_inode_lock);
63760+ retval =
63761+ lookup_acl_subj_label(dentry->d_inode->i_ino,
63762+ __get_dev(dentry), role);
63763+ read_unlock(&gr_inode_lock);
63764+ spin_unlock(&dentry->d_lock);
63765+ if (retval != NULL)
63766+ goto out;
63767+
63768+ dentry = real_mnt->mnt_mountpoint;
63769+ real_mnt = real_mnt->mnt_parent;
63770+ mnt = &real_mnt->mnt;
63771+ continue;
63772+ }
63773+
63774+ spin_lock(&dentry->d_lock);
63775+ read_lock(&gr_inode_lock);
63776+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
63777+ __get_dev(dentry), role);
63778+ read_unlock(&gr_inode_lock);
63779+ parent = dentry->d_parent;
63780+ spin_unlock(&dentry->d_lock);
63781+
63782+ if (retval != NULL)
63783+ goto out;
63784+
63785+ dentry = parent;
63786+ }
63787+
63788+ spin_lock(&dentry->d_lock);
63789+ read_lock(&gr_inode_lock);
63790+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
63791+ __get_dev(dentry), role);
63792+ read_unlock(&gr_inode_lock);
63793+ spin_unlock(&dentry->d_lock);
63794+
63795+ if (unlikely(retval == NULL)) {
63796+ /* gr_real_root is pinned, we don't need to hold a reference */
63797+ read_lock(&gr_inode_lock);
63798+ retval = lookup_acl_subj_label(gr_real_root.dentry->d_inode->i_ino,
63799+ __get_dev(gr_real_root.dentry), role);
63800+ read_unlock(&gr_inode_lock);
63801+ }
63802+out:
63803+ write_sequnlock(&rename_lock);
63804+ br_read_unlock(&vfsmount_lock);
63805+
63806+ BUG_ON(retval == NULL);
63807+
63808+ return retval;
63809+}
63810+
63811+void
63812+assign_special_role(const char *rolename)
63813+{
63814+ struct acl_object_label *obj;
63815+ struct acl_role_label *r;
63816+ struct acl_role_label *assigned = NULL;
63817+ struct task_struct *tsk;
63818+ struct file *filp;
63819+
63820+ FOR_EACH_ROLE_START(r)
63821+ if (!strcmp(rolename, r->rolename) &&
63822+ (r->roletype & GR_ROLE_SPECIAL)) {
63823+ assigned = r;
63824+ break;
63825+ }
63826+ FOR_EACH_ROLE_END(r)
63827+
63828+ if (!assigned)
63829+ return;
63830+
63831+ read_lock(&tasklist_lock);
63832+ read_lock(&grsec_exec_file_lock);
63833+
63834+ tsk = current->real_parent;
63835+ if (tsk == NULL)
63836+ goto out_unlock;
63837+
63838+ filp = tsk->exec_file;
63839+ if (filp == NULL)
63840+ goto out_unlock;
63841+
63842+ tsk->is_writable = 0;
63843+ tsk->inherited = 0;
63844+
63845+ tsk->acl_sp_role = 1;
63846+ tsk->acl_role_id = ++acl_sp_role_value;
63847+ tsk->role = assigned;
63848+ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
63849+
63850+ /* ignore additional mmap checks for processes that are writable
63851+ by the default ACL */
63852+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
63853+ if (unlikely(obj->mode & GR_WRITE))
63854+ tsk->is_writable = 1;
63855+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
63856+ if (unlikely(obj->mode & GR_WRITE))
63857+ tsk->is_writable = 1;
63858+
63859+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
63860+ printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename,
63861+ tsk->acl->filename, tsk->comm, task_pid_nr(tsk));
63862+#endif
63863+
63864+out_unlock:
63865+ read_unlock(&grsec_exec_file_lock);
63866+ read_unlock(&tasklist_lock);
63867+ return;
63868+}
63869+
63870+
63871+static void
63872+gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
63873+{
63874+ struct task_struct *task = current;
63875+ const struct cred *cred = current_cred();
63876+
63877+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
63878+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
63879+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
63880+ 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
63881+
63882+ return;
63883+}
63884+
63885+static void
63886+gr_log_learn_uid_change(const kuid_t real, const kuid_t effective, const kuid_t fs)
63887+{
63888+ struct task_struct *task = current;
63889+ const struct cred *cred = current_cred();
63890+
63891+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
63892+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
63893+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
63894+ 'u', GR_GLOBAL_UID(real), GR_GLOBAL_UID(effective), GR_GLOBAL_UID(fs), &task->signal->saved_ip);
63895+
63896+ return;
63897+}
63898+
63899+static void
63900+gr_log_learn_gid_change(const kgid_t real, const kgid_t effective, const kgid_t fs)
63901+{
63902+ struct task_struct *task = current;
63903+ const struct cred *cred = current_cred();
63904+
63905+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
63906+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
63907+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
63908+ 'g', GR_GLOBAL_GID(real), GR_GLOBAL_GID(effective), GR_GLOBAL_GID(fs), &task->signal->saved_ip);
63909+
63910+ return;
63911+}
63912+
63913+static void
63914+gr_set_proc_res(struct task_struct *task)
63915+{
63916+ struct acl_subject_label *proc;
63917+ unsigned short i;
63918+
63919+ proc = task->acl;
63920+
63921+ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
63922+ return;
63923+
63924+ for (i = 0; i < RLIM_NLIMITS; i++) {
63925+ if (!(proc->resmask & (1U << i)))
63926+ continue;
63927+
63928+ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
63929+ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
63930+
63931+ if (i == RLIMIT_CPU)
63932+ update_rlimit_cpu(task, proc->res[i].rlim_cur);
63933+ }
63934+
63935+ return;
63936+}
63937+
63938+/* both of the below must be called with
63939+ rcu_read_lock();
63940+ read_lock(&tasklist_lock);
63941+ read_lock(&grsec_exec_file_lock);
63942+*/
63943+
63944+void __gr_apply_subject_to_task(const struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj)
63945+{
63946+ struct acl_object_label *obj;
63947+ struct file *filp;
63948+
63949+ filp = task->exec_file;
63950+
63951+ task->acl = subj;
63952+ task->is_writable = 0;
63953+ /* ignore additional mmap checks for processes that are writable
63954+ by the default ACL */
63955+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, state->default_role->root_label);
63956+ if (unlikely(obj->mode & GR_WRITE))
63957+ task->is_writable = 1;
63958+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
63959+ if (unlikely(obj->mode & GR_WRITE))
63960+ task->is_writable = 1;
63961+
63962+ gr_set_proc_res(task);
63963+
63964+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
63965+ 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);
63966+#endif
63967+}
63968+
63969+static void gr_apply_subject_to_task(struct task_struct *task, struct acl_subject_label *subj)
63970+{
63971+ __gr_apply_subject_to_task(&running_polstate, task, subj);
63972+}
63973+
63974+__u32
63975+gr_search_file(const struct dentry * dentry, const __u32 mode,
63976+ const struct vfsmount * mnt)
63977+{
63978+ __u32 retval = mode;
63979+ struct acl_subject_label *curracl;
63980+ struct acl_object_label *currobj;
63981+
63982+ if (unlikely(!(gr_status & GR_READY)))
63983+ return (mode & ~GR_AUDITS);
63984+
63985+ curracl = current->acl;
63986+
63987+ currobj = chk_obj_label(dentry, mnt, curracl);
63988+ retval = currobj->mode & mode;
63989+
63990+ /* if we're opening a specified transfer file for writing
63991+ (e.g. /dev/initctl), then transfer our role to init
63992+ */
63993+ if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
63994+ current->role->roletype & GR_ROLE_PERSIST)) {
63995+ struct task_struct *task = init_pid_ns.child_reaper;
63996+
63997+ if (task->role != current->role) {
63998+ task->acl_sp_role = 0;
63999+ task->acl_role_id = current->acl_role_id;
64000+ task->role = current->role;
64001+ rcu_read_lock();
64002+ read_lock(&grsec_exec_file_lock);
64003+ gr_apply_subject_to_task(task, NULL);
64004+ read_unlock(&grsec_exec_file_lock);
64005+ rcu_read_unlock();
64006+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
64007+ }
64008+ }
64009+
64010+ if (unlikely
64011+ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
64012+ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
64013+ __u32 new_mode = mode;
64014+
64015+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
64016+
64017+ retval = new_mode;
64018+
64019+ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
64020+ new_mode |= GR_INHERIT;
64021+
64022+ if (!(mode & GR_NOLEARN))
64023+ gr_log_learn(dentry, mnt, new_mode);
64024+ }
64025+
64026+ return retval;
64027+}
64028+
64029+struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
64030+ const struct dentry *parent,
64031+ const struct vfsmount *mnt)
64032+{
64033+ struct name_entry *match;
64034+ struct acl_object_label *matchpo;
64035+ struct acl_subject_label *curracl;
64036+ char *path;
64037+
64038+ if (unlikely(!(gr_status & GR_READY)))
64039+ return NULL;
64040+
64041+ preempt_disable();
64042+ path = gr_to_filename_rbac(new_dentry, mnt);
64043+ match = lookup_name_entry_create(path);
64044+
64045+ curracl = current->acl;
64046+
64047+ if (match) {
64048+ read_lock(&gr_inode_lock);
64049+ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
64050+ read_unlock(&gr_inode_lock);
64051+
64052+ if (matchpo) {
64053+ preempt_enable();
64054+ return matchpo;
64055+ }
64056+ }
64057+
64058+ // lookup parent
64059+
64060+ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
64061+
64062+ preempt_enable();
64063+ return matchpo;
64064+}
64065+
64066+__u32
64067+gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
64068+ const struct vfsmount * mnt, const __u32 mode)
64069+{
64070+ struct acl_object_label *matchpo;
64071+ __u32 retval;
64072+
64073+ if (unlikely(!(gr_status & GR_READY)))
64074+ return (mode & ~GR_AUDITS);
64075+
64076+ matchpo = gr_get_create_object(new_dentry, parent, mnt);
64077+
64078+ retval = matchpo->mode & mode;
64079+
64080+ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
64081+ && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
64082+ __u32 new_mode = mode;
64083+
64084+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
64085+
64086+ gr_log_learn(new_dentry, mnt, new_mode);
64087+ return new_mode;
64088+ }
64089+
64090+ return retval;
64091+}
64092+
64093+__u32
64094+gr_check_link(const struct dentry * new_dentry,
64095+ const struct dentry * parent_dentry,
64096+ const struct vfsmount * parent_mnt,
64097+ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
64098+{
64099+ struct acl_object_label *obj;
64100+ __u32 oldmode, newmode;
64101+ __u32 needmode;
64102+ __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
64103+ GR_DELETE | GR_INHERIT;
64104+
64105+ if (unlikely(!(gr_status & GR_READY)))
64106+ return (GR_CREATE | GR_LINK);
64107+
64108+ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
64109+ oldmode = obj->mode;
64110+
64111+ obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
64112+ newmode = obj->mode;
64113+
64114+ needmode = newmode & checkmodes;
64115+
64116+ // old name for hardlink must have at least the permissions of the new name
64117+ if ((oldmode & needmode) != needmode)
64118+ goto bad;
64119+
64120+ // if old name had restrictions/auditing, make sure the new name does as well
64121+ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
64122+
64123+ // don't allow hardlinking of suid/sgid/fcapped files without permission
64124+ if (is_privileged_binary(old_dentry))
64125+ needmode |= GR_SETID;
64126+
64127+ if ((newmode & needmode) != needmode)
64128+ goto bad;
64129+
64130+ // enforce minimum permissions
64131+ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
64132+ return newmode;
64133+bad:
64134+ needmode = oldmode;
64135+ if (is_privileged_binary(old_dentry))
64136+ needmode |= GR_SETID;
64137+
64138+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
64139+ gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
64140+ return (GR_CREATE | GR_LINK);
64141+ } else if (newmode & GR_SUPPRESS)
64142+ return GR_SUPPRESS;
64143+ else
64144+ return 0;
64145+}
64146+
64147+int
64148+gr_check_hidden_task(const struct task_struct *task)
64149+{
64150+ if (unlikely(!(gr_status & GR_READY)))
64151+ return 0;
64152+
64153+ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
64154+ return 1;
64155+
64156+ return 0;
64157+}
64158+
64159+int
64160+gr_check_protected_task(const struct task_struct *task)
64161+{
64162+ if (unlikely(!(gr_status & GR_READY) || !task))
64163+ return 0;
64164+
64165+ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
64166+ task->acl != current->acl)
64167+ return 1;
64168+
64169+ return 0;
64170+}
64171+
64172+int
64173+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
64174+{
64175+ struct task_struct *p;
64176+ int ret = 0;
64177+
64178+ if (unlikely(!(gr_status & GR_READY) || !pid))
64179+ return ret;
64180+
64181+ read_lock(&tasklist_lock);
64182+ do_each_pid_task(pid, type, p) {
64183+ if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
64184+ p->acl != current->acl) {
64185+ ret = 1;
64186+ goto out;
64187+ }
64188+ } while_each_pid_task(pid, type, p);
64189+out:
64190+ read_unlock(&tasklist_lock);
64191+
64192+ return ret;
64193+}
64194+
64195+void
64196+gr_copy_label(struct task_struct *tsk)
64197+{
64198+ struct task_struct *p = current;
64199+
64200+ tsk->inherited = p->inherited;
64201+ tsk->acl_sp_role = 0;
64202+ tsk->acl_role_id = p->acl_role_id;
64203+ tsk->acl = p->acl;
64204+ tsk->role = p->role;
64205+ tsk->signal->used_accept = 0;
64206+ tsk->signal->curr_ip = p->signal->curr_ip;
64207+ tsk->signal->saved_ip = p->signal->saved_ip;
64208+ if (p->exec_file)
64209+ get_file(p->exec_file);
64210+ tsk->exec_file = p->exec_file;
64211+ tsk->is_writable = p->is_writable;
64212+ if (unlikely(p->signal->used_accept)) {
64213+ p->signal->curr_ip = 0;
64214+ p->signal->saved_ip = 0;
64215+ }
64216+
64217+ return;
64218+}
64219+
64220+extern int gr_process_kernel_setuid_ban(struct user_struct *user);
64221+
64222+int
64223+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
64224+{
64225+ unsigned int i;
64226+ __u16 num;
64227+ uid_t *uidlist;
64228+ uid_t curuid;
64229+ int realok = 0;
64230+ int effectiveok = 0;
64231+ int fsok = 0;
64232+ uid_t globalreal, globaleffective, globalfs;
64233+
64234+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT)
64235+ struct user_struct *user;
64236+
64237+ if (!uid_valid(real))
64238+ goto skipit;
64239+
64240+ /* find user based on global namespace */
64241+
64242+ globalreal = GR_GLOBAL_UID(real);
64243+
64244+ user = find_user(make_kuid(&init_user_ns, globalreal));
64245+ if (user == NULL)
64246+ goto skipit;
64247+
64248+ if (gr_process_kernel_setuid_ban(user)) {
64249+ /* for find_user */
64250+ free_uid(user);
64251+ return 1;
64252+ }
64253+
64254+ /* for find_user */
64255+ free_uid(user);
64256+
64257+skipit:
64258+#endif
64259+
64260+ if (unlikely(!(gr_status & GR_READY)))
64261+ return 0;
64262+
64263+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
64264+ gr_log_learn_uid_change(real, effective, fs);
64265+
64266+ num = current->acl->user_trans_num;
64267+ uidlist = current->acl->user_transitions;
64268+
64269+ if (uidlist == NULL)
64270+ return 0;
64271+
64272+ if (!uid_valid(real)) {
64273+ realok = 1;
64274+ globalreal = (uid_t)-1;
64275+ } else {
64276+ globalreal = GR_GLOBAL_UID(real);
64277+ }
64278+ if (!uid_valid(effective)) {
64279+ effectiveok = 1;
64280+ globaleffective = (uid_t)-1;
64281+ } else {
64282+ globaleffective = GR_GLOBAL_UID(effective);
64283+ }
64284+ if (!uid_valid(fs)) {
64285+ fsok = 1;
64286+ globalfs = (uid_t)-1;
64287+ } else {
64288+ globalfs = GR_GLOBAL_UID(fs);
64289+ }
64290+
64291+ if (current->acl->user_trans_type & GR_ID_ALLOW) {
64292+ for (i = 0; i < num; i++) {
64293+ curuid = uidlist[i];
64294+ if (globalreal == curuid)
64295+ realok = 1;
64296+ if (globaleffective == curuid)
64297+ effectiveok = 1;
64298+ if (globalfs == curuid)
64299+ fsok = 1;
64300+ }
64301+ } else if (current->acl->user_trans_type & GR_ID_DENY) {
64302+ for (i = 0; i < num; i++) {
64303+ curuid = uidlist[i];
64304+ if (globalreal == curuid)
64305+ break;
64306+ if (globaleffective == curuid)
64307+ break;
64308+ if (globalfs == curuid)
64309+ break;
64310+ }
64311+ /* not in deny list */
64312+ if (i == num) {
64313+ realok = 1;
64314+ effectiveok = 1;
64315+ fsok = 1;
64316+ }
64317+ }
64318+
64319+ if (realok && effectiveok && fsok)
64320+ return 0;
64321+ else {
64322+ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
64323+ return 1;
64324+ }
64325+}
64326+
64327+int
64328+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
64329+{
64330+ unsigned int i;
64331+ __u16 num;
64332+ gid_t *gidlist;
64333+ gid_t curgid;
64334+ int realok = 0;
64335+ int effectiveok = 0;
64336+ int fsok = 0;
64337+ gid_t globalreal, globaleffective, globalfs;
64338+
64339+ if (unlikely(!(gr_status & GR_READY)))
64340+ return 0;
64341+
64342+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
64343+ gr_log_learn_gid_change(real, effective, fs);
64344+
64345+ num = current->acl->group_trans_num;
64346+ gidlist = current->acl->group_transitions;
64347+
64348+ if (gidlist == NULL)
64349+ return 0;
64350+
64351+ if (!gid_valid(real)) {
64352+ realok = 1;
64353+ globalreal = (gid_t)-1;
64354+ } else {
64355+ globalreal = GR_GLOBAL_GID(real);
64356+ }
64357+ if (!gid_valid(effective)) {
64358+ effectiveok = 1;
64359+ globaleffective = (gid_t)-1;
64360+ } else {
64361+ globaleffective = GR_GLOBAL_GID(effective);
64362+ }
64363+ if (!gid_valid(fs)) {
64364+ fsok = 1;
64365+ globalfs = (gid_t)-1;
64366+ } else {
64367+ globalfs = GR_GLOBAL_GID(fs);
64368+ }
64369+
64370+ if (current->acl->group_trans_type & GR_ID_ALLOW) {
64371+ for (i = 0; i < num; i++) {
64372+ curgid = gidlist[i];
64373+ if (globalreal == curgid)
64374+ realok = 1;
64375+ if (globaleffective == curgid)
64376+ effectiveok = 1;
64377+ if (globalfs == curgid)
64378+ fsok = 1;
64379+ }
64380+ } else if (current->acl->group_trans_type & GR_ID_DENY) {
64381+ for (i = 0; i < num; i++) {
64382+ curgid = gidlist[i];
64383+ if (globalreal == curgid)
64384+ break;
64385+ if (globaleffective == curgid)
64386+ break;
64387+ if (globalfs == curgid)
64388+ break;
64389+ }
64390+ /* not in deny list */
64391+ if (i == num) {
64392+ realok = 1;
64393+ effectiveok = 1;
64394+ fsok = 1;
64395+ }
64396+ }
64397+
64398+ if (realok && effectiveok && fsok)
64399+ return 0;
64400+ else {
64401+ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
64402+ return 1;
64403+ }
64404+}
64405+
64406+extern int gr_acl_is_capable(const int cap);
64407+
64408+void
64409+gr_set_role_label(struct task_struct *task, const kuid_t kuid, const kgid_t kgid)
64410+{
64411+ struct acl_role_label *role = task->role;
64412+ struct acl_subject_label *subj = NULL;
64413+ struct acl_object_label *obj;
64414+ struct file *filp;
64415+ uid_t uid;
64416+ gid_t gid;
64417+
64418+ if (unlikely(!(gr_status & GR_READY)))
64419+ return;
64420+
64421+ uid = GR_GLOBAL_UID(kuid);
64422+ gid = GR_GLOBAL_GID(kgid);
64423+
64424+ filp = task->exec_file;
64425+
64426+ /* kernel process, we'll give them the kernel role */
64427+ if (unlikely(!filp)) {
64428+ task->role = running_polstate.kernel_role;
64429+ task->acl = running_polstate.kernel_role->root_label;
64430+ return;
64431+ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL)) {
64432+ /* save the current ip at time of role lookup so that the proper
64433+ IP will be learned for role_allowed_ip */
64434+ task->signal->saved_ip = task->signal->curr_ip;
64435+ role = lookup_acl_role_label(task, uid, gid);
64436+ }
64437+
64438+ /* don't change the role if we're not a privileged process */
64439+ if (role && task->role != role &&
64440+ (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
64441+ ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
64442+ return;
64443+
64444+ /* perform subject lookup in possibly new role
64445+ we can use this result below in the case where role == task->role
64446+ */
64447+ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
64448+
64449+ /* if we changed uid/gid, but result in the same role
64450+ and are using inheritance, don't lose the inherited subject
64451+ if current subject is other than what normal lookup
64452+ would result in, we arrived via inheritance, don't
64453+ lose subject
64454+ */
64455+ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
64456+ (subj == task->acl)))
64457+ task->acl = subj;
64458+
64459+ /* leave task->inherited unaffected */
64460+
64461+ task->role = role;
64462+
64463+ task->is_writable = 0;
64464+
64465+ /* ignore additional mmap checks for processes that are writable
64466+ by the default ACL */
64467+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
64468+ if (unlikely(obj->mode & GR_WRITE))
64469+ task->is_writable = 1;
64470+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
64471+ if (unlikely(obj->mode & GR_WRITE))
64472+ task->is_writable = 1;
64473+
64474+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
64475+ 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);
64476+#endif
64477+
64478+ gr_set_proc_res(task);
64479+
64480+ return;
64481+}
64482+
64483+int
64484+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
64485+ const int unsafe_flags)
64486+{
64487+ struct task_struct *task = current;
64488+ struct acl_subject_label *newacl;
64489+ struct acl_object_label *obj;
64490+ __u32 retmode;
64491+
64492+ if (unlikely(!(gr_status & GR_READY)))
64493+ return 0;
64494+
64495+ newacl = chk_subj_label(dentry, mnt, task->role);
64496+
64497+ /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
64498+ did an exec
64499+ */
64500+ rcu_read_lock();
64501+ read_lock(&tasklist_lock);
64502+ if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
64503+ (task->parent->acl->mode & GR_POVERRIDE))) {
64504+ read_unlock(&tasklist_lock);
64505+ rcu_read_unlock();
64506+ goto skip_check;
64507+ }
64508+ read_unlock(&tasklist_lock);
64509+ rcu_read_unlock();
64510+
64511+ if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
64512+ !(task->role->roletype & GR_ROLE_GOD) &&
64513+ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
64514+ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
64515+ if (unsafe_flags & LSM_UNSAFE_SHARE)
64516+ gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
64517+ else
64518+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
64519+ return -EACCES;
64520+ }
64521+
64522+skip_check:
64523+
64524+ obj = chk_obj_label(dentry, mnt, task->acl);
64525+ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
64526+
64527+ if (!(task->acl->mode & GR_INHERITLEARN) &&
64528+ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
64529+ if (obj->nested)
64530+ task->acl = obj->nested;
64531+ else
64532+ task->acl = newacl;
64533+ task->inherited = 0;
64534+ } else {
64535+ task->inherited = 1;
64536+ if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
64537+ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
64538+ }
64539+
64540+ task->is_writable = 0;
64541+
64542+ /* ignore additional mmap checks for processes that are writable
64543+ by the default ACL */
64544+ obj = chk_obj_label(dentry, mnt, running_polstate.default_role->root_label);
64545+ if (unlikely(obj->mode & GR_WRITE))
64546+ task->is_writable = 1;
64547+ obj = chk_obj_label(dentry, mnt, task->role->root_label);
64548+ if (unlikely(obj->mode & GR_WRITE))
64549+ task->is_writable = 1;
64550+
64551+ gr_set_proc_res(task);
64552+
64553+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
64554+ 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);
64555+#endif
64556+ return 0;
64557+}
64558+
64559+/* always called with valid inodev ptr */
64560+static void
64561+do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
64562+{
64563+ struct acl_object_label *matchpo;
64564+ struct acl_subject_label *matchps;
64565+ struct acl_subject_label *subj;
64566+ struct acl_role_label *role;
64567+ unsigned int x;
64568+
64569+ FOR_EACH_ROLE_START(role)
64570+ FOR_EACH_SUBJECT_START(role, subj, x)
64571+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
64572+ matchpo->mode |= GR_DELETED;
64573+ FOR_EACH_SUBJECT_END(subj,x)
64574+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
64575+ /* nested subjects aren't in the role's subj_hash table */
64576+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
64577+ matchpo->mode |= GR_DELETED;
64578+ FOR_EACH_NESTED_SUBJECT_END(subj)
64579+ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
64580+ matchps->mode |= GR_DELETED;
64581+ FOR_EACH_ROLE_END(role)
64582+
64583+ inodev->nentry->deleted = 1;
64584+
64585+ return;
64586+}
64587+
64588+void
64589+gr_handle_delete(const ino_t ino, const dev_t dev)
64590+{
64591+ struct inodev_entry *inodev;
64592+
64593+ if (unlikely(!(gr_status & GR_READY)))
64594+ return;
64595+
64596+ write_lock(&gr_inode_lock);
64597+ inodev = lookup_inodev_entry(ino, dev);
64598+ if (inodev != NULL)
64599+ do_handle_delete(inodev, ino, dev);
64600+ write_unlock(&gr_inode_lock);
64601+
64602+ return;
64603+}
64604+
64605+static void
64606+update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
64607+ const ino_t newinode, const dev_t newdevice,
64608+ struct acl_subject_label *subj)
64609+{
64610+ unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
64611+ struct acl_object_label *match;
64612+
64613+ match = subj->obj_hash[index];
64614+
64615+ while (match && (match->inode != oldinode ||
64616+ match->device != olddevice ||
64617+ !(match->mode & GR_DELETED)))
64618+ match = match->next;
64619+
64620+ if (match && (match->inode == oldinode)
64621+ && (match->device == olddevice)
64622+ && (match->mode & GR_DELETED)) {
64623+ if (match->prev == NULL) {
64624+ subj->obj_hash[index] = match->next;
64625+ if (match->next != NULL)
64626+ match->next->prev = NULL;
64627+ } else {
64628+ match->prev->next = match->next;
64629+ if (match->next != NULL)
64630+ match->next->prev = match->prev;
64631+ }
64632+ match->prev = NULL;
64633+ match->next = NULL;
64634+ match->inode = newinode;
64635+ match->device = newdevice;
64636+ match->mode &= ~GR_DELETED;
64637+
64638+ insert_acl_obj_label(match, subj);
64639+ }
64640+
64641+ return;
64642+}
64643+
64644+static void
64645+update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
64646+ const ino_t newinode, const dev_t newdevice,
64647+ struct acl_role_label *role)
64648+{
64649+ unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
64650+ struct acl_subject_label *match;
64651+
64652+ match = role->subj_hash[index];
64653+
64654+ while (match && (match->inode != oldinode ||
64655+ match->device != olddevice ||
64656+ !(match->mode & GR_DELETED)))
64657+ match = match->next;
64658+
64659+ if (match && (match->inode == oldinode)
64660+ && (match->device == olddevice)
64661+ && (match->mode & GR_DELETED)) {
64662+ if (match->prev == NULL) {
64663+ role->subj_hash[index] = match->next;
64664+ if (match->next != NULL)
64665+ match->next->prev = NULL;
64666+ } else {
64667+ match->prev->next = match->next;
64668+ if (match->next != NULL)
64669+ match->next->prev = match->prev;
64670+ }
64671+ match->prev = NULL;
64672+ match->next = NULL;
64673+ match->inode = newinode;
64674+ match->device = newdevice;
64675+ match->mode &= ~GR_DELETED;
64676+
64677+ insert_acl_subj_label(match, role);
64678+ }
64679+
64680+ return;
64681+}
64682+
64683+static void
64684+update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
64685+ const ino_t newinode, const dev_t newdevice)
64686+{
64687+ unsigned int index = gr_fhash(oldinode, olddevice, running_polstate.inodev_set.i_size);
64688+ struct inodev_entry *match;
64689+
64690+ match = running_polstate.inodev_set.i_hash[index];
64691+
64692+ while (match && (match->nentry->inode != oldinode ||
64693+ match->nentry->device != olddevice || !match->nentry->deleted))
64694+ match = match->next;
64695+
64696+ if (match && (match->nentry->inode == oldinode)
64697+ && (match->nentry->device == olddevice) &&
64698+ match->nentry->deleted) {
64699+ if (match->prev == NULL) {
64700+ running_polstate.inodev_set.i_hash[index] = match->next;
64701+ if (match->next != NULL)
64702+ match->next->prev = NULL;
64703+ } else {
64704+ match->prev->next = match->next;
64705+ if (match->next != NULL)
64706+ match->next->prev = match->prev;
64707+ }
64708+ match->prev = NULL;
64709+ match->next = NULL;
64710+ match->nentry->inode = newinode;
64711+ match->nentry->device = newdevice;
64712+ match->nentry->deleted = 0;
64713+
64714+ insert_inodev_entry(match);
64715+ }
64716+
64717+ return;
64718+}
64719+
64720+static void
64721+__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
64722+{
64723+ struct acl_subject_label *subj;
64724+ struct acl_role_label *role;
64725+ unsigned int x;
64726+
64727+ FOR_EACH_ROLE_START(role)
64728+ update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
64729+
64730+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
64731+ if ((subj->inode == ino) && (subj->device == dev)) {
64732+ subj->inode = ino;
64733+ subj->device = dev;
64734+ }
64735+ /* nested subjects aren't in the role's subj_hash table */
64736+ update_acl_obj_label(matchn->inode, matchn->device,
64737+ ino, dev, subj);
64738+ FOR_EACH_NESTED_SUBJECT_END(subj)
64739+ FOR_EACH_SUBJECT_START(role, subj, x)
64740+ update_acl_obj_label(matchn->inode, matchn->device,
64741+ ino, dev, subj);
64742+ FOR_EACH_SUBJECT_END(subj,x)
64743+ FOR_EACH_ROLE_END(role)
64744+
64745+ update_inodev_entry(matchn->inode, matchn->device, ino, dev);
64746+
64747+ return;
64748+}
64749+
64750+static void
64751+do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
64752+ const struct vfsmount *mnt)
64753+{
64754+ ino_t ino = dentry->d_inode->i_ino;
64755+ dev_t dev = __get_dev(dentry);
64756+
64757+ __do_handle_create(matchn, ino, dev);
64758+
64759+ return;
64760+}
64761+
64762+void
64763+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
64764+{
64765+ struct name_entry *matchn;
64766+
64767+ if (unlikely(!(gr_status & GR_READY)))
64768+ return;
64769+
64770+ preempt_disable();
64771+ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
64772+
64773+ if (unlikely((unsigned long)matchn)) {
64774+ write_lock(&gr_inode_lock);
64775+ do_handle_create(matchn, dentry, mnt);
64776+ write_unlock(&gr_inode_lock);
64777+ }
64778+ preempt_enable();
64779+
64780+ return;
64781+}
64782+
64783+void
64784+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
64785+{
64786+ struct name_entry *matchn;
64787+
64788+ if (unlikely(!(gr_status & GR_READY)))
64789+ return;
64790+
64791+ preempt_disable();
64792+ matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
64793+
64794+ if (unlikely((unsigned long)matchn)) {
64795+ write_lock(&gr_inode_lock);
64796+ __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
64797+ write_unlock(&gr_inode_lock);
64798+ }
64799+ preempt_enable();
64800+
64801+ return;
64802+}
64803+
64804+void
64805+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
64806+ struct dentry *old_dentry,
64807+ struct dentry *new_dentry,
64808+ struct vfsmount *mnt, const __u8 replace)
64809+{
64810+ struct name_entry *matchn;
64811+ struct inodev_entry *inodev;
64812+ struct inode *inode = new_dentry->d_inode;
64813+ ino_t old_ino = old_dentry->d_inode->i_ino;
64814+ dev_t old_dev = __get_dev(old_dentry);
64815+
64816+ /* vfs_rename swaps the name and parent link for old_dentry and
64817+ new_dentry
64818+ at this point, old_dentry has the new name, parent link, and inode
64819+ for the renamed file
64820+ if a file is being replaced by a rename, new_dentry has the inode
64821+ and name for the replaced file
64822+ */
64823+
64824+ if (unlikely(!(gr_status & GR_READY)))
64825+ return;
64826+
64827+ preempt_disable();
64828+ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
64829+
64830+ /* we wouldn't have to check d_inode if it weren't for
64831+ NFS silly-renaming
64832+ */
64833+
64834+ write_lock(&gr_inode_lock);
64835+ if (unlikely(replace && inode)) {
64836+ ino_t new_ino = inode->i_ino;
64837+ dev_t new_dev = __get_dev(new_dentry);
64838+
64839+ inodev = lookup_inodev_entry(new_ino, new_dev);
64840+ if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
64841+ do_handle_delete(inodev, new_ino, new_dev);
64842+ }
64843+
64844+ inodev = lookup_inodev_entry(old_ino, old_dev);
64845+ if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
64846+ do_handle_delete(inodev, old_ino, old_dev);
64847+
64848+ if (unlikely((unsigned long)matchn))
64849+ do_handle_create(matchn, old_dentry, mnt);
64850+
64851+ write_unlock(&gr_inode_lock);
64852+ preempt_enable();
64853+
64854+ return;
64855+}
64856+
64857+#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
64858+static const unsigned long res_learn_bumps[GR_NLIMITS] = {
64859+ [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
64860+ [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
64861+ [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
64862+ [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
64863+ [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
64864+ [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
64865+ [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
64866+ [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
64867+ [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
64868+ [RLIMIT_AS] = GR_RLIM_AS_BUMP,
64869+ [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
64870+ [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
64871+ [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
64872+ [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
64873+ [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
64874+ [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
64875+};
64876+
64877+void
64878+gr_learn_resource(const struct task_struct *task,
64879+ const int res, const unsigned long wanted, const int gt)
64880+{
64881+ struct acl_subject_label *acl;
64882+ const struct cred *cred;
64883+
64884+ if (unlikely((gr_status & GR_READY) &&
64885+ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
64886+ goto skip_reslog;
64887+
64888+ gr_log_resource(task, res, wanted, gt);
64889+skip_reslog:
64890+
64891+ if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
64892+ return;
64893+
64894+ acl = task->acl;
64895+
64896+ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
64897+ !(acl->resmask & (1U << (unsigned short) res))))
64898+ return;
64899+
64900+ if (wanted >= acl->res[res].rlim_cur) {
64901+ unsigned long res_add;
64902+
64903+ res_add = wanted + res_learn_bumps[res];
64904+
64905+ acl->res[res].rlim_cur = res_add;
64906+
64907+ if (wanted > acl->res[res].rlim_max)
64908+ acl->res[res].rlim_max = res_add;
64909+
64910+ /* only log the subject filename, since resource logging is supported for
64911+ single-subject learning only */
64912+ rcu_read_lock();
64913+ cred = __task_cred(task);
64914+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
64915+ task->role->roletype, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), acl->filename,
64916+ acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
64917+ "", (unsigned long) res, &task->signal->saved_ip);
64918+ rcu_read_unlock();
64919+ }
64920+
64921+ return;
64922+}
64923+EXPORT_SYMBOL(gr_learn_resource);
64924+#endif
64925+
64926+#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
64927+void
64928+pax_set_initial_flags(struct linux_binprm *bprm)
64929+{
64930+ struct task_struct *task = current;
64931+ struct acl_subject_label *proc;
64932+ unsigned long flags;
64933+
64934+ if (unlikely(!(gr_status & GR_READY)))
64935+ return;
64936+
64937+ flags = pax_get_flags(task);
64938+
64939+ proc = task->acl;
64940+
64941+ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
64942+ flags &= ~MF_PAX_PAGEEXEC;
64943+ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
64944+ flags &= ~MF_PAX_SEGMEXEC;
64945+ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
64946+ flags &= ~MF_PAX_RANDMMAP;
64947+ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
64948+ flags &= ~MF_PAX_EMUTRAMP;
64949+ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
64950+ flags &= ~MF_PAX_MPROTECT;
64951+
64952+ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
64953+ flags |= MF_PAX_PAGEEXEC;
64954+ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
64955+ flags |= MF_PAX_SEGMEXEC;
64956+ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
64957+ flags |= MF_PAX_RANDMMAP;
64958+ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
64959+ flags |= MF_PAX_EMUTRAMP;
64960+ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
64961+ flags |= MF_PAX_MPROTECT;
64962+
64963+ pax_set_flags(task, flags);
64964+
64965+ return;
64966+}
64967+#endif
64968+
64969+int
64970+gr_handle_proc_ptrace(struct task_struct *task)
64971+{
64972+ struct file *filp;
64973+ struct task_struct *tmp = task;
64974+ struct task_struct *curtemp = current;
64975+ __u32 retmode;
64976+
64977+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
64978+ if (unlikely(!(gr_status & GR_READY)))
64979+ return 0;
64980+#endif
64981+
64982+ read_lock(&tasklist_lock);
64983+ read_lock(&grsec_exec_file_lock);
64984+ filp = task->exec_file;
64985+
64986+ while (task_pid_nr(tmp) > 0) {
64987+ if (tmp == curtemp)
64988+ break;
64989+ tmp = tmp->real_parent;
64990+ }
64991+
64992+ if (!filp || (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
64993+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
64994+ read_unlock(&grsec_exec_file_lock);
64995+ read_unlock(&tasklist_lock);
64996+ return 1;
64997+ }
64998+
64999+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
65000+ if (!(gr_status & GR_READY)) {
65001+ read_unlock(&grsec_exec_file_lock);
65002+ read_unlock(&tasklist_lock);
65003+ return 0;
65004+ }
65005+#endif
65006+
65007+ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
65008+ read_unlock(&grsec_exec_file_lock);
65009+ read_unlock(&tasklist_lock);
65010+
65011+ if (retmode & GR_NOPTRACE)
65012+ return 1;
65013+
65014+ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
65015+ && (current->acl != task->acl || (current->acl != current->role->root_label
65016+ && task_pid_nr(current) != task_pid_nr(task))))
65017+ return 1;
65018+
65019+ return 0;
65020+}
65021+
65022+void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
65023+{
65024+ if (unlikely(!(gr_status & GR_READY)))
65025+ return;
65026+
65027+ if (!(current->role->roletype & GR_ROLE_GOD))
65028+ return;
65029+
65030+ seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
65031+ p->role->rolename, gr_task_roletype_to_char(p),
65032+ p->acl->filename);
65033+}
65034+
65035+int
65036+gr_handle_ptrace(struct task_struct *task, const long request)
65037+{
65038+ struct task_struct *tmp = task;
65039+ struct task_struct *curtemp = current;
65040+ __u32 retmode;
65041+
65042+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
65043+ if (unlikely(!(gr_status & GR_READY)))
65044+ return 0;
65045+#endif
65046+ if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
65047+ read_lock(&tasklist_lock);
65048+ while (task_pid_nr(tmp) > 0) {
65049+ if (tmp == curtemp)
65050+ break;
65051+ tmp = tmp->real_parent;
65052+ }
65053+
65054+ if (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
65055+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
65056+ read_unlock(&tasklist_lock);
65057+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
65058+ return 1;
65059+ }
65060+ read_unlock(&tasklist_lock);
65061+ }
65062+
65063+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
65064+ if (!(gr_status & GR_READY))
65065+ return 0;
65066+#endif
65067+
65068+ read_lock(&grsec_exec_file_lock);
65069+ if (unlikely(!task->exec_file)) {
65070+ read_unlock(&grsec_exec_file_lock);
65071+ return 0;
65072+ }
65073+
65074+ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
65075+ read_unlock(&grsec_exec_file_lock);
65076+
65077+ if (retmode & GR_NOPTRACE) {
65078+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
65079+ return 1;
65080+ }
65081+
65082+ if (retmode & GR_PTRACERD) {
65083+ switch (request) {
65084+ case PTRACE_SEIZE:
65085+ case PTRACE_POKETEXT:
65086+ case PTRACE_POKEDATA:
65087+ case PTRACE_POKEUSR:
65088+#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
65089+ case PTRACE_SETREGS:
65090+ case PTRACE_SETFPREGS:
65091+#endif
65092+#ifdef CONFIG_X86
65093+ case PTRACE_SETFPXREGS:
65094+#endif
65095+#ifdef CONFIG_ALTIVEC
65096+ case PTRACE_SETVRREGS:
65097+#endif
65098+ return 1;
65099+ default:
65100+ return 0;
65101+ }
65102+ } else if (!(current->acl->mode & GR_POVERRIDE) &&
65103+ !(current->role->roletype & GR_ROLE_GOD) &&
65104+ (current->acl != task->acl)) {
65105+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
65106+ return 1;
65107+ }
65108+
65109+ return 0;
65110+}
65111+
65112+static int is_writable_mmap(const struct file *filp)
65113+{
65114+ struct task_struct *task = current;
65115+ struct acl_object_label *obj, *obj2;
65116+
65117+ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
65118+ !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))) {
65119+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
65120+ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
65121+ task->role->root_label);
65122+ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
65123+ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
65124+ return 1;
65125+ }
65126+ }
65127+ return 0;
65128+}
65129+
65130+int
65131+gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
65132+{
65133+ __u32 mode;
65134+
65135+ if (unlikely(!file || !(prot & PROT_EXEC)))
65136+ return 1;
65137+
65138+ if (is_writable_mmap(file))
65139+ return 0;
65140+
65141+ mode =
65142+ gr_search_file(file->f_path.dentry,
65143+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
65144+ file->f_path.mnt);
65145+
65146+ if (!gr_tpe_allow(file))
65147+ return 0;
65148+
65149+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
65150+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
65151+ return 0;
65152+ } else if (unlikely(!(mode & GR_EXEC))) {
65153+ return 0;
65154+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
65155+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
65156+ return 1;
65157+ }
65158+
65159+ return 1;
65160+}
65161+
65162+int
65163+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
65164+{
65165+ __u32 mode;
65166+
65167+ if (unlikely(!file || !(prot & PROT_EXEC)))
65168+ return 1;
65169+
65170+ if (is_writable_mmap(file))
65171+ return 0;
65172+
65173+ mode =
65174+ gr_search_file(file->f_path.dentry,
65175+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
65176+ file->f_path.mnt);
65177+
65178+ if (!gr_tpe_allow(file))
65179+ return 0;
65180+
65181+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
65182+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
65183+ return 0;
65184+ } else if (unlikely(!(mode & GR_EXEC))) {
65185+ return 0;
65186+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
65187+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
65188+ return 1;
65189+ }
65190+
65191+ return 1;
65192+}
65193+
65194+void
65195+gr_acl_handle_psacct(struct task_struct *task, const long code)
65196+{
65197+ unsigned long runtime;
65198+ unsigned long cputime;
65199+ unsigned int wday, cday;
65200+ __u8 whr, chr;
65201+ __u8 wmin, cmin;
65202+ __u8 wsec, csec;
65203+ struct timespec timeval;
65204+
65205+ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
65206+ !(task->acl->mode & GR_PROCACCT)))
65207+ return;
65208+
65209+ do_posix_clock_monotonic_gettime(&timeval);
65210+ runtime = timeval.tv_sec - task->start_time.tv_sec;
65211+ wday = runtime / (3600 * 24);
65212+ runtime -= wday * (3600 * 24);
65213+ whr = runtime / 3600;
65214+ runtime -= whr * 3600;
65215+ wmin = runtime / 60;
65216+ runtime -= wmin * 60;
65217+ wsec = runtime;
65218+
65219+ cputime = (task->utime + task->stime) / HZ;
65220+ cday = cputime / (3600 * 24);
65221+ cputime -= cday * (3600 * 24);
65222+ chr = cputime / 3600;
65223+ cputime -= chr * 3600;
65224+ cmin = cputime / 60;
65225+ cputime -= cmin * 60;
65226+ csec = cputime;
65227+
65228+ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
65229+
65230+ return;
65231+}
65232+
65233+#ifdef CONFIG_TASKSTATS
65234+int gr_is_taskstats_denied(int pid)
65235+{
65236+ struct task_struct *task;
65237+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
65238+ const struct cred *cred;
65239+#endif
65240+ int ret = 0;
65241+
65242+ /* restrict taskstats viewing to un-chrooted root users
65243+ who have the 'view' subject flag if the RBAC system is enabled
65244+ */
65245+
65246+ rcu_read_lock();
65247+ read_lock(&tasklist_lock);
65248+ task = find_task_by_vpid(pid);
65249+ if (task) {
65250+#ifdef CONFIG_GRKERNSEC_CHROOT
65251+ if (proc_is_chrooted(task))
65252+ ret = -EACCES;
65253+#endif
65254+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
65255+ cred = __task_cred(task);
65256+#ifdef CONFIG_GRKERNSEC_PROC_USER
65257+ if (gr_is_global_nonroot(cred->uid))
65258+ ret = -EACCES;
65259+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
65260+ if (gr_is_global_nonroot(cred->uid) && !groups_search(cred->group_info, grsec_proc_gid))
65261+ ret = -EACCES;
65262+#endif
65263+#endif
65264+ if (gr_status & GR_READY) {
65265+ if (!(task->acl->mode & GR_VIEW))
65266+ ret = -EACCES;
65267+ }
65268+ } else
65269+ ret = -ENOENT;
65270+
65271+ read_unlock(&tasklist_lock);
65272+ rcu_read_unlock();
65273+
65274+ return ret;
65275+}
65276+#endif
65277+
65278+/* AUXV entries are filled via a descendant of search_binary_handler
65279+ after we've already applied the subject for the target
65280+*/
65281+int gr_acl_enable_at_secure(void)
65282+{
65283+ if (unlikely(!(gr_status & GR_READY)))
65284+ return 0;
65285+
65286+ if (current->acl->mode & GR_ATSECURE)
65287+ return 1;
65288+
65289+ return 0;
65290+}
65291+
65292+int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
65293+{
65294+ struct task_struct *task = current;
65295+ struct dentry *dentry = file->f_path.dentry;
65296+ struct vfsmount *mnt = file->f_path.mnt;
65297+ struct acl_object_label *obj, *tmp;
65298+ struct acl_subject_label *subj;
65299+ unsigned int bufsize;
65300+ int is_not_root;
65301+ char *path;
65302+ dev_t dev = __get_dev(dentry);
65303+
65304+ if (unlikely(!(gr_status & GR_READY)))
65305+ return 1;
65306+
65307+ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
65308+ return 1;
65309+
65310+ /* ignore Eric Biederman */
65311+ if (IS_PRIVATE(dentry->d_inode))
65312+ return 1;
65313+
65314+ subj = task->acl;
65315+ read_lock(&gr_inode_lock);
65316+ do {
65317+ obj = lookup_acl_obj_label(ino, dev, subj);
65318+ if (obj != NULL) {
65319+ read_unlock(&gr_inode_lock);
65320+ return (obj->mode & GR_FIND) ? 1 : 0;
65321+ }
65322+ } while ((subj = subj->parent_subject));
65323+ read_unlock(&gr_inode_lock);
65324+
65325+ /* this is purely an optimization since we're looking for an object
65326+ for the directory we're doing a readdir on
65327+ if it's possible for any globbed object to match the entry we're
65328+ filling into the directory, then the object we find here will be
65329+ an anchor point with attached globbed objects
65330+ */
65331+ obj = chk_obj_label_noglob(dentry, mnt, task->acl);
65332+ if (obj->globbed == NULL)
65333+ return (obj->mode & GR_FIND) ? 1 : 0;
65334+
65335+ is_not_root = ((obj->filename[0] == '/') &&
65336+ (obj->filename[1] == '\0')) ? 0 : 1;
65337+ bufsize = PAGE_SIZE - namelen - is_not_root;
65338+
65339+ /* check bufsize > PAGE_SIZE || bufsize == 0 */
65340+ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
65341+ return 1;
65342+
65343+ preempt_disable();
65344+ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
65345+ bufsize);
65346+
65347+ bufsize = strlen(path);
65348+
65349+ /* if base is "/", don't append an additional slash */
65350+ if (is_not_root)
65351+ *(path + bufsize) = '/';
65352+ memcpy(path + bufsize + is_not_root, name, namelen);
65353+ *(path + bufsize + namelen + is_not_root) = '\0';
65354+
65355+ tmp = obj->globbed;
65356+ while (tmp) {
65357+ if (!glob_match(tmp->filename, path)) {
65358+ preempt_enable();
65359+ return (tmp->mode & GR_FIND) ? 1 : 0;
65360+ }
65361+ tmp = tmp->next;
65362+ }
65363+ preempt_enable();
65364+ return (obj->mode & GR_FIND) ? 1 : 0;
65365+}
65366+
65367+void gr_put_exec_file(struct task_struct *task)
65368+{
65369+ struct file *filp;
65370+
65371+ write_lock(&grsec_exec_file_lock);
65372+ filp = task->exec_file;
65373+ task->exec_file = NULL;
65374+ write_unlock(&grsec_exec_file_lock);
65375+
65376+ if (filp)
65377+ fput(filp);
65378+
65379+ return;
65380+}
65381+
65382+
65383+#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
65384+EXPORT_SYMBOL(gr_acl_is_enabled);
65385+#endif
65386+#ifdef CONFIG_SECURITY
65387+EXPORT_SYMBOL(gr_check_user_change);
65388+EXPORT_SYMBOL(gr_check_group_change);
65389+#endif
65390+
65391diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
65392new file mode 100644
65393index 0000000..18ffbbd
65394--- /dev/null
65395+++ b/grsecurity/gracl_alloc.c
65396@@ -0,0 +1,105 @@
65397+#include <linux/kernel.h>
65398+#include <linux/mm.h>
65399+#include <linux/slab.h>
65400+#include <linux/vmalloc.h>
65401+#include <linux/gracl.h>
65402+#include <linux/grsecurity.h>
65403+
65404+static struct gr_alloc_state __current_alloc_state = { 1, 1, NULL };
65405+struct gr_alloc_state *current_alloc_state = &__current_alloc_state;
65406+
65407+static __inline__ int
65408+alloc_pop(void)
65409+{
65410+ if (current_alloc_state->alloc_stack_next == 1)
65411+ return 0;
65412+
65413+ kfree(current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 2]);
65414+
65415+ current_alloc_state->alloc_stack_next--;
65416+
65417+ return 1;
65418+}
65419+
65420+static __inline__ int
65421+alloc_push(void *buf)
65422+{
65423+ if (current_alloc_state->alloc_stack_next >= current_alloc_state->alloc_stack_size)
65424+ return 1;
65425+
65426+ current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 1] = buf;
65427+
65428+ current_alloc_state->alloc_stack_next++;
65429+
65430+ return 0;
65431+}
65432+
65433+void *
65434+acl_alloc(unsigned long len)
65435+{
65436+ void *ret = NULL;
65437+
65438+ if (!len || len > PAGE_SIZE)
65439+ goto out;
65440+
65441+ ret = kmalloc(len, GFP_KERNEL);
65442+
65443+ if (ret) {
65444+ if (alloc_push(ret)) {
65445+ kfree(ret);
65446+ ret = NULL;
65447+ }
65448+ }
65449+
65450+out:
65451+ return ret;
65452+}
65453+
65454+void *
65455+acl_alloc_num(unsigned long num, unsigned long len)
65456+{
65457+ if (!len || (num > (PAGE_SIZE / len)))
65458+ return NULL;
65459+
65460+ return acl_alloc(num * len);
65461+}
65462+
65463+void
65464+acl_free_all(void)
65465+{
65466+ if (!current_alloc_state->alloc_stack)
65467+ return;
65468+
65469+ while (alloc_pop()) ;
65470+
65471+ if (current_alloc_state->alloc_stack) {
65472+ if ((current_alloc_state->alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
65473+ kfree(current_alloc_state->alloc_stack);
65474+ else
65475+ vfree(current_alloc_state->alloc_stack);
65476+ }
65477+
65478+ current_alloc_state->alloc_stack = NULL;
65479+ current_alloc_state->alloc_stack_size = 1;
65480+ current_alloc_state->alloc_stack_next = 1;
65481+
65482+ return;
65483+}
65484+
65485+int
65486+acl_alloc_stack_init(unsigned long size)
65487+{
65488+ if ((size * sizeof (void *)) <= PAGE_SIZE)
65489+ current_alloc_state->alloc_stack =
65490+ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
65491+ else
65492+ current_alloc_state->alloc_stack = (void **) vmalloc(size * sizeof (void *));
65493+
65494+ current_alloc_state->alloc_stack_size = size;
65495+ current_alloc_state->alloc_stack_next = 1;
65496+
65497+ if (!current_alloc_state->alloc_stack)
65498+ return 0;
65499+ else
65500+ return 1;
65501+}
65502diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
65503new file mode 100644
65504index 0000000..bdd51ea
65505--- /dev/null
65506+++ b/grsecurity/gracl_cap.c
65507@@ -0,0 +1,110 @@
65508+#include <linux/kernel.h>
65509+#include <linux/module.h>
65510+#include <linux/sched.h>
65511+#include <linux/gracl.h>
65512+#include <linux/grsecurity.h>
65513+#include <linux/grinternal.h>
65514+
65515+extern const char *captab_log[];
65516+extern int captab_log_entries;
65517+
65518+int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
65519+{
65520+ struct acl_subject_label *curracl;
65521+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
65522+ kernel_cap_t cap_audit = __cap_empty_set;
65523+
65524+ if (!gr_acl_is_enabled())
65525+ return 1;
65526+
65527+ curracl = task->acl;
65528+
65529+ cap_drop = curracl->cap_lower;
65530+ cap_mask = curracl->cap_mask;
65531+ cap_audit = curracl->cap_invert_audit;
65532+
65533+ while ((curracl = curracl->parent_subject)) {
65534+ /* if the cap isn't specified in the current computed mask but is specified in the
65535+ current level subject, and is lowered in the current level subject, then add
65536+ it to the set of dropped capabilities
65537+ otherwise, add the current level subject's mask to the current computed mask
65538+ */
65539+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
65540+ cap_raise(cap_mask, cap);
65541+ if (cap_raised(curracl->cap_lower, cap))
65542+ cap_raise(cap_drop, cap);
65543+ if (cap_raised(curracl->cap_invert_audit, cap))
65544+ cap_raise(cap_audit, cap);
65545+ }
65546+ }
65547+
65548+ if (!cap_raised(cap_drop, cap)) {
65549+ if (cap_raised(cap_audit, cap))
65550+ gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
65551+ return 1;
65552+ }
65553+
65554+ curracl = task->acl;
65555+
65556+ if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
65557+ && cap_raised(cred->cap_effective, cap)) {
65558+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
65559+ task->role->roletype, GR_GLOBAL_UID(cred->uid),
65560+ GR_GLOBAL_GID(cred->gid), task->exec_file ?
65561+ gr_to_filename(task->exec_file->f_path.dentry,
65562+ task->exec_file->f_path.mnt) : curracl->filename,
65563+ curracl->filename, 0UL,
65564+ 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
65565+ return 1;
65566+ }
65567+
65568+ if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
65569+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
65570+
65571+ return 0;
65572+}
65573+
65574+int
65575+gr_acl_is_capable(const int cap)
65576+{
65577+ return gr_task_acl_is_capable(current, current_cred(), cap);
65578+}
65579+
65580+int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
65581+{
65582+ struct acl_subject_label *curracl;
65583+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
65584+
65585+ if (!gr_acl_is_enabled())
65586+ return 1;
65587+
65588+ curracl = task->acl;
65589+
65590+ cap_drop = curracl->cap_lower;
65591+ cap_mask = curracl->cap_mask;
65592+
65593+ while ((curracl = curracl->parent_subject)) {
65594+ /* if the cap isn't specified in the current computed mask but is specified in the
65595+ current level subject, and is lowered in the current level subject, then add
65596+ it to the set of dropped capabilities
65597+ otherwise, add the current level subject's mask to the current computed mask
65598+ */
65599+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
65600+ cap_raise(cap_mask, cap);
65601+ if (cap_raised(curracl->cap_lower, cap))
65602+ cap_raise(cap_drop, cap);
65603+ }
65604+ }
65605+
65606+ if (!cap_raised(cap_drop, cap))
65607+ return 1;
65608+
65609+ return 0;
65610+}
65611+
65612+int
65613+gr_acl_is_capable_nolog(const int cap)
65614+{
65615+ return gr_task_acl_is_capable_nolog(current, cap);
65616+}
65617+
65618diff --git a/grsecurity/gracl_compat.c b/grsecurity/gracl_compat.c
65619new file mode 100644
65620index 0000000..ca25605
65621--- /dev/null
65622+++ b/grsecurity/gracl_compat.c
65623@@ -0,0 +1,270 @@
65624+#include <linux/kernel.h>
65625+#include <linux/gracl.h>
65626+#include <linux/compat.h>
65627+#include <linux/gracl_compat.h>
65628+
65629+#include <asm/uaccess.h>
65630+
65631+int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap)
65632+{
65633+ struct gr_arg_wrapper_compat uwrapcompat;
65634+
65635+ if (copy_from_user(&uwrapcompat, buf, sizeof(uwrapcompat)))
65636+ return -EFAULT;
65637+
65638+ if (((uwrapcompat.version != GRSECURITY_VERSION) &&
65639+ (uwrapcompat.version != 0x2901)) ||
65640+ (uwrapcompat.size != sizeof(struct gr_arg_compat)))
65641+ return -EINVAL;
65642+
65643+ uwrap->arg = compat_ptr(uwrapcompat.arg);
65644+ uwrap->version = uwrapcompat.version;
65645+ uwrap->size = sizeof(struct gr_arg);
65646+
65647+ return 0;
65648+}
65649+
65650+int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg)
65651+{
65652+ struct gr_arg_compat argcompat;
65653+
65654+ if (copy_from_user(&argcompat, buf, sizeof(argcompat)))
65655+ return -EFAULT;
65656+
65657+ arg->role_db.r_table = compat_ptr(argcompat.role_db.r_table);
65658+ arg->role_db.num_pointers = argcompat.role_db.num_pointers;
65659+ arg->role_db.num_roles = argcompat.role_db.num_roles;
65660+ arg->role_db.num_domain_children = argcompat.role_db.num_domain_children;
65661+ arg->role_db.num_subjects = argcompat.role_db.num_subjects;
65662+ arg->role_db.num_objects = argcompat.role_db.num_objects;
65663+
65664+ memcpy(&arg->pw, &argcompat.pw, sizeof(arg->pw));
65665+ memcpy(&arg->salt, &argcompat.salt, sizeof(arg->salt));
65666+ memcpy(&arg->sum, &argcompat.sum, sizeof(arg->sum));
65667+ memcpy(&arg->sp_role, &argcompat.sp_role, sizeof(arg->sp_role));
65668+ arg->sprole_pws = compat_ptr(argcompat.sprole_pws);
65669+ arg->segv_device = argcompat.segv_device;
65670+ arg->segv_inode = argcompat.segv_inode;
65671+ arg->segv_uid = argcompat.segv_uid;
65672+ arg->num_sprole_pws = argcompat.num_sprole_pws;
65673+ arg->mode = argcompat.mode;
65674+
65675+ return 0;
65676+}
65677+
65678+int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp)
65679+{
65680+ struct acl_object_label_compat objcompat;
65681+
65682+ if (copy_from_user(&objcompat, userp, sizeof(objcompat)))
65683+ return -EFAULT;
65684+
65685+ obj->filename = compat_ptr(objcompat.filename);
65686+ obj->inode = objcompat.inode;
65687+ obj->device = objcompat.device;
65688+ obj->mode = objcompat.mode;
65689+
65690+ obj->nested = compat_ptr(objcompat.nested);
65691+ obj->globbed = compat_ptr(objcompat.globbed);
65692+
65693+ obj->prev = compat_ptr(objcompat.prev);
65694+ obj->next = compat_ptr(objcompat.next);
65695+
65696+ return 0;
65697+}
65698+
65699+int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp)
65700+{
65701+ unsigned int i;
65702+ struct acl_subject_label_compat subjcompat;
65703+
65704+ if (copy_from_user(&subjcompat, userp, sizeof(subjcompat)))
65705+ return -EFAULT;
65706+
65707+ subj->filename = compat_ptr(subjcompat.filename);
65708+ subj->inode = subjcompat.inode;
65709+ subj->device = subjcompat.device;
65710+ subj->mode = subjcompat.mode;
65711+ subj->cap_mask = subjcompat.cap_mask;
65712+ subj->cap_lower = subjcompat.cap_lower;
65713+ subj->cap_invert_audit = subjcompat.cap_invert_audit;
65714+
65715+ for (i = 0; i < GR_NLIMITS; i++) {
65716+ if (subjcompat.res[i].rlim_cur == COMPAT_RLIM_INFINITY)
65717+ subj->res[i].rlim_cur = RLIM_INFINITY;
65718+ else
65719+ subj->res[i].rlim_cur = subjcompat.res[i].rlim_cur;
65720+ if (subjcompat.res[i].rlim_max == COMPAT_RLIM_INFINITY)
65721+ subj->res[i].rlim_max = RLIM_INFINITY;
65722+ else
65723+ subj->res[i].rlim_max = subjcompat.res[i].rlim_max;
65724+ }
65725+ subj->resmask = subjcompat.resmask;
65726+
65727+ subj->user_trans_type = subjcompat.user_trans_type;
65728+ subj->group_trans_type = subjcompat.group_trans_type;
65729+ subj->user_transitions = compat_ptr(subjcompat.user_transitions);
65730+ subj->group_transitions = compat_ptr(subjcompat.group_transitions);
65731+ subj->user_trans_num = subjcompat.user_trans_num;
65732+ subj->group_trans_num = subjcompat.group_trans_num;
65733+
65734+ memcpy(&subj->sock_families, &subjcompat.sock_families, sizeof(subj->sock_families));
65735+ memcpy(&subj->ip_proto, &subjcompat.ip_proto, sizeof(subj->ip_proto));
65736+ subj->ip_type = subjcompat.ip_type;
65737+ subj->ips = compat_ptr(subjcompat.ips);
65738+ subj->ip_num = subjcompat.ip_num;
65739+ subj->inaddr_any_override = subjcompat.inaddr_any_override;
65740+
65741+ subj->crashes = subjcompat.crashes;
65742+ subj->expires = subjcompat.expires;
65743+
65744+ subj->parent_subject = compat_ptr(subjcompat.parent_subject);
65745+ subj->hash = compat_ptr(subjcompat.hash);
65746+ subj->prev = compat_ptr(subjcompat.prev);
65747+ subj->next = compat_ptr(subjcompat.next);
65748+
65749+ subj->obj_hash = compat_ptr(subjcompat.obj_hash);
65750+ subj->obj_hash_size = subjcompat.obj_hash_size;
65751+ subj->pax_flags = subjcompat.pax_flags;
65752+
65753+ return 0;
65754+}
65755+
65756+int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp)
65757+{
65758+ struct acl_role_label_compat rolecompat;
65759+
65760+ if (copy_from_user(&rolecompat, userp, sizeof(rolecompat)))
65761+ return -EFAULT;
65762+
65763+ role->rolename = compat_ptr(rolecompat.rolename);
65764+ role->uidgid = rolecompat.uidgid;
65765+ role->roletype = rolecompat.roletype;
65766+
65767+ role->auth_attempts = rolecompat.auth_attempts;
65768+ role->expires = rolecompat.expires;
65769+
65770+ role->root_label = compat_ptr(rolecompat.root_label);
65771+ role->hash = compat_ptr(rolecompat.hash);
65772+
65773+ role->prev = compat_ptr(rolecompat.prev);
65774+ role->next = compat_ptr(rolecompat.next);
65775+
65776+ role->transitions = compat_ptr(rolecompat.transitions);
65777+ role->allowed_ips = compat_ptr(rolecompat.allowed_ips);
65778+ role->domain_children = compat_ptr(rolecompat.domain_children);
65779+ role->domain_child_num = rolecompat.domain_child_num;
65780+
65781+ role->umask = rolecompat.umask;
65782+
65783+ role->subj_hash = compat_ptr(rolecompat.subj_hash);
65784+ role->subj_hash_size = rolecompat.subj_hash_size;
65785+
65786+ return 0;
65787+}
65788+
65789+int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
65790+{
65791+ struct role_allowed_ip_compat roleip_compat;
65792+
65793+ if (copy_from_user(&roleip_compat, userp, sizeof(roleip_compat)))
65794+ return -EFAULT;
65795+
65796+ roleip->addr = roleip_compat.addr;
65797+ roleip->netmask = roleip_compat.netmask;
65798+
65799+ roleip->prev = compat_ptr(roleip_compat.prev);
65800+ roleip->next = compat_ptr(roleip_compat.next);
65801+
65802+ return 0;
65803+}
65804+
65805+int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp)
65806+{
65807+ struct role_transition_compat trans_compat;
65808+
65809+ if (copy_from_user(&trans_compat, userp, sizeof(trans_compat)))
65810+ return -EFAULT;
65811+
65812+ trans->rolename = compat_ptr(trans_compat.rolename);
65813+
65814+ trans->prev = compat_ptr(trans_compat.prev);
65815+ trans->next = compat_ptr(trans_compat.next);
65816+
65817+ return 0;
65818+
65819+}
65820+
65821+int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
65822+{
65823+ struct gr_hash_struct_compat hash_compat;
65824+
65825+ if (copy_from_user(&hash_compat, userp, sizeof(hash_compat)))
65826+ return -EFAULT;
65827+
65828+ hash->table = compat_ptr(hash_compat.table);
65829+ hash->nametable = compat_ptr(hash_compat.nametable);
65830+ hash->first = compat_ptr(hash_compat.first);
65831+
65832+ hash->table_size = hash_compat.table_size;
65833+ hash->used_size = hash_compat.used_size;
65834+
65835+ hash->type = hash_compat.type;
65836+
65837+ return 0;
65838+}
65839+
65840+int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp)
65841+{
65842+ compat_uptr_t ptrcompat;
65843+
65844+ if (copy_from_user(&ptrcompat, userp + (idx * sizeof(ptrcompat)), sizeof(ptrcompat)))
65845+ return -EFAULT;
65846+
65847+ *(void **)ptr = compat_ptr(ptrcompat);
65848+
65849+ return 0;
65850+}
65851+
65852+int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp)
65853+{
65854+ struct acl_ip_label_compat ip_compat;
65855+
65856+ if (copy_from_user(&ip_compat, userp, sizeof(ip_compat)))
65857+ return -EFAULT;
65858+
65859+ ip->iface = compat_ptr(ip_compat.iface);
65860+ ip->addr = ip_compat.addr;
65861+ ip->netmask = ip_compat.netmask;
65862+ ip->low = ip_compat.low;
65863+ ip->high = ip_compat.high;
65864+ ip->mode = ip_compat.mode;
65865+ ip->type = ip_compat.type;
65866+
65867+ memcpy(&ip->proto, &ip_compat.proto, sizeof(ip->proto));
65868+
65869+ ip->prev = compat_ptr(ip_compat.prev);
65870+ ip->next = compat_ptr(ip_compat.next);
65871+
65872+ return 0;
65873+}
65874+
65875+int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
65876+{
65877+ struct sprole_pw_compat pw_compat;
65878+
65879+ if (copy_from_user(&pw_compat, (const void *)userp + (sizeof(pw_compat) * idx), sizeof(pw_compat)))
65880+ return -EFAULT;
65881+
65882+ pw->rolename = compat_ptr(pw_compat.rolename);
65883+ memcpy(&pw->salt, pw_compat.salt, sizeof(pw->salt));
65884+ memcpy(&pw->sum, pw_compat.sum, sizeof(pw->sum));
65885+
65886+ return 0;
65887+}
65888+
65889+size_t get_gr_arg_wrapper_size_compat(void)
65890+{
65891+ return sizeof(struct gr_arg_wrapper_compat);
65892+}
65893+
65894diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
65895new file mode 100644
65896index 0000000..a340c17
65897--- /dev/null
65898+++ b/grsecurity/gracl_fs.c
65899@@ -0,0 +1,431 @@
65900+#include <linux/kernel.h>
65901+#include <linux/sched.h>
65902+#include <linux/types.h>
65903+#include <linux/fs.h>
65904+#include <linux/file.h>
65905+#include <linux/stat.h>
65906+#include <linux/grsecurity.h>
65907+#include <linux/grinternal.h>
65908+#include <linux/gracl.h>
65909+
65910+umode_t
65911+gr_acl_umask(void)
65912+{
65913+ if (unlikely(!gr_acl_is_enabled()))
65914+ return 0;
65915+
65916+ return current->role->umask;
65917+}
65918+
65919+__u32
65920+gr_acl_handle_hidden_file(const struct dentry * dentry,
65921+ const struct vfsmount * mnt)
65922+{
65923+ __u32 mode;
65924+
65925+ if (unlikely(!dentry->d_inode))
65926+ return GR_FIND;
65927+
65928+ mode =
65929+ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
65930+
65931+ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
65932+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
65933+ return mode;
65934+ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
65935+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
65936+ return 0;
65937+ } else if (unlikely(!(mode & GR_FIND)))
65938+ return 0;
65939+
65940+ return GR_FIND;
65941+}
65942+
65943+__u32
65944+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
65945+ int acc_mode)
65946+{
65947+ __u32 reqmode = GR_FIND;
65948+ __u32 mode;
65949+
65950+ if (unlikely(!dentry->d_inode))
65951+ return reqmode;
65952+
65953+ if (acc_mode & MAY_APPEND)
65954+ reqmode |= GR_APPEND;
65955+ else if (acc_mode & MAY_WRITE)
65956+ reqmode |= GR_WRITE;
65957+ if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
65958+ reqmode |= GR_READ;
65959+
65960+ mode =
65961+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
65962+ mnt);
65963+
65964+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
65965+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
65966+ reqmode & GR_READ ? " reading" : "",
65967+ reqmode & GR_WRITE ? " writing" : reqmode &
65968+ GR_APPEND ? " appending" : "");
65969+ return reqmode;
65970+ } else
65971+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
65972+ {
65973+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
65974+ reqmode & GR_READ ? " reading" : "",
65975+ reqmode & GR_WRITE ? " writing" : reqmode &
65976+ GR_APPEND ? " appending" : "");
65977+ return 0;
65978+ } else if (unlikely((mode & reqmode) != reqmode))
65979+ return 0;
65980+
65981+ return reqmode;
65982+}
65983+
65984+__u32
65985+gr_acl_handle_creat(const struct dentry * dentry,
65986+ const struct dentry * p_dentry,
65987+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
65988+ const int imode)
65989+{
65990+ __u32 reqmode = GR_WRITE | GR_CREATE;
65991+ __u32 mode;
65992+
65993+ if (acc_mode & MAY_APPEND)
65994+ reqmode |= GR_APPEND;
65995+ // if a directory was required or the directory already exists, then
65996+ // don't count this open as a read
65997+ if ((acc_mode & MAY_READ) &&
65998+ !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
65999+ reqmode |= GR_READ;
66000+ if ((open_flags & O_CREAT) &&
66001+ ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
66002+ reqmode |= GR_SETID;
66003+
66004+ mode =
66005+ gr_check_create(dentry, p_dentry, p_mnt,
66006+ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
66007+
66008+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
66009+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
66010+ reqmode & GR_READ ? " reading" : "",
66011+ reqmode & GR_WRITE ? " writing" : reqmode &
66012+ GR_APPEND ? " appending" : "");
66013+ return reqmode;
66014+ } else
66015+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
66016+ {
66017+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
66018+ reqmode & GR_READ ? " reading" : "",
66019+ reqmode & GR_WRITE ? " writing" : reqmode &
66020+ GR_APPEND ? " appending" : "");
66021+ return 0;
66022+ } else if (unlikely((mode & reqmode) != reqmode))
66023+ return 0;
66024+
66025+ return reqmode;
66026+}
66027+
66028+__u32
66029+gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
66030+ const int fmode)
66031+{
66032+ __u32 mode, reqmode = GR_FIND;
66033+
66034+ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
66035+ reqmode |= GR_EXEC;
66036+ if (fmode & S_IWOTH)
66037+ reqmode |= GR_WRITE;
66038+ if (fmode & S_IROTH)
66039+ reqmode |= GR_READ;
66040+
66041+ mode =
66042+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
66043+ mnt);
66044+
66045+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
66046+ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
66047+ reqmode & GR_READ ? " reading" : "",
66048+ reqmode & GR_WRITE ? " writing" : "",
66049+ reqmode & GR_EXEC ? " executing" : "");
66050+ return reqmode;
66051+ } else
66052+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
66053+ {
66054+ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
66055+ reqmode & GR_READ ? " reading" : "",
66056+ reqmode & GR_WRITE ? " writing" : "",
66057+ reqmode & GR_EXEC ? " executing" : "");
66058+ return 0;
66059+ } else if (unlikely((mode & reqmode) != reqmode))
66060+ return 0;
66061+
66062+ return reqmode;
66063+}
66064+
66065+static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
66066+{
66067+ __u32 mode;
66068+
66069+ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
66070+
66071+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
66072+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
66073+ return mode;
66074+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
66075+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
66076+ return 0;
66077+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
66078+ return 0;
66079+
66080+ return (reqmode);
66081+}
66082+
66083+__u32
66084+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
66085+{
66086+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
66087+}
66088+
66089+__u32
66090+gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
66091+{
66092+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
66093+}
66094+
66095+__u32
66096+gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
66097+{
66098+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
66099+}
66100+
66101+__u32
66102+gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
66103+{
66104+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
66105+}
66106+
66107+__u32
66108+gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
66109+ umode_t *modeptr)
66110+{
66111+ umode_t mode;
66112+
66113+ *modeptr &= ~gr_acl_umask();
66114+ mode = *modeptr;
66115+
66116+ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
66117+ return 1;
66118+
66119+ if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
66120+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
66121+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
66122+ GR_CHMOD_ACL_MSG);
66123+ } else {
66124+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
66125+ }
66126+}
66127+
66128+__u32
66129+gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
66130+{
66131+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
66132+}
66133+
66134+__u32
66135+gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
66136+{
66137+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
66138+}
66139+
66140+__u32
66141+gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
66142+{
66143+ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
66144+}
66145+
66146+__u32
66147+gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
66148+{
66149+ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
66150+ GR_UNIXCONNECT_ACL_MSG);
66151+}
66152+
66153+/* hardlinks require at minimum create and link permission,
66154+ any additional privilege required is based on the
66155+ privilege of the file being linked to
66156+*/
66157+__u32
66158+gr_acl_handle_link(const struct dentry * new_dentry,
66159+ const struct dentry * parent_dentry,
66160+ const struct vfsmount * parent_mnt,
66161+ const struct dentry * old_dentry,
66162+ const struct vfsmount * old_mnt, const struct filename *to)
66163+{
66164+ __u32 mode;
66165+ __u32 needmode = GR_CREATE | GR_LINK;
66166+ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
66167+
66168+ mode =
66169+ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
66170+ old_mnt);
66171+
66172+ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
66173+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
66174+ return mode;
66175+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
66176+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
66177+ return 0;
66178+ } else if (unlikely((mode & needmode) != needmode))
66179+ return 0;
66180+
66181+ return 1;
66182+}
66183+
66184+__u32
66185+gr_acl_handle_symlink(const struct dentry * new_dentry,
66186+ const struct dentry * parent_dentry,
66187+ const struct vfsmount * parent_mnt, const struct filename *from)
66188+{
66189+ __u32 needmode = GR_WRITE | GR_CREATE;
66190+ __u32 mode;
66191+
66192+ mode =
66193+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
66194+ GR_CREATE | GR_AUDIT_CREATE |
66195+ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
66196+
66197+ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
66198+ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
66199+ return mode;
66200+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
66201+ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
66202+ return 0;
66203+ } else if (unlikely((mode & needmode) != needmode))
66204+ return 0;
66205+
66206+ return (GR_WRITE | GR_CREATE);
66207+}
66208+
66209+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)
66210+{
66211+ __u32 mode;
66212+
66213+ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
66214+
66215+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
66216+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
66217+ return mode;
66218+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
66219+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
66220+ return 0;
66221+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
66222+ return 0;
66223+
66224+ return (reqmode);
66225+}
66226+
66227+__u32
66228+gr_acl_handle_mknod(const struct dentry * new_dentry,
66229+ const struct dentry * parent_dentry,
66230+ const struct vfsmount * parent_mnt,
66231+ const int mode)
66232+{
66233+ __u32 reqmode = GR_WRITE | GR_CREATE;
66234+ if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
66235+ reqmode |= GR_SETID;
66236+
66237+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
66238+ reqmode, GR_MKNOD_ACL_MSG);
66239+}
66240+
66241+__u32
66242+gr_acl_handle_mkdir(const struct dentry *new_dentry,
66243+ const struct dentry *parent_dentry,
66244+ const struct vfsmount *parent_mnt)
66245+{
66246+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
66247+ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
66248+}
66249+
66250+#define RENAME_CHECK_SUCCESS(old, new) \
66251+ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
66252+ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
66253+
66254+int
66255+gr_acl_handle_rename(struct dentry *new_dentry,
66256+ struct dentry *parent_dentry,
66257+ const struct vfsmount *parent_mnt,
66258+ struct dentry *old_dentry,
66259+ struct inode *old_parent_inode,
66260+ struct vfsmount *old_mnt, const struct filename *newname)
66261+{
66262+ __u32 comp1, comp2;
66263+ int error = 0;
66264+
66265+ if (unlikely(!gr_acl_is_enabled()))
66266+ return 0;
66267+
66268+ if (!new_dentry->d_inode) {
66269+ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
66270+ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
66271+ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
66272+ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
66273+ GR_DELETE | GR_AUDIT_DELETE |
66274+ GR_AUDIT_READ | GR_AUDIT_WRITE |
66275+ GR_SUPPRESS, old_mnt);
66276+ } else {
66277+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
66278+ GR_CREATE | GR_DELETE |
66279+ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
66280+ GR_AUDIT_READ | GR_AUDIT_WRITE |
66281+ GR_SUPPRESS, parent_mnt);
66282+ comp2 =
66283+ gr_search_file(old_dentry,
66284+ GR_READ | GR_WRITE | GR_AUDIT_READ |
66285+ GR_DELETE | GR_AUDIT_DELETE |
66286+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
66287+ }
66288+
66289+ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
66290+ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
66291+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
66292+ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
66293+ && !(comp2 & GR_SUPPRESS)) {
66294+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
66295+ error = -EACCES;
66296+ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
66297+ error = -EACCES;
66298+
66299+ return error;
66300+}
66301+
66302+void
66303+gr_acl_handle_exit(void)
66304+{
66305+ u16 id;
66306+ char *rolename;
66307+
66308+ if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
66309+ !(current->role->roletype & GR_ROLE_PERSIST))) {
66310+ id = current->acl_role_id;
66311+ rolename = current->role->rolename;
66312+ gr_set_acls(1);
66313+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
66314+ }
66315+
66316+ gr_put_exec_file(current);
66317+ return;
66318+}
66319+
66320+int
66321+gr_acl_handle_procpidmem(const struct task_struct *task)
66322+{
66323+ if (unlikely(!gr_acl_is_enabled()))
66324+ return 0;
66325+
66326+ if (task != current && task->acl->mode & GR_PROTPROCFD)
66327+ return -EACCES;
66328+
66329+ return 0;
66330+}
66331diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
66332new file mode 100644
66333index 0000000..f056b81
66334--- /dev/null
66335+++ b/grsecurity/gracl_ip.c
66336@@ -0,0 +1,386 @@
66337+#include <linux/kernel.h>
66338+#include <asm/uaccess.h>
66339+#include <asm/errno.h>
66340+#include <net/sock.h>
66341+#include <linux/file.h>
66342+#include <linux/fs.h>
66343+#include <linux/net.h>
66344+#include <linux/in.h>
66345+#include <linux/skbuff.h>
66346+#include <linux/ip.h>
66347+#include <linux/udp.h>
66348+#include <linux/types.h>
66349+#include <linux/sched.h>
66350+#include <linux/netdevice.h>
66351+#include <linux/inetdevice.h>
66352+#include <linux/gracl.h>
66353+#include <linux/grsecurity.h>
66354+#include <linux/grinternal.h>
66355+
66356+#define GR_BIND 0x01
66357+#define GR_CONNECT 0x02
66358+#define GR_INVERT 0x04
66359+#define GR_BINDOVERRIDE 0x08
66360+#define GR_CONNECTOVERRIDE 0x10
66361+#define GR_SOCK_FAMILY 0x20
66362+
66363+static const char * gr_protocols[IPPROTO_MAX] = {
66364+ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
66365+ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
66366+ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
66367+ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
66368+ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
66369+ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
66370+ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
66371+ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
66372+ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
66373+ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
66374+ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
66375+ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
66376+ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
66377+ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
66378+ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
66379+ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
66380+ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
66381+ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
66382+ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
66383+ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
66384+ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
66385+ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
66386+ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
66387+ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
66388+ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
66389+ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
66390+ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
66391+ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
66392+ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
66393+ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
66394+ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
66395+ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
66396+ };
66397+
66398+static const char * gr_socktypes[SOCK_MAX] = {
66399+ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
66400+ "unknown:7", "unknown:8", "unknown:9", "packet"
66401+ };
66402+
66403+static const char * gr_sockfamilies[AF_MAX+1] = {
66404+ "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
66405+ "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
66406+ "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
66407+ "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
66408+ };
66409+
66410+const char *
66411+gr_proto_to_name(unsigned char proto)
66412+{
66413+ return gr_protocols[proto];
66414+}
66415+
66416+const char *
66417+gr_socktype_to_name(unsigned char type)
66418+{
66419+ return gr_socktypes[type];
66420+}
66421+
66422+const char *
66423+gr_sockfamily_to_name(unsigned char family)
66424+{
66425+ return gr_sockfamilies[family];
66426+}
66427+
66428+extern const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
66429+
66430+int
66431+gr_search_socket(const int domain, const int type, const int protocol)
66432+{
66433+ struct acl_subject_label *curr;
66434+ const struct cred *cred = current_cred();
66435+
66436+ if (unlikely(!gr_acl_is_enabled()))
66437+ goto exit;
66438+
66439+ if ((domain < 0) || (type < 0) || (protocol < 0) ||
66440+ (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
66441+ goto exit; // let the kernel handle it
66442+
66443+ curr = current->acl;
66444+
66445+ if (curr->sock_families[domain / 32] & (1U << (domain % 32))) {
66446+ /* the family is allowed, if this is PF_INET allow it only if
66447+ the extra sock type/protocol checks pass */
66448+ if (domain == PF_INET)
66449+ goto inet_check;
66450+ goto exit;
66451+ } else {
66452+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
66453+ __u32 fakeip = 0;
66454+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
66455+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
66456+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
66457+ gr_to_filename(current->exec_file->f_path.dentry,
66458+ current->exec_file->f_path.mnt) :
66459+ curr->filename, curr->filename,
66460+ &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
66461+ &current->signal->saved_ip);
66462+ goto exit;
66463+ }
66464+ goto exit_fail;
66465+ }
66466+
66467+inet_check:
66468+ /* the rest of this checking is for IPv4 only */
66469+ if (!curr->ips)
66470+ goto exit;
66471+
66472+ if ((curr->ip_type & (1U << type)) &&
66473+ (curr->ip_proto[protocol / 32] & (1U << (protocol % 32))))
66474+ goto exit;
66475+
66476+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
66477+ /* we don't place acls on raw sockets , and sometimes
66478+ dgram/ip sockets are opened for ioctl and not
66479+ bind/connect, so we'll fake a bind learn log */
66480+ if (type == SOCK_RAW || type == SOCK_PACKET) {
66481+ __u32 fakeip = 0;
66482+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
66483+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
66484+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
66485+ gr_to_filename(current->exec_file->f_path.dentry,
66486+ current->exec_file->f_path.mnt) :
66487+ curr->filename, curr->filename,
66488+ &fakeip, 0, type,
66489+ protocol, GR_CONNECT, &current->signal->saved_ip);
66490+ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
66491+ __u32 fakeip = 0;
66492+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
66493+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
66494+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
66495+ gr_to_filename(current->exec_file->f_path.dentry,
66496+ current->exec_file->f_path.mnt) :
66497+ curr->filename, curr->filename,
66498+ &fakeip, 0, type,
66499+ protocol, GR_BIND, &current->signal->saved_ip);
66500+ }
66501+ /* we'll log when they use connect or bind */
66502+ goto exit;
66503+ }
66504+
66505+exit_fail:
66506+ if (domain == PF_INET)
66507+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
66508+ gr_socktype_to_name(type), gr_proto_to_name(protocol));
66509+ else if (rcu_access_pointer(net_families[domain]) != NULL)
66510+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
66511+ gr_socktype_to_name(type), protocol);
66512+
66513+ return 0;
66514+exit:
66515+ return 1;
66516+}
66517+
66518+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)
66519+{
66520+ if ((ip->mode & mode) &&
66521+ (ip_port >= ip->low) &&
66522+ (ip_port <= ip->high) &&
66523+ ((ntohl(ip_addr) & our_netmask) ==
66524+ (ntohl(our_addr) & our_netmask))
66525+ && (ip->proto[protocol / 32] & (1U << (protocol % 32)))
66526+ && (ip->type & (1U << type))) {
66527+ if (ip->mode & GR_INVERT)
66528+ return 2; // specifically denied
66529+ else
66530+ return 1; // allowed
66531+ }
66532+
66533+ return 0; // not specifically allowed, may continue parsing
66534+}
66535+
66536+static int
66537+gr_search_connectbind(const int full_mode, struct sock *sk,
66538+ struct sockaddr_in *addr, const int type)
66539+{
66540+ char iface[IFNAMSIZ] = {0};
66541+ struct acl_subject_label *curr;
66542+ struct acl_ip_label *ip;
66543+ struct inet_sock *isk;
66544+ struct net_device *dev;
66545+ struct in_device *idev;
66546+ unsigned long i;
66547+ int ret;
66548+ int mode = full_mode & (GR_BIND | GR_CONNECT);
66549+ __u32 ip_addr = 0;
66550+ __u32 our_addr;
66551+ __u32 our_netmask;
66552+ char *p;
66553+ __u16 ip_port = 0;
66554+ const struct cred *cred = current_cred();
66555+
66556+ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
66557+ return 0;
66558+
66559+ curr = current->acl;
66560+ isk = inet_sk(sk);
66561+
66562+ /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
66563+ if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
66564+ addr->sin_addr.s_addr = curr->inaddr_any_override;
66565+ if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
66566+ struct sockaddr_in saddr;
66567+ int err;
66568+
66569+ saddr.sin_family = AF_INET;
66570+ saddr.sin_addr.s_addr = curr->inaddr_any_override;
66571+ saddr.sin_port = isk->inet_sport;
66572+
66573+ err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
66574+ if (err)
66575+ return err;
66576+
66577+ err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
66578+ if (err)
66579+ return err;
66580+ }
66581+
66582+ if (!curr->ips)
66583+ return 0;
66584+
66585+ ip_addr = addr->sin_addr.s_addr;
66586+ ip_port = ntohs(addr->sin_port);
66587+
66588+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
66589+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
66590+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
66591+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
66592+ gr_to_filename(current->exec_file->f_path.dentry,
66593+ current->exec_file->f_path.mnt) :
66594+ curr->filename, curr->filename,
66595+ &ip_addr, ip_port, type,
66596+ sk->sk_protocol, mode, &current->signal->saved_ip);
66597+ return 0;
66598+ }
66599+
66600+ for (i = 0; i < curr->ip_num; i++) {
66601+ ip = *(curr->ips + i);
66602+ if (ip->iface != NULL) {
66603+ strncpy(iface, ip->iface, IFNAMSIZ - 1);
66604+ p = strchr(iface, ':');
66605+ if (p != NULL)
66606+ *p = '\0';
66607+ dev = dev_get_by_name(sock_net(sk), iface);
66608+ if (dev == NULL)
66609+ continue;
66610+ idev = in_dev_get(dev);
66611+ if (idev == NULL) {
66612+ dev_put(dev);
66613+ continue;
66614+ }
66615+ rcu_read_lock();
66616+ for_ifa(idev) {
66617+ if (!strcmp(ip->iface, ifa->ifa_label)) {
66618+ our_addr = ifa->ifa_address;
66619+ our_netmask = 0xffffffff;
66620+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
66621+ if (ret == 1) {
66622+ rcu_read_unlock();
66623+ in_dev_put(idev);
66624+ dev_put(dev);
66625+ return 0;
66626+ } else if (ret == 2) {
66627+ rcu_read_unlock();
66628+ in_dev_put(idev);
66629+ dev_put(dev);
66630+ goto denied;
66631+ }
66632+ }
66633+ } endfor_ifa(idev);
66634+ rcu_read_unlock();
66635+ in_dev_put(idev);
66636+ dev_put(dev);
66637+ } else {
66638+ our_addr = ip->addr;
66639+ our_netmask = ip->netmask;
66640+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
66641+ if (ret == 1)
66642+ return 0;
66643+ else if (ret == 2)
66644+ goto denied;
66645+ }
66646+ }
66647+
66648+denied:
66649+ if (mode == GR_BIND)
66650+ 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));
66651+ else if (mode == GR_CONNECT)
66652+ 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));
66653+
66654+ return -EACCES;
66655+}
66656+
66657+int
66658+gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
66659+{
66660+ /* always allow disconnection of dgram sockets with connect */
66661+ if (addr->sin_family == AF_UNSPEC)
66662+ return 0;
66663+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
66664+}
66665+
66666+int
66667+gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
66668+{
66669+ return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
66670+}
66671+
66672+int gr_search_listen(struct socket *sock)
66673+{
66674+ struct sock *sk = sock->sk;
66675+ struct sockaddr_in addr;
66676+
66677+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
66678+ addr.sin_port = inet_sk(sk)->inet_sport;
66679+
66680+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
66681+}
66682+
66683+int gr_search_accept(struct socket *sock)
66684+{
66685+ struct sock *sk = sock->sk;
66686+ struct sockaddr_in addr;
66687+
66688+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
66689+ addr.sin_port = inet_sk(sk)->inet_sport;
66690+
66691+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
66692+}
66693+
66694+int
66695+gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
66696+{
66697+ if (addr)
66698+ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
66699+ else {
66700+ struct sockaddr_in sin;
66701+ const struct inet_sock *inet = inet_sk(sk);
66702+
66703+ sin.sin_addr.s_addr = inet->inet_daddr;
66704+ sin.sin_port = inet->inet_dport;
66705+
66706+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
66707+ }
66708+}
66709+
66710+int
66711+gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
66712+{
66713+ struct sockaddr_in sin;
66714+
66715+ if (unlikely(skb->len < sizeof (struct udphdr)))
66716+ return 0; // skip this packet
66717+
66718+ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
66719+ sin.sin_port = udp_hdr(skb)->source;
66720+
66721+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
66722+}
66723diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
66724new file mode 100644
66725index 0000000..25f54ef
66726--- /dev/null
66727+++ b/grsecurity/gracl_learn.c
66728@@ -0,0 +1,207 @@
66729+#include <linux/kernel.h>
66730+#include <linux/mm.h>
66731+#include <linux/sched.h>
66732+#include <linux/poll.h>
66733+#include <linux/string.h>
66734+#include <linux/file.h>
66735+#include <linux/types.h>
66736+#include <linux/vmalloc.h>
66737+#include <linux/grinternal.h>
66738+
66739+extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
66740+ size_t count, loff_t *ppos);
66741+extern int gr_acl_is_enabled(void);
66742+
66743+static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
66744+static int gr_learn_attached;
66745+
66746+/* use a 512k buffer */
66747+#define LEARN_BUFFER_SIZE (512 * 1024)
66748+
66749+static DEFINE_SPINLOCK(gr_learn_lock);
66750+static DEFINE_MUTEX(gr_learn_user_mutex);
66751+
66752+/* we need to maintain two buffers, so that the kernel context of grlearn
66753+ uses a semaphore around the userspace copying, and the other kernel contexts
66754+ use a spinlock when copying into the buffer, since they cannot sleep
66755+*/
66756+static char *learn_buffer;
66757+static char *learn_buffer_user;
66758+static int learn_buffer_len;
66759+static int learn_buffer_user_len;
66760+
66761+static ssize_t
66762+read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
66763+{
66764+ DECLARE_WAITQUEUE(wait, current);
66765+ ssize_t retval = 0;
66766+
66767+ add_wait_queue(&learn_wait, &wait);
66768+ set_current_state(TASK_INTERRUPTIBLE);
66769+ do {
66770+ mutex_lock(&gr_learn_user_mutex);
66771+ spin_lock(&gr_learn_lock);
66772+ if (learn_buffer_len)
66773+ break;
66774+ spin_unlock(&gr_learn_lock);
66775+ mutex_unlock(&gr_learn_user_mutex);
66776+ if (file->f_flags & O_NONBLOCK) {
66777+ retval = -EAGAIN;
66778+ goto out;
66779+ }
66780+ if (signal_pending(current)) {
66781+ retval = -ERESTARTSYS;
66782+ goto out;
66783+ }
66784+
66785+ schedule();
66786+ } while (1);
66787+
66788+ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
66789+ learn_buffer_user_len = learn_buffer_len;
66790+ retval = learn_buffer_len;
66791+ learn_buffer_len = 0;
66792+
66793+ spin_unlock(&gr_learn_lock);
66794+
66795+ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
66796+ retval = -EFAULT;
66797+
66798+ mutex_unlock(&gr_learn_user_mutex);
66799+out:
66800+ set_current_state(TASK_RUNNING);
66801+ remove_wait_queue(&learn_wait, &wait);
66802+ return retval;
66803+}
66804+
66805+static unsigned int
66806+poll_learn(struct file * file, poll_table * wait)
66807+{
66808+ poll_wait(file, &learn_wait, wait);
66809+
66810+ if (learn_buffer_len)
66811+ return (POLLIN | POLLRDNORM);
66812+
66813+ return 0;
66814+}
66815+
66816+void
66817+gr_clear_learn_entries(void)
66818+{
66819+ char *tmp;
66820+
66821+ mutex_lock(&gr_learn_user_mutex);
66822+ spin_lock(&gr_learn_lock);
66823+ tmp = learn_buffer;
66824+ learn_buffer = NULL;
66825+ spin_unlock(&gr_learn_lock);
66826+ if (tmp)
66827+ vfree(tmp);
66828+ if (learn_buffer_user != NULL) {
66829+ vfree(learn_buffer_user);
66830+ learn_buffer_user = NULL;
66831+ }
66832+ learn_buffer_len = 0;
66833+ mutex_unlock(&gr_learn_user_mutex);
66834+
66835+ return;
66836+}
66837+
66838+void
66839+gr_add_learn_entry(const char *fmt, ...)
66840+{
66841+ va_list args;
66842+ unsigned int len;
66843+
66844+ if (!gr_learn_attached)
66845+ return;
66846+
66847+ spin_lock(&gr_learn_lock);
66848+
66849+ /* leave a gap at the end so we know when it's "full" but don't have to
66850+ compute the exact length of the string we're trying to append
66851+ */
66852+ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
66853+ spin_unlock(&gr_learn_lock);
66854+ wake_up_interruptible(&learn_wait);
66855+ return;
66856+ }
66857+ if (learn_buffer == NULL) {
66858+ spin_unlock(&gr_learn_lock);
66859+ return;
66860+ }
66861+
66862+ va_start(args, fmt);
66863+ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
66864+ va_end(args);
66865+
66866+ learn_buffer_len += len + 1;
66867+
66868+ spin_unlock(&gr_learn_lock);
66869+ wake_up_interruptible(&learn_wait);
66870+
66871+ return;
66872+}
66873+
66874+static int
66875+open_learn(struct inode *inode, struct file *file)
66876+{
66877+ if (file->f_mode & FMODE_READ && gr_learn_attached)
66878+ return -EBUSY;
66879+ if (file->f_mode & FMODE_READ) {
66880+ int retval = 0;
66881+ mutex_lock(&gr_learn_user_mutex);
66882+ if (learn_buffer == NULL)
66883+ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
66884+ if (learn_buffer_user == NULL)
66885+ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
66886+ if (learn_buffer == NULL) {
66887+ retval = -ENOMEM;
66888+ goto out_error;
66889+ }
66890+ if (learn_buffer_user == NULL) {
66891+ retval = -ENOMEM;
66892+ goto out_error;
66893+ }
66894+ learn_buffer_len = 0;
66895+ learn_buffer_user_len = 0;
66896+ gr_learn_attached = 1;
66897+out_error:
66898+ mutex_unlock(&gr_learn_user_mutex);
66899+ return retval;
66900+ }
66901+ return 0;
66902+}
66903+
66904+static int
66905+close_learn(struct inode *inode, struct file *file)
66906+{
66907+ if (file->f_mode & FMODE_READ) {
66908+ char *tmp = NULL;
66909+ mutex_lock(&gr_learn_user_mutex);
66910+ spin_lock(&gr_learn_lock);
66911+ tmp = learn_buffer;
66912+ learn_buffer = NULL;
66913+ spin_unlock(&gr_learn_lock);
66914+ if (tmp)
66915+ vfree(tmp);
66916+ if (learn_buffer_user != NULL) {
66917+ vfree(learn_buffer_user);
66918+ learn_buffer_user = NULL;
66919+ }
66920+ learn_buffer_len = 0;
66921+ learn_buffer_user_len = 0;
66922+ gr_learn_attached = 0;
66923+ mutex_unlock(&gr_learn_user_mutex);
66924+ }
66925+
66926+ return 0;
66927+}
66928+
66929+const struct file_operations grsec_fops = {
66930+ .read = read_learn,
66931+ .write = write_grsec_handler,
66932+ .open = open_learn,
66933+ .release = close_learn,
66934+ .poll = poll_learn,
66935+};
66936diff --git a/grsecurity/gracl_policy.c b/grsecurity/gracl_policy.c
66937new file mode 100644
66938index 0000000..d409f33
66939--- /dev/null
66940+++ b/grsecurity/gracl_policy.c
66941@@ -0,0 +1,1825 @@
66942+#include <linux/kernel.h>
66943+#include <linux/module.h>
66944+#include <linux/sched.h>
66945+#include <linux/mm.h>
66946+#include <linux/file.h>
66947+#include <linux/fs.h>
66948+#include <linux/namei.h>
66949+#include <linux/mount.h>
66950+#include <linux/tty.h>
66951+#include <linux/proc_fs.h>
66952+#include <linux/lglock.h>
66953+#include <linux/slab.h>
66954+#include <linux/vmalloc.h>
66955+#include <linux/types.h>
66956+#include <linux/sysctl.h>
66957+#include <linux/netdevice.h>
66958+#include <linux/ptrace.h>
66959+#include <linux/gracl.h>
66960+#include <linux/gralloc.h>
66961+#include <linux/security.h>
66962+#include <linux/grinternal.h>
66963+#include <linux/pid_namespace.h>
66964+#include <linux/stop_machine.h>
66965+#include <linux/fdtable.h>
66966+#include <linux/percpu.h>
66967+#include <linux/lglock.h>
66968+#include <linux/hugetlb.h>
66969+#include <linux/posix-timers.h>
66970+#include "../fs/mount.h"
66971+
66972+#include <asm/uaccess.h>
66973+#include <asm/errno.h>
66974+#include <asm/mman.h>
66975+
66976+extern struct gr_policy_state *polstate;
66977+
66978+#define FOR_EACH_ROLE_START(role) \
66979+ role = polstate->role_list; \
66980+ while (role) {
66981+
66982+#define FOR_EACH_ROLE_END(role) \
66983+ role = role->prev; \
66984+ }
66985+
66986+struct path gr_real_root;
66987+
66988+extern struct gr_alloc_state *current_alloc_state;
66989+
66990+u16 acl_sp_role_value;
66991+
66992+static DEFINE_MUTEX(gr_dev_mutex);
66993+
66994+extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
66995+extern void gr_clear_learn_entries(void);
66996+
66997+static struct gr_arg gr_usermode;
66998+static unsigned char gr_system_salt[GR_SALT_LEN];
66999+static unsigned char gr_system_sum[GR_SHA_LEN];
67000+
67001+static unsigned int gr_auth_attempts = 0;
67002+static unsigned long gr_auth_expires = 0UL;
67003+
67004+struct acl_object_label *fakefs_obj_rw;
67005+struct acl_object_label *fakefs_obj_rwx;
67006+
67007+extern int gr_init_uidset(void);
67008+extern void gr_free_uidset(void);
67009+extern void gr_remove_uid(uid_t uid);
67010+extern int gr_find_uid(uid_t uid);
67011+
67012+extern void __gr_apply_subject_to_task(struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj);
67013+extern int gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb);
67014+extern void __insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry);
67015+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);
67016+extern void insert_acl_obj_label(struct acl_object_label *obj, struct acl_subject_label *subj);
67017+extern void insert_acl_subj_label(struct acl_subject_label *obj, struct acl_role_label *role);
67018+extern struct name_entry * __lookup_name_entry(const struct gr_policy_state *state, const char *name);
67019+extern char *gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt);
67020+extern struct acl_subject_label *lookup_acl_subj_label(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
67021+extern struct acl_subject_label *lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
67022+extern void assign_special_role(const char *rolename);
67023+extern struct acl_subject_label *chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt, const struct acl_role_label *role);
67024+extern int gr_rbac_disable(void *unused);
67025+extern void gr_enable_rbac_system(void);
67026+
67027+static int copy_acl_object_label_normal(struct acl_object_label *obj, const struct acl_object_label *userp)
67028+{
67029+ if (copy_from_user(obj, userp, sizeof(struct acl_object_label)))
67030+ return -EFAULT;
67031+
67032+ return 0;
67033+}
67034+
67035+static int copy_acl_ip_label_normal(struct acl_ip_label *ip, const struct acl_ip_label *userp)
67036+{
67037+ if (copy_from_user(ip, userp, sizeof(struct acl_ip_label)))
67038+ return -EFAULT;
67039+
67040+ return 0;
67041+}
67042+
67043+static int copy_acl_subject_label_normal(struct acl_subject_label *subj, const struct acl_subject_label *userp)
67044+{
67045+ if (copy_from_user(subj, userp, sizeof(struct acl_subject_label)))
67046+ return -EFAULT;
67047+
67048+ return 0;
67049+}
67050+
67051+static int copy_acl_role_label_normal(struct acl_role_label *role, const struct acl_role_label *userp)
67052+{
67053+ if (copy_from_user(role, userp, sizeof(struct acl_role_label)))
67054+ return -EFAULT;
67055+
67056+ return 0;
67057+}
67058+
67059+static int copy_role_allowed_ip_normal(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
67060+{
67061+ if (copy_from_user(roleip, userp, sizeof(struct role_allowed_ip)))
67062+ return -EFAULT;
67063+
67064+ return 0;
67065+}
67066+
67067+static int copy_sprole_pw_normal(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
67068+{
67069+ if (copy_from_user(pw, userp + idx, sizeof(struct sprole_pw)))
67070+ return -EFAULT;
67071+
67072+ return 0;
67073+}
67074+
67075+static int copy_gr_hash_struct_normal(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
67076+{
67077+ if (copy_from_user(hash, userp, sizeof(struct gr_hash_struct)))
67078+ return -EFAULT;
67079+
67080+ return 0;
67081+}
67082+
67083+static int copy_role_transition_normal(struct role_transition *trans, const struct role_transition *userp)
67084+{
67085+ if (copy_from_user(trans, userp, sizeof(struct role_transition)))
67086+ return -EFAULT;
67087+
67088+ return 0;
67089+}
67090+
67091+int copy_pointer_from_array_normal(void *ptr, unsigned long idx, const void *userp)
67092+{
67093+ if (copy_from_user(ptr, userp + (idx * sizeof(void *)), sizeof(void *)))
67094+ return -EFAULT;
67095+
67096+ return 0;
67097+}
67098+
67099+static int copy_gr_arg_wrapper_normal(const char __user *buf, struct gr_arg_wrapper *uwrap)
67100+{
67101+ if (copy_from_user(uwrap, buf, sizeof (struct gr_arg_wrapper)))
67102+ return -EFAULT;
67103+
67104+ if (((uwrap->version != GRSECURITY_VERSION) &&
67105+ (uwrap->version != 0x2901)) ||
67106+ (uwrap->size != sizeof(struct gr_arg)))
67107+ return -EINVAL;
67108+
67109+ return 0;
67110+}
67111+
67112+static int copy_gr_arg_normal(const struct gr_arg __user *buf, struct gr_arg *arg)
67113+{
67114+ if (copy_from_user(arg, buf, sizeof (struct gr_arg)))
67115+ return -EFAULT;
67116+
67117+ return 0;
67118+}
67119+
67120+static size_t get_gr_arg_wrapper_size_normal(void)
67121+{
67122+ return sizeof(struct gr_arg_wrapper);
67123+}
67124+
67125+#ifdef CONFIG_COMPAT
67126+extern int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap);
67127+extern int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg);
67128+extern int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp);
67129+extern int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp);
67130+extern int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp);
67131+extern int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp);
67132+extern int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp);
67133+extern int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp);
67134+extern int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp);
67135+extern int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp);
67136+extern int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp);
67137+extern size_t get_gr_arg_wrapper_size_compat(void);
67138+
67139+int (* copy_gr_arg_wrapper)(const char *buf, struct gr_arg_wrapper *uwrap) __read_only;
67140+int (* copy_gr_arg)(const struct gr_arg *buf, struct gr_arg *arg) __read_only;
67141+int (* copy_acl_object_label)(struct acl_object_label *obj, const struct acl_object_label *userp) __read_only;
67142+int (* copy_acl_subject_label)(struct acl_subject_label *subj, const struct acl_subject_label *userp) __read_only;
67143+int (* copy_acl_role_label)(struct acl_role_label *role, const struct acl_role_label *userp) __read_only;
67144+int (* copy_acl_ip_label)(struct acl_ip_label *ip, const struct acl_ip_label *userp) __read_only;
67145+int (* copy_pointer_from_array)(void *ptr, unsigned long idx, const void *userp) __read_only;
67146+int (* copy_sprole_pw)(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp) __read_only;
67147+int (* copy_gr_hash_struct)(struct gr_hash_struct *hash, const struct gr_hash_struct *userp) __read_only;
67148+int (* copy_role_transition)(struct role_transition *trans, const struct role_transition *userp) __read_only;
67149+int (* copy_role_allowed_ip)(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp) __read_only;
67150+size_t (* get_gr_arg_wrapper_size)(void) __read_only;
67151+
67152+#else
67153+#define copy_gr_arg_wrapper copy_gr_arg_wrapper_normal
67154+#define copy_gr_arg copy_gr_arg_normal
67155+#define copy_gr_hash_struct copy_gr_hash_struct_normal
67156+#define copy_acl_object_label copy_acl_object_label_normal
67157+#define copy_acl_subject_label copy_acl_subject_label_normal
67158+#define copy_acl_role_label copy_acl_role_label_normal
67159+#define copy_acl_ip_label copy_acl_ip_label_normal
67160+#define copy_pointer_from_array copy_pointer_from_array_normal
67161+#define copy_sprole_pw copy_sprole_pw_normal
67162+#define copy_role_transition copy_role_transition_normal
67163+#define copy_role_allowed_ip copy_role_allowed_ip_normal
67164+#define get_gr_arg_wrapper_size get_gr_arg_wrapper_size_normal
67165+#endif
67166+
67167+static struct acl_subject_label *
67168+lookup_subject_map(const struct acl_subject_label *userp)
67169+{
67170+ unsigned int index = gr_shash(userp, polstate->subj_map_set.s_size);
67171+ struct subject_map *match;
67172+
67173+ match = polstate->subj_map_set.s_hash[index];
67174+
67175+ while (match && match->user != userp)
67176+ match = match->next;
67177+
67178+ if (match != NULL)
67179+ return match->kernel;
67180+ else
67181+ return NULL;
67182+}
67183+
67184+static void
67185+insert_subj_map_entry(struct subject_map *subjmap)
67186+{
67187+ unsigned int index = gr_shash(subjmap->user, polstate->subj_map_set.s_size);
67188+ struct subject_map **curr;
67189+
67190+ subjmap->prev = NULL;
67191+
67192+ curr = &polstate->subj_map_set.s_hash[index];
67193+ if (*curr != NULL)
67194+ (*curr)->prev = subjmap;
67195+
67196+ subjmap->next = *curr;
67197+ *curr = subjmap;
67198+
67199+ return;
67200+}
67201+
67202+static void
67203+__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
67204+{
67205+ unsigned int index =
67206+ gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), polstate->acl_role_set.r_size);
67207+ struct acl_role_label **curr;
67208+ struct acl_role_label *tmp, *tmp2;
67209+
67210+ curr = &polstate->acl_role_set.r_hash[index];
67211+
67212+ /* simple case, slot is empty, just set it to our role */
67213+ if (*curr == NULL) {
67214+ *curr = role;
67215+ } else {
67216+ /* example:
67217+ 1 -> 2 -> 3 (adding 2 -> 3 to here)
67218+ 2 -> 3
67219+ */
67220+ /* first check to see if we can already be reached via this slot */
67221+ tmp = *curr;
67222+ while (tmp && tmp != role)
67223+ tmp = tmp->next;
67224+ if (tmp == role) {
67225+ /* we don't need to add ourselves to this slot's chain */
67226+ return;
67227+ }
67228+ /* we need to add ourselves to this chain, two cases */
67229+ if (role->next == NULL) {
67230+ /* simple case, append the current chain to our role */
67231+ role->next = *curr;
67232+ *curr = role;
67233+ } else {
67234+ /* 1 -> 2 -> 3 -> 4
67235+ 2 -> 3 -> 4
67236+ 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
67237+ */
67238+ /* trickier case: walk our role's chain until we find
67239+ the role for the start of the current slot's chain */
67240+ tmp = role;
67241+ tmp2 = *curr;
67242+ while (tmp->next && tmp->next != tmp2)
67243+ tmp = tmp->next;
67244+ if (tmp->next == tmp2) {
67245+ /* from example above, we found 3, so just
67246+ replace this slot's chain with ours */
67247+ *curr = role;
67248+ } else {
67249+ /* we didn't find a subset of our role's chain
67250+ in the current slot's chain, so append their
67251+ chain to ours, and set us as the first role in
67252+ the slot's chain
67253+
67254+ we could fold this case with the case above,
67255+ but making it explicit for clarity
67256+ */
67257+ tmp->next = tmp2;
67258+ *curr = role;
67259+ }
67260+ }
67261+ }
67262+
67263+ return;
67264+}
67265+
67266+static void
67267+insert_acl_role_label(struct acl_role_label *role)
67268+{
67269+ int i;
67270+
67271+ if (polstate->role_list == NULL) {
67272+ polstate->role_list = role;
67273+ role->prev = NULL;
67274+ } else {
67275+ role->prev = polstate->role_list;
67276+ polstate->role_list = role;
67277+ }
67278+
67279+ /* used for hash chains */
67280+ role->next = NULL;
67281+
67282+ if (role->roletype & GR_ROLE_DOMAIN) {
67283+ for (i = 0; i < role->domain_child_num; i++)
67284+ __insert_acl_role_label(role, role->domain_children[i]);
67285+ } else
67286+ __insert_acl_role_label(role, role->uidgid);
67287+}
67288+
67289+static int
67290+insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
67291+{
67292+ struct name_entry **curr, *nentry;
67293+ struct inodev_entry *ientry;
67294+ unsigned int len = strlen(name);
67295+ unsigned int key = full_name_hash(name, len);
67296+ unsigned int index = key % polstate->name_set.n_size;
67297+
67298+ curr = &polstate->name_set.n_hash[index];
67299+
67300+ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
67301+ curr = &((*curr)->next);
67302+
67303+ if (*curr != NULL)
67304+ return 1;
67305+
67306+ nentry = acl_alloc(sizeof (struct name_entry));
67307+ if (nentry == NULL)
67308+ return 0;
67309+ ientry = acl_alloc(sizeof (struct inodev_entry));
67310+ if (ientry == NULL)
67311+ return 0;
67312+ ientry->nentry = nentry;
67313+
67314+ nentry->key = key;
67315+ nentry->name = name;
67316+ nentry->inode = inode;
67317+ nentry->device = device;
67318+ nentry->len = len;
67319+ nentry->deleted = deleted;
67320+
67321+ nentry->prev = NULL;
67322+ curr = &polstate->name_set.n_hash[index];
67323+ if (*curr != NULL)
67324+ (*curr)->prev = nentry;
67325+ nentry->next = *curr;
67326+ *curr = nentry;
67327+
67328+ /* insert us into the table searchable by inode/dev */
67329+ __insert_inodev_entry(polstate, ientry);
67330+
67331+ return 1;
67332+}
67333+
67334+/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
67335+
67336+static void *
67337+create_table(__u32 * len, int elementsize)
67338+{
67339+ unsigned int table_sizes[] = {
67340+ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
67341+ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
67342+ 4194301, 8388593, 16777213, 33554393, 67108859
67343+ };
67344+ void *newtable = NULL;
67345+ unsigned int pwr = 0;
67346+
67347+ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
67348+ table_sizes[pwr] <= *len)
67349+ pwr++;
67350+
67351+ if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
67352+ return newtable;
67353+
67354+ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
67355+ newtable =
67356+ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
67357+ else
67358+ newtable = vmalloc(table_sizes[pwr] * elementsize);
67359+
67360+ *len = table_sizes[pwr];
67361+
67362+ return newtable;
67363+}
67364+
67365+static int
67366+init_variables(const struct gr_arg *arg, bool reload)
67367+{
67368+ struct task_struct *reaper = init_pid_ns.child_reaper;
67369+ unsigned int stacksize;
67370+
67371+ polstate->subj_map_set.s_size = arg->role_db.num_subjects;
67372+ polstate->acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
67373+ polstate->name_set.n_size = arg->role_db.num_objects;
67374+ polstate->inodev_set.i_size = arg->role_db.num_objects;
67375+
67376+ if (!polstate->subj_map_set.s_size || !polstate->acl_role_set.r_size ||
67377+ !polstate->name_set.n_size || !polstate->inodev_set.i_size)
67378+ return 1;
67379+
67380+ if (!reload) {
67381+ if (!gr_init_uidset())
67382+ return 1;
67383+ }
67384+
67385+ /* set up the stack that holds allocation info */
67386+
67387+ stacksize = arg->role_db.num_pointers + 5;
67388+
67389+ if (!acl_alloc_stack_init(stacksize))
67390+ return 1;
67391+
67392+ if (!reload) {
67393+ /* grab reference for the real root dentry and vfsmount */
67394+ get_fs_root(reaper->fs, &gr_real_root);
67395+
67396+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
67397+ 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);
67398+#endif
67399+
67400+ fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
67401+ if (fakefs_obj_rw == NULL)
67402+ return 1;
67403+ fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
67404+
67405+ fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
67406+ if (fakefs_obj_rwx == NULL)
67407+ return 1;
67408+ fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
67409+ }
67410+
67411+ polstate->subj_map_set.s_hash =
67412+ (struct subject_map **) create_table(&polstate->subj_map_set.s_size, sizeof(void *));
67413+ polstate->acl_role_set.r_hash =
67414+ (struct acl_role_label **) create_table(&polstate->acl_role_set.r_size, sizeof(void *));
67415+ polstate->name_set.n_hash = (struct name_entry **) create_table(&polstate->name_set.n_size, sizeof(void *));
67416+ polstate->inodev_set.i_hash =
67417+ (struct inodev_entry **) create_table(&polstate->inodev_set.i_size, sizeof(void *));
67418+
67419+ if (!polstate->subj_map_set.s_hash || !polstate->acl_role_set.r_hash ||
67420+ !polstate->name_set.n_hash || !polstate->inodev_set.i_hash)
67421+ return 1;
67422+
67423+ memset(polstate->subj_map_set.s_hash, 0,
67424+ sizeof(struct subject_map *) * polstate->subj_map_set.s_size);
67425+ memset(polstate->acl_role_set.r_hash, 0,
67426+ sizeof (struct acl_role_label *) * polstate->acl_role_set.r_size);
67427+ memset(polstate->name_set.n_hash, 0,
67428+ sizeof (struct name_entry *) * polstate->name_set.n_size);
67429+ memset(polstate->inodev_set.i_hash, 0,
67430+ sizeof (struct inodev_entry *) * polstate->inodev_set.i_size);
67431+
67432+ return 0;
67433+}
67434+
67435+/* free information not needed after startup
67436+ currently contains user->kernel pointer mappings for subjects
67437+*/
67438+
67439+static void
67440+free_init_variables(void)
67441+{
67442+ __u32 i;
67443+
67444+ if (polstate->subj_map_set.s_hash) {
67445+ for (i = 0; i < polstate->subj_map_set.s_size; i++) {
67446+ if (polstate->subj_map_set.s_hash[i]) {
67447+ kfree(polstate->subj_map_set.s_hash[i]);
67448+ polstate->subj_map_set.s_hash[i] = NULL;
67449+ }
67450+ }
67451+
67452+ if ((polstate->subj_map_set.s_size * sizeof (struct subject_map *)) <=
67453+ PAGE_SIZE)
67454+ kfree(polstate->subj_map_set.s_hash);
67455+ else
67456+ vfree(polstate->subj_map_set.s_hash);
67457+ }
67458+
67459+ return;
67460+}
67461+
67462+static void
67463+free_variables(bool reload)
67464+{
67465+ struct acl_subject_label *s;
67466+ struct acl_role_label *r;
67467+ struct task_struct *task, *task2;
67468+ unsigned int x;
67469+
67470+ if (!reload) {
67471+ gr_clear_learn_entries();
67472+
67473+ read_lock(&tasklist_lock);
67474+ do_each_thread(task2, task) {
67475+ task->acl_sp_role = 0;
67476+ task->acl_role_id = 0;
67477+ task->inherited = 0;
67478+ task->acl = NULL;
67479+ task->role = NULL;
67480+ } while_each_thread(task2, task);
67481+ read_unlock(&tasklist_lock);
67482+
67483+ /* release the reference to the real root dentry and vfsmount */
67484+ path_put(&gr_real_root);
67485+ memset(&gr_real_root, 0, sizeof(gr_real_root));
67486+ }
67487+
67488+ /* free all object hash tables */
67489+
67490+ FOR_EACH_ROLE_START(r)
67491+ if (r->subj_hash == NULL)
67492+ goto next_role;
67493+ FOR_EACH_SUBJECT_START(r, s, x)
67494+ if (s->obj_hash == NULL)
67495+ break;
67496+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
67497+ kfree(s->obj_hash);
67498+ else
67499+ vfree(s->obj_hash);
67500+ FOR_EACH_SUBJECT_END(s, x)
67501+ FOR_EACH_NESTED_SUBJECT_START(r, s)
67502+ if (s->obj_hash == NULL)
67503+ break;
67504+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
67505+ kfree(s->obj_hash);
67506+ else
67507+ vfree(s->obj_hash);
67508+ FOR_EACH_NESTED_SUBJECT_END(s)
67509+ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
67510+ kfree(r->subj_hash);
67511+ else
67512+ vfree(r->subj_hash);
67513+ r->subj_hash = NULL;
67514+next_role:
67515+ FOR_EACH_ROLE_END(r)
67516+
67517+ acl_free_all();
67518+
67519+ if (polstate->acl_role_set.r_hash) {
67520+ if ((polstate->acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
67521+ PAGE_SIZE)
67522+ kfree(polstate->acl_role_set.r_hash);
67523+ else
67524+ vfree(polstate->acl_role_set.r_hash);
67525+ }
67526+ if (polstate->name_set.n_hash) {
67527+ if ((polstate->name_set.n_size * sizeof (struct name_entry *)) <=
67528+ PAGE_SIZE)
67529+ kfree(polstate->name_set.n_hash);
67530+ else
67531+ vfree(polstate->name_set.n_hash);
67532+ }
67533+
67534+ if (polstate->inodev_set.i_hash) {
67535+ if ((polstate->inodev_set.i_size * sizeof (struct inodev_entry *)) <=
67536+ PAGE_SIZE)
67537+ kfree(polstate->inodev_set.i_hash);
67538+ else
67539+ vfree(polstate->inodev_set.i_hash);
67540+ }
67541+
67542+ if (!reload)
67543+ gr_free_uidset();
67544+
67545+ memset(&polstate->name_set, 0, sizeof (struct name_db));
67546+ memset(&polstate->inodev_set, 0, sizeof (struct inodev_db));
67547+ memset(&polstate->acl_role_set, 0, sizeof (struct acl_role_db));
67548+ memset(&polstate->subj_map_set, 0, sizeof (struct acl_subj_map_db));
67549+
67550+ polstate->default_role = NULL;
67551+ polstate->kernel_role = NULL;
67552+ polstate->role_list = NULL;
67553+
67554+ return;
67555+}
67556+
67557+static struct acl_subject_label *
67558+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
67559+
67560+static int alloc_and_copy_string(char **name, unsigned int maxlen)
67561+{
67562+ unsigned int len = strnlen_user(*name, maxlen);
67563+ char *tmp;
67564+
67565+ if (!len || len >= maxlen)
67566+ return -EINVAL;
67567+
67568+ if ((tmp = (char *) acl_alloc(len)) == NULL)
67569+ return -ENOMEM;
67570+
67571+ if (copy_from_user(tmp, *name, len))
67572+ return -EFAULT;
67573+
67574+ tmp[len-1] = '\0';
67575+ *name = tmp;
67576+
67577+ return 0;
67578+}
67579+
67580+static int
67581+copy_user_glob(struct acl_object_label *obj)
67582+{
67583+ struct acl_object_label *g_tmp, **guser;
67584+ int error;
67585+
67586+ if (obj->globbed == NULL)
67587+ return 0;
67588+
67589+ guser = &obj->globbed;
67590+ while (*guser) {
67591+ g_tmp = (struct acl_object_label *)
67592+ acl_alloc(sizeof (struct acl_object_label));
67593+ if (g_tmp == NULL)
67594+ return -ENOMEM;
67595+
67596+ if (copy_acl_object_label(g_tmp, *guser))
67597+ return -EFAULT;
67598+
67599+ error = alloc_and_copy_string(&g_tmp->filename, PATH_MAX);
67600+ if (error)
67601+ return error;
67602+
67603+ *guser = g_tmp;
67604+ guser = &(g_tmp->next);
67605+ }
67606+
67607+ return 0;
67608+}
67609+
67610+static int
67611+copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
67612+ struct acl_role_label *role)
67613+{
67614+ struct acl_object_label *o_tmp;
67615+ int ret;
67616+
67617+ while (userp) {
67618+ if ((o_tmp = (struct acl_object_label *)
67619+ acl_alloc(sizeof (struct acl_object_label))) == NULL)
67620+ return -ENOMEM;
67621+
67622+ if (copy_acl_object_label(o_tmp, userp))
67623+ return -EFAULT;
67624+
67625+ userp = o_tmp->prev;
67626+
67627+ ret = alloc_and_copy_string(&o_tmp->filename, PATH_MAX);
67628+ if (ret)
67629+ return ret;
67630+
67631+ insert_acl_obj_label(o_tmp, subj);
67632+ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
67633+ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
67634+ return -ENOMEM;
67635+
67636+ ret = copy_user_glob(o_tmp);
67637+ if (ret)
67638+ return ret;
67639+
67640+ if (o_tmp->nested) {
67641+ int already_copied;
67642+
67643+ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
67644+ if (IS_ERR(o_tmp->nested))
67645+ return PTR_ERR(o_tmp->nested);
67646+
67647+ /* insert into nested subject list if we haven't copied this one yet
67648+ to prevent duplicate entries */
67649+ if (!already_copied) {
67650+ o_tmp->nested->next = role->hash->first;
67651+ role->hash->first = o_tmp->nested;
67652+ }
67653+ }
67654+ }
67655+
67656+ return 0;
67657+}
67658+
67659+static __u32
67660+count_user_subjs(struct acl_subject_label *userp)
67661+{
67662+ struct acl_subject_label s_tmp;
67663+ __u32 num = 0;
67664+
67665+ while (userp) {
67666+ if (copy_acl_subject_label(&s_tmp, userp))
67667+ break;
67668+
67669+ userp = s_tmp.prev;
67670+ }
67671+
67672+ return num;
67673+}
67674+
67675+static int
67676+copy_user_allowedips(struct acl_role_label *rolep)
67677+{
67678+ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
67679+
67680+ ruserip = rolep->allowed_ips;
67681+
67682+ while (ruserip) {
67683+ rlast = rtmp;
67684+
67685+ if ((rtmp = (struct role_allowed_ip *)
67686+ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
67687+ return -ENOMEM;
67688+
67689+ if (copy_role_allowed_ip(rtmp, ruserip))
67690+ return -EFAULT;
67691+
67692+ ruserip = rtmp->prev;
67693+
67694+ if (!rlast) {
67695+ rtmp->prev = NULL;
67696+ rolep->allowed_ips = rtmp;
67697+ } else {
67698+ rlast->next = rtmp;
67699+ rtmp->prev = rlast;
67700+ }
67701+
67702+ if (!ruserip)
67703+ rtmp->next = NULL;
67704+ }
67705+
67706+ return 0;
67707+}
67708+
67709+static int
67710+copy_user_transitions(struct acl_role_label *rolep)
67711+{
67712+ struct role_transition *rusertp, *rtmp = NULL, *rlast;
67713+ int error;
67714+
67715+ rusertp = rolep->transitions;
67716+
67717+ while (rusertp) {
67718+ rlast = rtmp;
67719+
67720+ if ((rtmp = (struct role_transition *)
67721+ acl_alloc(sizeof (struct role_transition))) == NULL)
67722+ return -ENOMEM;
67723+
67724+ if (copy_role_transition(rtmp, rusertp))
67725+ return -EFAULT;
67726+
67727+ rusertp = rtmp->prev;
67728+
67729+ error = alloc_and_copy_string(&rtmp->rolename, GR_SPROLE_LEN);
67730+ if (error)
67731+ return error;
67732+
67733+ if (!rlast) {
67734+ rtmp->prev = NULL;
67735+ rolep->transitions = rtmp;
67736+ } else {
67737+ rlast->next = rtmp;
67738+ rtmp->prev = rlast;
67739+ }
67740+
67741+ if (!rusertp)
67742+ rtmp->next = NULL;
67743+ }
67744+
67745+ return 0;
67746+}
67747+
67748+static __u32 count_user_objs(const struct acl_object_label __user *userp)
67749+{
67750+ struct acl_object_label o_tmp;
67751+ __u32 num = 0;
67752+
67753+ while (userp) {
67754+ if (copy_acl_object_label(&o_tmp, userp))
67755+ break;
67756+
67757+ userp = o_tmp.prev;
67758+ num++;
67759+ }
67760+
67761+ return num;
67762+}
67763+
67764+static struct acl_subject_label *
67765+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
67766+{
67767+ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
67768+ __u32 num_objs;
67769+ struct acl_ip_label **i_tmp, *i_utmp2;
67770+ struct gr_hash_struct ghash;
67771+ struct subject_map *subjmap;
67772+ unsigned int i_num;
67773+ int err;
67774+
67775+ if (already_copied != NULL)
67776+ *already_copied = 0;
67777+
67778+ s_tmp = lookup_subject_map(userp);
67779+
67780+ /* we've already copied this subject into the kernel, just return
67781+ the reference to it, and don't copy it over again
67782+ */
67783+ if (s_tmp) {
67784+ if (already_copied != NULL)
67785+ *already_copied = 1;
67786+ return(s_tmp);
67787+ }
67788+
67789+ if ((s_tmp = (struct acl_subject_label *)
67790+ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
67791+ return ERR_PTR(-ENOMEM);
67792+
67793+ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
67794+ if (subjmap == NULL)
67795+ return ERR_PTR(-ENOMEM);
67796+
67797+ subjmap->user = userp;
67798+ subjmap->kernel = s_tmp;
67799+ insert_subj_map_entry(subjmap);
67800+
67801+ if (copy_acl_subject_label(s_tmp, userp))
67802+ return ERR_PTR(-EFAULT);
67803+
67804+ err = alloc_and_copy_string(&s_tmp->filename, PATH_MAX);
67805+ if (err)
67806+ return ERR_PTR(err);
67807+
67808+ if (!strcmp(s_tmp->filename, "/"))
67809+ role->root_label = s_tmp;
67810+
67811+ if (copy_gr_hash_struct(&ghash, s_tmp->hash))
67812+ return ERR_PTR(-EFAULT);
67813+
67814+ /* copy user and group transition tables */
67815+
67816+ if (s_tmp->user_trans_num) {
67817+ uid_t *uidlist;
67818+
67819+ uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
67820+ if (uidlist == NULL)
67821+ return ERR_PTR(-ENOMEM);
67822+ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
67823+ return ERR_PTR(-EFAULT);
67824+
67825+ s_tmp->user_transitions = uidlist;
67826+ }
67827+
67828+ if (s_tmp->group_trans_num) {
67829+ gid_t *gidlist;
67830+
67831+ gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
67832+ if (gidlist == NULL)
67833+ return ERR_PTR(-ENOMEM);
67834+ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
67835+ return ERR_PTR(-EFAULT);
67836+
67837+ s_tmp->group_transitions = gidlist;
67838+ }
67839+
67840+ /* set up object hash table */
67841+ num_objs = count_user_objs(ghash.first);
67842+
67843+ s_tmp->obj_hash_size = num_objs;
67844+ s_tmp->obj_hash =
67845+ (struct acl_object_label **)
67846+ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
67847+
67848+ if (!s_tmp->obj_hash)
67849+ return ERR_PTR(-ENOMEM);
67850+
67851+ memset(s_tmp->obj_hash, 0,
67852+ s_tmp->obj_hash_size *
67853+ sizeof (struct acl_object_label *));
67854+
67855+ /* add in objects */
67856+ err = copy_user_objs(ghash.first, s_tmp, role);
67857+
67858+ if (err)
67859+ return ERR_PTR(err);
67860+
67861+ /* set pointer for parent subject */
67862+ if (s_tmp->parent_subject) {
67863+ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
67864+
67865+ if (IS_ERR(s_tmp2))
67866+ return s_tmp2;
67867+
67868+ s_tmp->parent_subject = s_tmp2;
67869+ }
67870+
67871+ /* add in ip acls */
67872+
67873+ if (!s_tmp->ip_num) {
67874+ s_tmp->ips = NULL;
67875+ goto insert;
67876+ }
67877+
67878+ i_tmp =
67879+ (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
67880+ sizeof (struct acl_ip_label *));
67881+
67882+ if (!i_tmp)
67883+ return ERR_PTR(-ENOMEM);
67884+
67885+ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
67886+ *(i_tmp + i_num) =
67887+ (struct acl_ip_label *)
67888+ acl_alloc(sizeof (struct acl_ip_label));
67889+ if (!*(i_tmp + i_num))
67890+ return ERR_PTR(-ENOMEM);
67891+
67892+ if (copy_pointer_from_array(&i_utmp2, i_num, s_tmp->ips))
67893+ return ERR_PTR(-EFAULT);
67894+
67895+ if (copy_acl_ip_label(*(i_tmp + i_num), i_utmp2))
67896+ return ERR_PTR(-EFAULT);
67897+
67898+ if ((*(i_tmp + i_num))->iface == NULL)
67899+ continue;
67900+
67901+ err = alloc_and_copy_string(&(*(i_tmp + i_num))->iface, IFNAMSIZ);
67902+ if (err)
67903+ return ERR_PTR(err);
67904+ }
67905+
67906+ s_tmp->ips = i_tmp;
67907+
67908+insert:
67909+ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
67910+ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
67911+ return ERR_PTR(-ENOMEM);
67912+
67913+ return s_tmp;
67914+}
67915+
67916+static int
67917+copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
67918+{
67919+ struct acl_subject_label s_pre;
67920+ struct acl_subject_label * ret;
67921+ int err;
67922+
67923+ while (userp) {
67924+ if (copy_acl_subject_label(&s_pre, userp))
67925+ return -EFAULT;
67926+
67927+ ret = do_copy_user_subj(userp, role, NULL);
67928+
67929+ err = PTR_ERR(ret);
67930+ if (IS_ERR(ret))
67931+ return err;
67932+
67933+ insert_acl_subj_label(ret, role);
67934+
67935+ userp = s_pre.prev;
67936+ }
67937+
67938+ return 0;
67939+}
67940+
67941+static int
67942+copy_user_acl(struct gr_arg *arg)
67943+{
67944+ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
67945+ struct acl_subject_label *subj_list;
67946+ struct sprole_pw *sptmp;
67947+ struct gr_hash_struct *ghash;
67948+ uid_t *domainlist;
67949+ unsigned int r_num;
67950+ int err = 0;
67951+ __u16 i;
67952+ __u32 num_subjs;
67953+
67954+ /* we need a default and kernel role */
67955+ if (arg->role_db.num_roles < 2)
67956+ return -EINVAL;
67957+
67958+ /* copy special role authentication info from userspace */
67959+
67960+ polstate->num_sprole_pws = arg->num_sprole_pws;
67961+ polstate->acl_special_roles = (struct sprole_pw **) acl_alloc_num(polstate->num_sprole_pws, sizeof(struct sprole_pw *));
67962+
67963+ if (!polstate->acl_special_roles && polstate->num_sprole_pws)
67964+ return -ENOMEM;
67965+
67966+ for (i = 0; i < polstate->num_sprole_pws; i++) {
67967+ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
67968+ if (!sptmp)
67969+ return -ENOMEM;
67970+ if (copy_sprole_pw(sptmp, i, arg->sprole_pws))
67971+ return -EFAULT;
67972+
67973+ err = alloc_and_copy_string((char **)&sptmp->rolename, GR_SPROLE_LEN);
67974+ if (err)
67975+ return err;
67976+
67977+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
67978+ printk(KERN_ALERT "Copying special role %s\n", sptmp->rolename);
67979+#endif
67980+
67981+ polstate->acl_special_roles[i] = sptmp;
67982+ }
67983+
67984+ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
67985+
67986+ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
67987+ r_tmp = acl_alloc(sizeof (struct acl_role_label));
67988+
67989+ if (!r_tmp)
67990+ return -ENOMEM;
67991+
67992+ if (copy_pointer_from_array(&r_utmp2, r_num, r_utmp))
67993+ return -EFAULT;
67994+
67995+ if (copy_acl_role_label(r_tmp, r_utmp2))
67996+ return -EFAULT;
67997+
67998+ err = alloc_and_copy_string(&r_tmp->rolename, GR_SPROLE_LEN);
67999+ if (err)
68000+ return err;
68001+
68002+ if (!strcmp(r_tmp->rolename, "default")
68003+ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
68004+ polstate->default_role = r_tmp;
68005+ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
68006+ polstate->kernel_role = r_tmp;
68007+ }
68008+
68009+ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
68010+ return -ENOMEM;
68011+
68012+ if (copy_gr_hash_struct(ghash, r_tmp->hash))
68013+ return -EFAULT;
68014+
68015+ r_tmp->hash = ghash;
68016+
68017+ num_subjs = count_user_subjs(r_tmp->hash->first);
68018+
68019+ r_tmp->subj_hash_size = num_subjs;
68020+ r_tmp->subj_hash =
68021+ (struct acl_subject_label **)
68022+ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
68023+
68024+ if (!r_tmp->subj_hash)
68025+ return -ENOMEM;
68026+
68027+ err = copy_user_allowedips(r_tmp);
68028+ if (err)
68029+ return err;
68030+
68031+ /* copy domain info */
68032+ if (r_tmp->domain_children != NULL) {
68033+ domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
68034+ if (domainlist == NULL)
68035+ return -ENOMEM;
68036+
68037+ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
68038+ return -EFAULT;
68039+
68040+ r_tmp->domain_children = domainlist;
68041+ }
68042+
68043+ err = copy_user_transitions(r_tmp);
68044+ if (err)
68045+ return err;
68046+
68047+ memset(r_tmp->subj_hash, 0,
68048+ r_tmp->subj_hash_size *
68049+ sizeof (struct acl_subject_label *));
68050+
68051+ /* acquire the list of subjects, then NULL out
68052+ the list prior to parsing the subjects for this role,
68053+ as during this parsing the list is replaced with a list
68054+ of *nested* subjects for the role
68055+ */
68056+ subj_list = r_tmp->hash->first;
68057+
68058+ /* set nested subject list to null */
68059+ r_tmp->hash->first = NULL;
68060+
68061+ err = copy_user_subjs(subj_list, r_tmp);
68062+
68063+ if (err)
68064+ return err;
68065+
68066+ insert_acl_role_label(r_tmp);
68067+ }
68068+
68069+ if (polstate->default_role == NULL || polstate->kernel_role == NULL)
68070+ return -EINVAL;
68071+
68072+ return err;
68073+}
68074+
68075+static struct acl_subject_label *gr_get_subject_for_task(struct task_struct *task, const char *filename)
68076+{
68077+ char *tmpname;
68078+ struct acl_subject_label *tmpsubj;
68079+ struct file *filp;
68080+ struct name_entry *nmatch;
68081+
68082+ filp = task->exec_file;
68083+ if (filp == NULL)
68084+ return NULL;
68085+
68086+ /* the following is to apply the correct subject
68087+ on binaries running when the RBAC system
68088+ is enabled, when the binaries have been
68089+ replaced or deleted since their execution
68090+ -----
68091+ when the RBAC system starts, the inode/dev
68092+ from exec_file will be one the RBAC system
68093+ is unaware of. It only knows the inode/dev
68094+ of the present file on disk, or the absence
68095+ of it.
68096+ */
68097+
68098+ if (filename)
68099+ nmatch = __lookup_name_entry(polstate, filename);
68100+ else {
68101+ preempt_disable();
68102+ tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
68103+
68104+ nmatch = __lookup_name_entry(polstate, tmpname);
68105+ preempt_enable();
68106+ }
68107+ tmpsubj = NULL;
68108+ if (nmatch) {
68109+ if (nmatch->deleted)
68110+ tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
68111+ else
68112+ tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
68113+ }
68114+ /* this also works for the reload case -- if we don't match a potentially inherited subject
68115+ then we fall back to a normal lookup based on the binary's ino/dev
68116+ */
68117+ if (tmpsubj == NULL)
68118+ tmpsubj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
68119+ task->role);
68120+
68121+ return tmpsubj;
68122+}
68123+
68124+static int gracl_reload_apply_policies(void *reload)
68125+{
68126+ struct gr_reload_state *reload_state = (struct gr_reload_state *)reload;
68127+ struct task_struct *task, *task2;
68128+ struct acl_role_label *role, *rtmp;
68129+ struct acl_subject_label *subj;
68130+ const struct cred *cred;
68131+ int role_applied;
68132+ int ret = 0;
68133+
68134+ memcpy(&reload_state->oldpolicy, reload_state->oldpolicy_ptr, sizeof(struct gr_reload_state));
68135+ memcpy(&reload_state->oldalloc, reload_state->oldalloc_ptr, sizeof(struct gr_alloc_state));
68136+
68137+ /* first make sure we'll be able to apply the new policy cleanly */
68138+ do_each_thread(task2, task) {
68139+ if (task->exec_file == NULL)
68140+ continue;
68141+ role_applied = 0;
68142+ if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
68143+ /* preserve special roles */
68144+ FOR_EACH_ROLE_START(role)
68145+ if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
68146+ rtmp = task->role;
68147+ task->role = role;
68148+ role_applied = 1;
68149+ break;
68150+ }
68151+ FOR_EACH_ROLE_END(role)
68152+ }
68153+ if (!role_applied) {
68154+ cred = __task_cred(task);
68155+ rtmp = task->role;
68156+ task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
68157+ }
68158+ /* this handles non-nested inherited subjects, nested subjects will still
68159+ be dropped currently */
68160+ subj = gr_get_subject_for_task(task, task->acl->filename);
68161+ task->tmpacl = gr_get_subject_for_task(task, NULL);
68162+ /* change the role back so that we've made no modifications to the policy */
68163+ task->role = rtmp;
68164+
68165+ if (subj == NULL || task->tmpacl == NULL) {
68166+ ret = -EINVAL;
68167+ goto out;
68168+ }
68169+ } while_each_thread(task2, task);
68170+
68171+ /* now actually apply the policy */
68172+
68173+ do_each_thread(task2, task) {
68174+ if (task->exec_file) {
68175+ role_applied = 0;
68176+ if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
68177+ /* preserve special roles */
68178+ FOR_EACH_ROLE_START(role)
68179+ if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
68180+ task->role = role;
68181+ role_applied = 1;
68182+ break;
68183+ }
68184+ FOR_EACH_ROLE_END(role)
68185+ }
68186+ if (!role_applied) {
68187+ cred = __task_cred(task);
68188+ task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
68189+ }
68190+ /* this handles non-nested inherited subjects, nested subjects will still
68191+ be dropped currently */
68192+ if (!reload_state->oldmode && task->inherited)
68193+ subj = gr_get_subject_for_task(task, task->acl->filename);
68194+ else {
68195+ /* looked up and tagged to the task previously */
68196+ subj = task->tmpacl;
68197+ }
68198+ /* subj will be non-null */
68199+ __gr_apply_subject_to_task(polstate, task, subj);
68200+ if (reload_state->oldmode) {
68201+ task->acl_role_id = 0;
68202+ task->acl_sp_role = 0;
68203+ task->inherited = 0;
68204+ }
68205+ } else {
68206+ // it's a kernel process
68207+ task->role = polstate->kernel_role;
68208+ task->acl = polstate->kernel_role->root_label;
68209+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
68210+ task->acl->mode &= ~GR_PROCFIND;
68211+#endif
68212+ }
68213+ } while_each_thread(task2, task);
68214+
68215+ memcpy(reload_state->oldpolicy_ptr, &reload_state->newpolicy, sizeof(struct gr_policy_state));
68216+ memcpy(reload_state->oldalloc_ptr, &reload_state->newalloc, sizeof(struct gr_alloc_state));
68217+
68218+out:
68219+
68220+ return ret;
68221+}
68222+
68223+static int gracl_reload(struct gr_arg *args, unsigned char oldmode)
68224+{
68225+ struct gr_reload_state new_reload_state = { };
68226+ int err;
68227+
68228+ new_reload_state.oldpolicy_ptr = polstate;
68229+ new_reload_state.oldalloc_ptr = current_alloc_state;
68230+ new_reload_state.oldmode = oldmode;
68231+
68232+ current_alloc_state = &new_reload_state.newalloc;
68233+ polstate = &new_reload_state.newpolicy;
68234+
68235+ /* everything relevant is now saved off, copy in the new policy */
68236+ if (init_variables(args, true)) {
68237+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
68238+ err = -ENOMEM;
68239+ goto error;
68240+ }
68241+
68242+ err = copy_user_acl(args);
68243+ free_init_variables();
68244+ if (err)
68245+ goto error;
68246+ /* the new policy is copied in, with the old policy available via saved_state
68247+ first go through applying roles, making sure to preserve special roles
68248+ then apply new subjects, making sure to preserve inherited and nested subjects,
68249+ though currently only inherited subjects will be preserved
68250+ */
68251+ err = stop_machine(gracl_reload_apply_policies, &new_reload_state, NULL);
68252+ if (err)
68253+ goto error;
68254+
68255+ /* we've now applied the new policy, so restore the old policy state to free it */
68256+ polstate = &new_reload_state.oldpolicy;
68257+ current_alloc_state = &new_reload_state.oldalloc;
68258+ free_variables(true);
68259+
68260+ /* oldpolicy/oldalloc_ptr point to the new policy/alloc states as they were copied
68261+ to running_polstate/current_alloc_state inside stop_machine
68262+ */
68263+ err = 0;
68264+ goto out;
68265+error:
68266+ /* on error of loading the new policy, we'll just keep the previous
68267+ policy set around
68268+ */
68269+ free_variables(true);
68270+
68271+ /* doesn't affect runtime, but maintains consistent state */
68272+out:
68273+ polstate = new_reload_state.oldpolicy_ptr;
68274+ current_alloc_state = new_reload_state.oldalloc_ptr;
68275+
68276+ return err;
68277+}
68278+
68279+static int
68280+gracl_init(struct gr_arg *args)
68281+{
68282+ int error = 0;
68283+
68284+ memcpy(&gr_system_salt, args->salt, sizeof(gr_system_salt));
68285+ memcpy(&gr_system_sum, args->sum, sizeof(gr_system_sum));
68286+
68287+ if (init_variables(args, false)) {
68288+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
68289+ error = -ENOMEM;
68290+ goto out;
68291+ }
68292+
68293+ error = copy_user_acl(args);
68294+ free_init_variables();
68295+ if (error)
68296+ goto out;
68297+
68298+ error = gr_set_acls(0);
68299+ if (error)
68300+ goto out;
68301+
68302+ gr_enable_rbac_system();
68303+
68304+ return 0;
68305+
68306+out:
68307+ free_variables(false);
68308+ return error;
68309+}
68310+
68311+static int
68312+lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
68313+ unsigned char **sum)
68314+{
68315+ struct acl_role_label *r;
68316+ struct role_allowed_ip *ipp;
68317+ struct role_transition *trans;
68318+ unsigned int i;
68319+ int found = 0;
68320+ u32 curr_ip = current->signal->curr_ip;
68321+
68322+ current->signal->saved_ip = curr_ip;
68323+
68324+ /* check transition table */
68325+
68326+ for (trans = current->role->transitions; trans; trans = trans->next) {
68327+ if (!strcmp(rolename, trans->rolename)) {
68328+ found = 1;
68329+ break;
68330+ }
68331+ }
68332+
68333+ if (!found)
68334+ return 0;
68335+
68336+ /* handle special roles that do not require authentication
68337+ and check ip */
68338+
68339+ FOR_EACH_ROLE_START(r)
68340+ if (!strcmp(rolename, r->rolename) &&
68341+ (r->roletype & GR_ROLE_SPECIAL)) {
68342+ found = 0;
68343+ if (r->allowed_ips != NULL) {
68344+ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
68345+ if ((ntohl(curr_ip) & ipp->netmask) ==
68346+ (ntohl(ipp->addr) & ipp->netmask))
68347+ found = 1;
68348+ }
68349+ } else
68350+ found = 2;
68351+ if (!found)
68352+ return 0;
68353+
68354+ if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
68355+ ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
68356+ *salt = NULL;
68357+ *sum = NULL;
68358+ return 1;
68359+ }
68360+ }
68361+ FOR_EACH_ROLE_END(r)
68362+
68363+ for (i = 0; i < polstate->num_sprole_pws; i++) {
68364+ if (!strcmp(rolename, polstate->acl_special_roles[i]->rolename)) {
68365+ *salt = polstate->acl_special_roles[i]->salt;
68366+ *sum = polstate->acl_special_roles[i]->sum;
68367+ return 1;
68368+ }
68369+ }
68370+
68371+ return 0;
68372+}
68373+
68374+int gr_check_secure_terminal(struct task_struct *task)
68375+{
68376+ struct task_struct *p, *p2, *p3;
68377+ struct files_struct *files;
68378+ struct fdtable *fdt;
68379+ struct file *our_file = NULL, *file;
68380+ int i;
68381+
68382+ if (task->signal->tty == NULL)
68383+ return 1;
68384+
68385+ files = get_files_struct(task);
68386+ if (files != NULL) {
68387+ rcu_read_lock();
68388+ fdt = files_fdtable(files);
68389+ for (i=0; i < fdt->max_fds; i++) {
68390+ file = fcheck_files(files, i);
68391+ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
68392+ get_file(file);
68393+ our_file = file;
68394+ }
68395+ }
68396+ rcu_read_unlock();
68397+ put_files_struct(files);
68398+ }
68399+
68400+ if (our_file == NULL)
68401+ return 1;
68402+
68403+ read_lock(&tasklist_lock);
68404+ do_each_thread(p2, p) {
68405+ files = get_files_struct(p);
68406+ if (files == NULL ||
68407+ (p->signal && p->signal->tty == task->signal->tty)) {
68408+ if (files != NULL)
68409+ put_files_struct(files);
68410+ continue;
68411+ }
68412+ rcu_read_lock();
68413+ fdt = files_fdtable(files);
68414+ for (i=0; i < fdt->max_fds; i++) {
68415+ file = fcheck_files(files, i);
68416+ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
68417+ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
68418+ p3 = task;
68419+ while (task_pid_nr(p3) > 0) {
68420+ if (p3 == p)
68421+ break;
68422+ p3 = p3->real_parent;
68423+ }
68424+ if (p3 == p)
68425+ break;
68426+ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
68427+ gr_handle_alertkill(p);
68428+ rcu_read_unlock();
68429+ put_files_struct(files);
68430+ read_unlock(&tasklist_lock);
68431+ fput(our_file);
68432+ return 0;
68433+ }
68434+ }
68435+ rcu_read_unlock();
68436+ put_files_struct(files);
68437+ } while_each_thread(p2, p);
68438+ read_unlock(&tasklist_lock);
68439+
68440+ fput(our_file);
68441+ return 1;
68442+}
68443+
68444+ssize_t
68445+write_grsec_handler(struct file *file, const char __user * buf, size_t count, loff_t *ppos)
68446+{
68447+ struct gr_arg_wrapper uwrap;
68448+ unsigned char *sprole_salt = NULL;
68449+ unsigned char *sprole_sum = NULL;
68450+ int error = 0;
68451+ int error2 = 0;
68452+ size_t req_count = 0;
68453+ unsigned char oldmode = 0;
68454+
68455+ mutex_lock(&gr_dev_mutex);
68456+
68457+ if (gr_acl_is_enabled() && !(current->acl->mode & GR_KERNELAUTH)) {
68458+ error = -EPERM;
68459+ goto out;
68460+ }
68461+
68462+#ifdef CONFIG_COMPAT
68463+ pax_open_kernel();
68464+ if (is_compat_task()) {
68465+ copy_gr_arg_wrapper = &copy_gr_arg_wrapper_compat;
68466+ copy_gr_arg = &copy_gr_arg_compat;
68467+ copy_acl_object_label = &copy_acl_object_label_compat;
68468+ copy_acl_subject_label = &copy_acl_subject_label_compat;
68469+ copy_acl_role_label = &copy_acl_role_label_compat;
68470+ copy_acl_ip_label = &copy_acl_ip_label_compat;
68471+ copy_role_allowed_ip = &copy_role_allowed_ip_compat;
68472+ copy_role_transition = &copy_role_transition_compat;
68473+ copy_sprole_pw = &copy_sprole_pw_compat;
68474+ copy_gr_hash_struct = &copy_gr_hash_struct_compat;
68475+ copy_pointer_from_array = &copy_pointer_from_array_compat;
68476+ get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_compat;
68477+ } else {
68478+ copy_gr_arg_wrapper = &copy_gr_arg_wrapper_normal;
68479+ copy_gr_arg = &copy_gr_arg_normal;
68480+ copy_acl_object_label = &copy_acl_object_label_normal;
68481+ copy_acl_subject_label = &copy_acl_subject_label_normal;
68482+ copy_acl_role_label = &copy_acl_role_label_normal;
68483+ copy_acl_ip_label = &copy_acl_ip_label_normal;
68484+ copy_role_allowed_ip = &copy_role_allowed_ip_normal;
68485+ copy_role_transition = &copy_role_transition_normal;
68486+ copy_sprole_pw = &copy_sprole_pw_normal;
68487+ copy_gr_hash_struct = &copy_gr_hash_struct_normal;
68488+ copy_pointer_from_array = &copy_pointer_from_array_normal;
68489+ get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_normal;
68490+ }
68491+ pax_close_kernel();
68492+#endif
68493+
68494+ req_count = get_gr_arg_wrapper_size();
68495+
68496+ if (count != req_count) {
68497+ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)req_count);
68498+ error = -EINVAL;
68499+ goto out;
68500+ }
68501+
68502+
68503+ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
68504+ gr_auth_expires = 0;
68505+ gr_auth_attempts = 0;
68506+ }
68507+
68508+ error = copy_gr_arg_wrapper(buf, &uwrap);
68509+ if (error)
68510+ goto out;
68511+
68512+ error = copy_gr_arg(uwrap.arg, &gr_usermode);
68513+ if (error)
68514+ goto out;
68515+
68516+ if (gr_usermode.mode != GR_SPROLE && gr_usermode.mode != GR_SPROLEPAM &&
68517+ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
68518+ time_after(gr_auth_expires, get_seconds())) {
68519+ error = -EBUSY;
68520+ goto out;
68521+ }
68522+
68523+ /* if non-root trying to do anything other than use a special role,
68524+ do not attempt authentication, do not count towards authentication
68525+ locking
68526+ */
68527+
68528+ if (gr_usermode.mode != GR_SPROLE && gr_usermode.mode != GR_STATUS &&
68529+ gr_usermode.mode != GR_UNSPROLE && gr_usermode.mode != GR_SPROLEPAM &&
68530+ gr_is_global_nonroot(current_uid())) {
68531+ error = -EPERM;
68532+ goto out;
68533+ }
68534+
68535+ /* ensure pw and special role name are null terminated */
68536+
68537+ gr_usermode.pw[GR_PW_LEN - 1] = '\0';
68538+ gr_usermode.sp_role[GR_SPROLE_LEN - 1] = '\0';
68539+
68540+ /* Okay.
68541+ * We have our enough of the argument structure..(we have yet
68542+ * to copy_from_user the tables themselves) . Copy the tables
68543+ * only if we need them, i.e. for loading operations. */
68544+
68545+ switch (gr_usermode.mode) {
68546+ case GR_STATUS:
68547+ if (gr_acl_is_enabled()) {
68548+ error = 1;
68549+ if (!gr_check_secure_terminal(current))
68550+ error = 3;
68551+ } else
68552+ error = 2;
68553+ goto out;
68554+ case GR_SHUTDOWN:
68555+ if (gr_acl_is_enabled() && !(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
68556+ stop_machine(gr_rbac_disable, NULL, NULL);
68557+ free_variables(false);
68558+ memset(&gr_usermode, 0, sizeof(gr_usermode));
68559+ memset(&gr_system_salt, 0, sizeof(gr_system_salt));
68560+ memset(&gr_system_sum, 0, sizeof(gr_system_sum));
68561+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
68562+ } else if (gr_acl_is_enabled()) {
68563+ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
68564+ error = -EPERM;
68565+ } else {
68566+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
68567+ error = -EAGAIN;
68568+ }
68569+ break;
68570+ case GR_ENABLE:
68571+ if (!gr_acl_is_enabled() && !(error2 = gracl_init(&gr_usermode)))
68572+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
68573+ else {
68574+ if (gr_acl_is_enabled())
68575+ error = -EAGAIN;
68576+ else
68577+ error = error2;
68578+ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
68579+ }
68580+ break;
68581+ case GR_OLDRELOAD:
68582+ oldmode = 1;
68583+ case GR_RELOAD:
68584+ if (!gr_acl_is_enabled()) {
68585+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
68586+ error = -EAGAIN;
68587+ } else if (!(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
68588+ error2 = gracl_reload(&gr_usermode, oldmode);
68589+ if (!error2)
68590+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
68591+ else {
68592+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
68593+ error = error2;
68594+ }
68595+ } else {
68596+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
68597+ error = -EPERM;
68598+ }
68599+ break;
68600+ case GR_SEGVMOD:
68601+ if (unlikely(!gr_acl_is_enabled())) {
68602+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
68603+ error = -EAGAIN;
68604+ break;
68605+ }
68606+
68607+ if (!(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
68608+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
68609+ if (gr_usermode.segv_device && gr_usermode.segv_inode) {
68610+ struct acl_subject_label *segvacl;
68611+ segvacl =
68612+ lookup_acl_subj_label(gr_usermode.segv_inode,
68613+ gr_usermode.segv_device,
68614+ current->role);
68615+ if (segvacl) {
68616+ segvacl->crashes = 0;
68617+ segvacl->expires = 0;
68618+ }
68619+ } else if (gr_find_uid(gr_usermode.segv_uid) >= 0) {
68620+ gr_remove_uid(gr_usermode.segv_uid);
68621+ }
68622+ } else {
68623+ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
68624+ error = -EPERM;
68625+ }
68626+ break;
68627+ case GR_SPROLE:
68628+ case GR_SPROLEPAM:
68629+ if (unlikely(!gr_acl_is_enabled())) {
68630+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
68631+ error = -EAGAIN;
68632+ break;
68633+ }
68634+
68635+ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
68636+ current->role->expires = 0;
68637+ current->role->auth_attempts = 0;
68638+ }
68639+
68640+ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
68641+ time_after(current->role->expires, get_seconds())) {
68642+ error = -EBUSY;
68643+ goto out;
68644+ }
68645+
68646+ if (lookup_special_role_auth
68647+ (gr_usermode.mode, gr_usermode.sp_role, &sprole_salt, &sprole_sum)
68648+ && ((!sprole_salt && !sprole_sum)
68649+ || !(chkpw(&gr_usermode, sprole_salt, sprole_sum)))) {
68650+ char *p = "";
68651+ assign_special_role(gr_usermode.sp_role);
68652+ read_lock(&tasklist_lock);
68653+ if (current->real_parent)
68654+ p = current->real_parent->role->rolename;
68655+ read_unlock(&tasklist_lock);
68656+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
68657+ p, acl_sp_role_value);
68658+ } else {
68659+ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode.sp_role);
68660+ error = -EPERM;
68661+ if(!(current->role->auth_attempts++))
68662+ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
68663+
68664+ goto out;
68665+ }
68666+ break;
68667+ case GR_UNSPROLE:
68668+ if (unlikely(!gr_acl_is_enabled())) {
68669+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
68670+ error = -EAGAIN;
68671+ break;
68672+ }
68673+
68674+ if (current->role->roletype & GR_ROLE_SPECIAL) {
68675+ char *p = "";
68676+ int i = 0;
68677+
68678+ read_lock(&tasklist_lock);
68679+ if (current->real_parent) {
68680+ p = current->real_parent->role->rolename;
68681+ i = current->real_parent->acl_role_id;
68682+ }
68683+ read_unlock(&tasklist_lock);
68684+
68685+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
68686+ gr_set_acls(1);
68687+ } else {
68688+ error = -EPERM;
68689+ goto out;
68690+ }
68691+ break;
68692+ default:
68693+ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode.mode);
68694+ error = -EINVAL;
68695+ break;
68696+ }
68697+
68698+ if (error != -EPERM)
68699+ goto out;
68700+
68701+ if(!(gr_auth_attempts++))
68702+ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
68703+
68704+ out:
68705+ mutex_unlock(&gr_dev_mutex);
68706+
68707+ if (!error)
68708+ error = req_count;
68709+
68710+ return error;
68711+}
68712+
68713+int
68714+gr_set_acls(const int type)
68715+{
68716+ struct task_struct *task, *task2;
68717+ struct acl_role_label *role = current->role;
68718+ struct acl_subject_label *subj;
68719+ __u16 acl_role_id = current->acl_role_id;
68720+ const struct cred *cred;
68721+ int ret;
68722+
68723+ rcu_read_lock();
68724+ read_lock(&tasklist_lock);
68725+ read_lock(&grsec_exec_file_lock);
68726+ do_each_thread(task2, task) {
68727+ /* check to see if we're called from the exit handler,
68728+ if so, only replace ACLs that have inherited the admin
68729+ ACL */
68730+
68731+ if (type && (task->role != role ||
68732+ task->acl_role_id != acl_role_id))
68733+ continue;
68734+
68735+ task->acl_role_id = 0;
68736+ task->acl_sp_role = 0;
68737+ task->inherited = 0;
68738+
68739+ if (task->exec_file) {
68740+ cred = __task_cred(task);
68741+ task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
68742+ subj = gr_get_subject_for_task(task, NULL);
68743+ if (subj == NULL) {
68744+ ret = -EINVAL;
68745+ read_unlock(&grsec_exec_file_lock);
68746+ read_unlock(&tasklist_lock);
68747+ rcu_read_unlock();
68748+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task_pid_nr(task));
68749+ return ret;
68750+ }
68751+ __gr_apply_subject_to_task(polstate, task, subj);
68752+ } else {
68753+ // it's a kernel process
68754+ task->role = polstate->kernel_role;
68755+ task->acl = polstate->kernel_role->root_label;
68756+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
68757+ task->acl->mode &= ~GR_PROCFIND;
68758+#endif
68759+ }
68760+ } while_each_thread(task2, task);
68761+ read_unlock(&grsec_exec_file_lock);
68762+ read_unlock(&tasklist_lock);
68763+ rcu_read_unlock();
68764+
68765+ return 0;
68766+}
68767diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
68768new file mode 100644
68769index 0000000..39645c9
68770--- /dev/null
68771+++ b/grsecurity/gracl_res.c
68772@@ -0,0 +1,68 @@
68773+#include <linux/kernel.h>
68774+#include <linux/sched.h>
68775+#include <linux/gracl.h>
68776+#include <linux/grinternal.h>
68777+
68778+static const char *restab_log[] = {
68779+ [RLIMIT_CPU] = "RLIMIT_CPU",
68780+ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
68781+ [RLIMIT_DATA] = "RLIMIT_DATA",
68782+ [RLIMIT_STACK] = "RLIMIT_STACK",
68783+ [RLIMIT_CORE] = "RLIMIT_CORE",
68784+ [RLIMIT_RSS] = "RLIMIT_RSS",
68785+ [RLIMIT_NPROC] = "RLIMIT_NPROC",
68786+ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
68787+ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
68788+ [RLIMIT_AS] = "RLIMIT_AS",
68789+ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
68790+ [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
68791+ [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
68792+ [RLIMIT_NICE] = "RLIMIT_NICE",
68793+ [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
68794+ [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
68795+ [GR_CRASH_RES] = "RLIMIT_CRASH"
68796+};
68797+
68798+void
68799+gr_log_resource(const struct task_struct *task,
68800+ const int res, const unsigned long wanted, const int gt)
68801+{
68802+ const struct cred *cred;
68803+ unsigned long rlim;
68804+
68805+ if (!gr_acl_is_enabled() && !grsec_resource_logging)
68806+ return;
68807+
68808+ // not yet supported resource
68809+ if (unlikely(!restab_log[res]))
68810+ return;
68811+
68812+ if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
68813+ rlim = task_rlimit_max(task, res);
68814+ else
68815+ rlim = task_rlimit(task, res);
68816+
68817+ if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
68818+ return;
68819+
68820+ rcu_read_lock();
68821+ cred = __task_cred(task);
68822+
68823+ if (res == RLIMIT_NPROC &&
68824+ (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
68825+ cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
68826+ goto out_rcu_unlock;
68827+ else if (res == RLIMIT_MEMLOCK &&
68828+ cap_raised(cred->cap_effective, CAP_IPC_LOCK))
68829+ goto out_rcu_unlock;
68830+ else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
68831+ goto out_rcu_unlock;
68832+ rcu_read_unlock();
68833+
68834+ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
68835+
68836+ return;
68837+out_rcu_unlock:
68838+ rcu_read_unlock();
68839+ return;
68840+}
68841diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
68842new file mode 100644
68843index 0000000..2040e61
68844--- /dev/null
68845+++ b/grsecurity/gracl_segv.c
68846@@ -0,0 +1,313 @@
68847+#include <linux/kernel.h>
68848+#include <linux/mm.h>
68849+#include <asm/uaccess.h>
68850+#include <asm/errno.h>
68851+#include <asm/mman.h>
68852+#include <net/sock.h>
68853+#include <linux/file.h>
68854+#include <linux/fs.h>
68855+#include <linux/net.h>
68856+#include <linux/in.h>
68857+#include <linux/slab.h>
68858+#include <linux/types.h>
68859+#include <linux/sched.h>
68860+#include <linux/timer.h>
68861+#include <linux/gracl.h>
68862+#include <linux/grsecurity.h>
68863+#include <linux/grinternal.h>
68864+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
68865+#include <linux/magic.h>
68866+#include <linux/pagemap.h>
68867+#include "../fs/btrfs/async-thread.h"
68868+#include "../fs/btrfs/ctree.h"
68869+#include "../fs/btrfs/btrfs_inode.h"
68870+#endif
68871+
68872+static struct crash_uid *uid_set;
68873+static unsigned short uid_used;
68874+static DEFINE_SPINLOCK(gr_uid_lock);
68875+extern rwlock_t gr_inode_lock;
68876+extern struct acl_subject_label *
68877+ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
68878+ struct acl_role_label *role);
68879+
68880+static inline dev_t __get_dev(const struct dentry *dentry)
68881+{
68882+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
68883+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
68884+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
68885+ else
68886+#endif
68887+ return dentry->d_sb->s_dev;
68888+}
68889+
68890+int
68891+gr_init_uidset(void)
68892+{
68893+ uid_set =
68894+ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
68895+ uid_used = 0;
68896+
68897+ return uid_set ? 1 : 0;
68898+}
68899+
68900+void
68901+gr_free_uidset(void)
68902+{
68903+ if (uid_set) {
68904+ struct crash_uid *tmpset;
68905+ spin_lock(&gr_uid_lock);
68906+ tmpset = uid_set;
68907+ uid_set = NULL;
68908+ uid_used = 0;
68909+ spin_unlock(&gr_uid_lock);
68910+ if (tmpset)
68911+ kfree(tmpset);
68912+ }
68913+
68914+ return;
68915+}
68916+
68917+int
68918+gr_find_uid(const uid_t uid)
68919+{
68920+ struct crash_uid *tmp = uid_set;
68921+ uid_t buid;
68922+ int low = 0, high = uid_used - 1, mid;
68923+
68924+ while (high >= low) {
68925+ mid = (low + high) >> 1;
68926+ buid = tmp[mid].uid;
68927+ if (buid == uid)
68928+ return mid;
68929+ if (buid > uid)
68930+ high = mid - 1;
68931+ if (buid < uid)
68932+ low = mid + 1;
68933+ }
68934+
68935+ return -1;
68936+}
68937+
68938+static __inline__ void
68939+gr_insertsort(void)
68940+{
68941+ unsigned short i, j;
68942+ struct crash_uid index;
68943+
68944+ for (i = 1; i < uid_used; i++) {
68945+ index = uid_set[i];
68946+ j = i;
68947+ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
68948+ uid_set[j] = uid_set[j - 1];
68949+ j--;
68950+ }
68951+ uid_set[j] = index;
68952+ }
68953+
68954+ return;
68955+}
68956+
68957+static __inline__ void
68958+gr_insert_uid(const kuid_t kuid, const unsigned long expires)
68959+{
68960+ int loc;
68961+ uid_t uid = GR_GLOBAL_UID(kuid);
68962+
68963+ if (uid_used == GR_UIDTABLE_MAX)
68964+ return;
68965+
68966+ loc = gr_find_uid(uid);
68967+
68968+ if (loc >= 0) {
68969+ uid_set[loc].expires = expires;
68970+ return;
68971+ }
68972+
68973+ uid_set[uid_used].uid = uid;
68974+ uid_set[uid_used].expires = expires;
68975+ uid_used++;
68976+
68977+ gr_insertsort();
68978+
68979+ return;
68980+}
68981+
68982+void
68983+gr_remove_uid(const unsigned short loc)
68984+{
68985+ unsigned short i;
68986+
68987+ for (i = loc + 1; i < uid_used; i++)
68988+ uid_set[i - 1] = uid_set[i];
68989+
68990+ uid_used--;
68991+
68992+ return;
68993+}
68994+
68995+int
68996+gr_check_crash_uid(const kuid_t kuid)
68997+{
68998+ int loc;
68999+ int ret = 0;
69000+ uid_t uid;
69001+
69002+ if (unlikely(!gr_acl_is_enabled()))
69003+ return 0;
69004+
69005+ uid = GR_GLOBAL_UID(kuid);
69006+
69007+ spin_lock(&gr_uid_lock);
69008+ loc = gr_find_uid(uid);
69009+
69010+ if (loc < 0)
69011+ goto out_unlock;
69012+
69013+ if (time_before_eq(uid_set[loc].expires, get_seconds()))
69014+ gr_remove_uid(loc);
69015+ else
69016+ ret = 1;
69017+
69018+out_unlock:
69019+ spin_unlock(&gr_uid_lock);
69020+ return ret;
69021+}
69022+
69023+static __inline__ int
69024+proc_is_setxid(const struct cred *cred)
69025+{
69026+ if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
69027+ !uid_eq(cred->uid, cred->fsuid))
69028+ return 1;
69029+ if (!gid_eq(cred->gid, cred->egid) || !gid_eq(cred->gid, cred->sgid) ||
69030+ !gid_eq(cred->gid, cred->fsgid))
69031+ return 1;
69032+
69033+ return 0;
69034+}
69035+
69036+extern int gr_fake_force_sig(int sig, struct task_struct *t);
69037+
69038+void
69039+gr_handle_crash(struct task_struct *task, const int sig)
69040+{
69041+ struct acl_subject_label *curr;
69042+ struct task_struct *tsk, *tsk2;
69043+ const struct cred *cred;
69044+ const struct cred *cred2;
69045+
69046+ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
69047+ return;
69048+
69049+ if (unlikely(!gr_acl_is_enabled()))
69050+ return;
69051+
69052+ curr = task->acl;
69053+
69054+ if (!(curr->resmask & (1U << GR_CRASH_RES)))
69055+ return;
69056+
69057+ if (time_before_eq(curr->expires, get_seconds())) {
69058+ curr->expires = 0;
69059+ curr->crashes = 0;
69060+ }
69061+
69062+ curr->crashes++;
69063+
69064+ if (!curr->expires)
69065+ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
69066+
69067+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
69068+ time_after(curr->expires, get_seconds())) {
69069+ rcu_read_lock();
69070+ cred = __task_cred(task);
69071+ if (gr_is_global_nonroot(cred->uid) && proc_is_setxid(cred)) {
69072+ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
69073+ spin_lock(&gr_uid_lock);
69074+ gr_insert_uid(cred->uid, curr->expires);
69075+ spin_unlock(&gr_uid_lock);
69076+ curr->expires = 0;
69077+ curr->crashes = 0;
69078+ read_lock(&tasklist_lock);
69079+ do_each_thread(tsk2, tsk) {
69080+ cred2 = __task_cred(tsk);
69081+ if (tsk != task && uid_eq(cred2->uid, cred->uid))
69082+ gr_fake_force_sig(SIGKILL, tsk);
69083+ } while_each_thread(tsk2, tsk);
69084+ read_unlock(&tasklist_lock);
69085+ } else {
69086+ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
69087+ read_lock(&tasklist_lock);
69088+ read_lock(&grsec_exec_file_lock);
69089+ do_each_thread(tsk2, tsk) {
69090+ if (likely(tsk != task)) {
69091+ // if this thread has the same subject as the one that triggered
69092+ // RES_CRASH and it's the same binary, kill it
69093+ if (tsk->acl == task->acl && gr_is_same_file(tsk->exec_file, task->exec_file))
69094+ gr_fake_force_sig(SIGKILL, tsk);
69095+ }
69096+ } while_each_thread(tsk2, tsk);
69097+ read_unlock(&grsec_exec_file_lock);
69098+ read_unlock(&tasklist_lock);
69099+ }
69100+ rcu_read_unlock();
69101+ }
69102+
69103+ return;
69104+}
69105+
69106+int
69107+gr_check_crash_exec(const struct file *filp)
69108+{
69109+ struct acl_subject_label *curr;
69110+
69111+ if (unlikely(!gr_acl_is_enabled()))
69112+ return 0;
69113+
69114+ read_lock(&gr_inode_lock);
69115+ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
69116+ __get_dev(filp->f_path.dentry),
69117+ current->role);
69118+ read_unlock(&gr_inode_lock);
69119+
69120+ if (!curr || !(curr->resmask & (1U << GR_CRASH_RES)) ||
69121+ (!curr->crashes && !curr->expires))
69122+ return 0;
69123+
69124+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
69125+ time_after(curr->expires, get_seconds()))
69126+ return 1;
69127+ else if (time_before_eq(curr->expires, get_seconds())) {
69128+ curr->crashes = 0;
69129+ curr->expires = 0;
69130+ }
69131+
69132+ return 0;
69133+}
69134+
69135+void
69136+gr_handle_alertkill(struct task_struct *task)
69137+{
69138+ struct acl_subject_label *curracl;
69139+ __u32 curr_ip;
69140+ struct task_struct *p, *p2;
69141+
69142+ if (unlikely(!gr_acl_is_enabled()))
69143+ return;
69144+
69145+ curracl = task->acl;
69146+ curr_ip = task->signal->curr_ip;
69147+
69148+ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
69149+ read_lock(&tasklist_lock);
69150+ do_each_thread(p2, p) {
69151+ if (p->signal->curr_ip == curr_ip)
69152+ gr_fake_force_sig(SIGKILL, p);
69153+ } while_each_thread(p2, p);
69154+ read_unlock(&tasklist_lock);
69155+ } else if (curracl->mode & GR_KILLPROC)
69156+ gr_fake_force_sig(SIGKILL, task);
69157+
69158+ return;
69159+}
69160diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
69161new file mode 100644
69162index 0000000..98011b0
69163--- /dev/null
69164+++ b/grsecurity/gracl_shm.c
69165@@ -0,0 +1,40 @@
69166+#include <linux/kernel.h>
69167+#include <linux/mm.h>
69168+#include <linux/sched.h>
69169+#include <linux/file.h>
69170+#include <linux/ipc.h>
69171+#include <linux/gracl.h>
69172+#include <linux/grsecurity.h>
69173+#include <linux/grinternal.h>
69174+
69175+int
69176+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
69177+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
69178+{
69179+ struct task_struct *task;
69180+
69181+ if (!gr_acl_is_enabled())
69182+ return 1;
69183+
69184+ rcu_read_lock();
69185+ read_lock(&tasklist_lock);
69186+
69187+ task = find_task_by_vpid(shm_cprid);
69188+
69189+ if (unlikely(!task))
69190+ task = find_task_by_vpid(shm_lapid);
69191+
69192+ if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
69193+ (task_pid_nr(task) == shm_lapid)) &&
69194+ (task->acl->mode & GR_PROTSHM) &&
69195+ (task->acl != current->acl))) {
69196+ read_unlock(&tasklist_lock);
69197+ rcu_read_unlock();
69198+ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, GR_GLOBAL_UID(cuid), shm_cprid, shmid);
69199+ return 0;
69200+ }
69201+ read_unlock(&tasklist_lock);
69202+ rcu_read_unlock();
69203+
69204+ return 1;
69205+}
69206diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
69207new file mode 100644
69208index 0000000..bc0be01
69209--- /dev/null
69210+++ b/grsecurity/grsec_chdir.c
69211@@ -0,0 +1,19 @@
69212+#include <linux/kernel.h>
69213+#include <linux/sched.h>
69214+#include <linux/fs.h>
69215+#include <linux/file.h>
69216+#include <linux/grsecurity.h>
69217+#include <linux/grinternal.h>
69218+
69219+void
69220+gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
69221+{
69222+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
69223+ if ((grsec_enable_chdir && grsec_enable_group &&
69224+ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
69225+ !grsec_enable_group)) {
69226+ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
69227+ }
69228+#endif
69229+ return;
69230+}
69231diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
69232new file mode 100644
69233index 0000000..e10b319
69234--- /dev/null
69235+++ b/grsecurity/grsec_chroot.c
69236@@ -0,0 +1,370 @@
69237+#include <linux/kernel.h>
69238+#include <linux/module.h>
69239+#include <linux/sched.h>
69240+#include <linux/file.h>
69241+#include <linux/fs.h>
69242+#include <linux/mount.h>
69243+#include <linux/types.h>
69244+#include "../fs/mount.h"
69245+#include <linux/grsecurity.h>
69246+#include <linux/grinternal.h>
69247+
69248+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
69249+int gr_init_ran;
69250+#endif
69251+
69252+void gr_set_chroot_entries(struct task_struct *task, const struct path *path)
69253+{
69254+#ifdef CONFIG_GRKERNSEC
69255+ if (task_pid_nr(task) > 1 && path->dentry != init_task.fs->root.dentry &&
69256+ path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root
69257+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
69258+ && gr_init_ran
69259+#endif
69260+ )
69261+ task->gr_is_chrooted = 1;
69262+ else {
69263+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
69264+ if (task_pid_nr(task) == 1 && !gr_init_ran)
69265+ gr_init_ran = 1;
69266+#endif
69267+ task->gr_is_chrooted = 0;
69268+ }
69269+
69270+ task->gr_chroot_dentry = path->dentry;
69271+#endif
69272+ return;
69273+}
69274+
69275+void gr_clear_chroot_entries(struct task_struct *task)
69276+{
69277+#ifdef CONFIG_GRKERNSEC
69278+ task->gr_is_chrooted = 0;
69279+ task->gr_chroot_dentry = NULL;
69280+#endif
69281+ return;
69282+}
69283+
69284+int
69285+gr_handle_chroot_unix(const pid_t pid)
69286+{
69287+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
69288+ struct task_struct *p;
69289+
69290+ if (unlikely(!grsec_enable_chroot_unix))
69291+ return 1;
69292+
69293+ if (likely(!proc_is_chrooted(current)))
69294+ return 1;
69295+
69296+ rcu_read_lock();
69297+ read_lock(&tasklist_lock);
69298+ p = find_task_by_vpid_unrestricted(pid);
69299+ if (unlikely(p && !have_same_root(current, p))) {
69300+ read_unlock(&tasklist_lock);
69301+ rcu_read_unlock();
69302+ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
69303+ return 0;
69304+ }
69305+ read_unlock(&tasklist_lock);
69306+ rcu_read_unlock();
69307+#endif
69308+ return 1;
69309+}
69310+
69311+int
69312+gr_handle_chroot_nice(void)
69313+{
69314+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
69315+ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
69316+ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
69317+ return -EPERM;
69318+ }
69319+#endif
69320+ return 0;
69321+}
69322+
69323+int
69324+gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
69325+{
69326+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
69327+ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
69328+ && proc_is_chrooted(current)) {
69329+ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, task_pid_nr(p));
69330+ return -EACCES;
69331+ }
69332+#endif
69333+ return 0;
69334+}
69335+
69336+int
69337+gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
69338+{
69339+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
69340+ struct task_struct *p;
69341+ int ret = 0;
69342+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
69343+ return ret;
69344+
69345+ read_lock(&tasklist_lock);
69346+ do_each_pid_task(pid, type, p) {
69347+ if (!have_same_root(current, p)) {
69348+ ret = 1;
69349+ goto out;
69350+ }
69351+ } while_each_pid_task(pid, type, p);
69352+out:
69353+ read_unlock(&tasklist_lock);
69354+ return ret;
69355+#endif
69356+ return 0;
69357+}
69358+
69359+int
69360+gr_pid_is_chrooted(struct task_struct *p)
69361+{
69362+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
69363+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
69364+ return 0;
69365+
69366+ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
69367+ !have_same_root(current, p)) {
69368+ return 1;
69369+ }
69370+#endif
69371+ return 0;
69372+}
69373+
69374+EXPORT_SYMBOL(gr_pid_is_chrooted);
69375+
69376+#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
69377+int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
69378+{
69379+ struct path path, currentroot;
69380+ int ret = 0;
69381+
69382+ path.dentry = (struct dentry *)u_dentry;
69383+ path.mnt = (struct vfsmount *)u_mnt;
69384+ get_fs_root(current->fs, &currentroot);
69385+ if (path_is_under(&path, &currentroot))
69386+ ret = 1;
69387+ path_put(&currentroot);
69388+
69389+ return ret;
69390+}
69391+#endif
69392+
69393+int
69394+gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
69395+{
69396+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
69397+ if (!grsec_enable_chroot_fchdir)
69398+ return 1;
69399+
69400+ if (!proc_is_chrooted(current))
69401+ return 1;
69402+ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
69403+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
69404+ return 0;
69405+ }
69406+#endif
69407+ return 1;
69408+}
69409+
69410+int
69411+gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
69412+ const time_t shm_createtime)
69413+{
69414+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
69415+ struct task_struct *p;
69416+ time_t starttime;
69417+
69418+ if (unlikely(!grsec_enable_chroot_shmat))
69419+ return 1;
69420+
69421+ if (likely(!proc_is_chrooted(current)))
69422+ return 1;
69423+
69424+ rcu_read_lock();
69425+ read_lock(&tasklist_lock);
69426+
69427+ if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
69428+ starttime = p->start_time.tv_sec;
69429+ if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
69430+ if (have_same_root(current, p)) {
69431+ goto allow;
69432+ } else {
69433+ read_unlock(&tasklist_lock);
69434+ rcu_read_unlock();
69435+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
69436+ return 0;
69437+ }
69438+ }
69439+ /* creator exited, pid reuse, fall through to next check */
69440+ }
69441+ if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
69442+ if (unlikely(!have_same_root(current, p))) {
69443+ read_unlock(&tasklist_lock);
69444+ rcu_read_unlock();
69445+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
69446+ return 0;
69447+ }
69448+ }
69449+
69450+allow:
69451+ read_unlock(&tasklist_lock);
69452+ rcu_read_unlock();
69453+#endif
69454+ return 1;
69455+}
69456+
69457+void
69458+gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
69459+{
69460+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
69461+ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
69462+ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
69463+#endif
69464+ return;
69465+}
69466+
69467+int
69468+gr_handle_chroot_mknod(const struct dentry *dentry,
69469+ const struct vfsmount *mnt, const int mode)
69470+{
69471+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
69472+ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
69473+ proc_is_chrooted(current)) {
69474+ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
69475+ return -EPERM;
69476+ }
69477+#endif
69478+ return 0;
69479+}
69480+
69481+int
69482+gr_handle_chroot_mount(const struct dentry *dentry,
69483+ const struct vfsmount *mnt, const char *dev_name)
69484+{
69485+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
69486+ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
69487+ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
69488+ return -EPERM;
69489+ }
69490+#endif
69491+ return 0;
69492+}
69493+
69494+int
69495+gr_handle_chroot_pivot(void)
69496+{
69497+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
69498+ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
69499+ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
69500+ return -EPERM;
69501+ }
69502+#endif
69503+ return 0;
69504+}
69505+
69506+int
69507+gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
69508+{
69509+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
69510+ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
69511+ !gr_is_outside_chroot(dentry, mnt)) {
69512+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
69513+ return -EPERM;
69514+ }
69515+#endif
69516+ return 0;
69517+}
69518+
69519+extern const char *captab_log[];
69520+extern int captab_log_entries;
69521+
69522+int
69523+gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
69524+{
69525+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
69526+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
69527+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
69528+ if (cap_raised(chroot_caps, cap)) {
69529+ if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
69530+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
69531+ }
69532+ return 0;
69533+ }
69534+ }
69535+#endif
69536+ return 1;
69537+}
69538+
69539+int
69540+gr_chroot_is_capable(const int cap)
69541+{
69542+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
69543+ return gr_task_chroot_is_capable(current, current_cred(), cap);
69544+#endif
69545+ return 1;
69546+}
69547+
69548+int
69549+gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
69550+{
69551+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
69552+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
69553+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
69554+ if (cap_raised(chroot_caps, cap)) {
69555+ return 0;
69556+ }
69557+ }
69558+#endif
69559+ return 1;
69560+}
69561+
69562+int
69563+gr_chroot_is_capable_nolog(const int cap)
69564+{
69565+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
69566+ return gr_task_chroot_is_capable_nolog(current, cap);
69567+#endif
69568+ return 1;
69569+}
69570+
69571+int
69572+gr_handle_chroot_sysctl(const int op)
69573+{
69574+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
69575+ if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
69576+ proc_is_chrooted(current))
69577+ return -EACCES;
69578+#endif
69579+ return 0;
69580+}
69581+
69582+void
69583+gr_handle_chroot_chdir(const struct path *path)
69584+{
69585+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
69586+ if (grsec_enable_chroot_chdir)
69587+ set_fs_pwd(current->fs, path);
69588+#endif
69589+ return;
69590+}
69591+
69592+int
69593+gr_handle_chroot_chmod(const struct dentry *dentry,
69594+ const struct vfsmount *mnt, const int mode)
69595+{
69596+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
69597+ /* allow chmod +s on directories, but not files */
69598+ if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
69599+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
69600+ proc_is_chrooted(current)) {
69601+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
69602+ return -EPERM;
69603+ }
69604+#endif
69605+ return 0;
69606+}
69607diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
69608new file mode 100644
69609index 0000000..0866ab2
69610--- /dev/null
69611+++ b/grsecurity/grsec_disabled.c
69612@@ -0,0 +1,427 @@
69613+#include <linux/kernel.h>
69614+#include <linux/module.h>
69615+#include <linux/sched.h>
69616+#include <linux/file.h>
69617+#include <linux/fs.h>
69618+#include <linux/kdev_t.h>
69619+#include <linux/net.h>
69620+#include <linux/in.h>
69621+#include <linux/ip.h>
69622+#include <linux/skbuff.h>
69623+#include <linux/sysctl.h>
69624+
69625+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
69626+void
69627+pax_set_initial_flags(struct linux_binprm *bprm)
69628+{
69629+ return;
69630+}
69631+#endif
69632+
69633+#ifdef CONFIG_SYSCTL
69634+__u32
69635+gr_handle_sysctl(const struct ctl_table * table, const int op)
69636+{
69637+ return 0;
69638+}
69639+#endif
69640+
69641+#ifdef CONFIG_TASKSTATS
69642+int gr_is_taskstats_denied(int pid)
69643+{
69644+ return 0;
69645+}
69646+#endif
69647+
69648+int
69649+gr_acl_is_enabled(void)
69650+{
69651+ return 0;
69652+}
69653+
69654+void
69655+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
69656+{
69657+ return;
69658+}
69659+
69660+int
69661+gr_handle_rawio(const struct inode *inode)
69662+{
69663+ return 0;
69664+}
69665+
69666+void
69667+gr_acl_handle_psacct(struct task_struct *task, const long code)
69668+{
69669+ return;
69670+}
69671+
69672+int
69673+gr_handle_ptrace(struct task_struct *task, const long request)
69674+{
69675+ return 0;
69676+}
69677+
69678+int
69679+gr_handle_proc_ptrace(struct task_struct *task)
69680+{
69681+ return 0;
69682+}
69683+
69684+int
69685+gr_set_acls(const int type)
69686+{
69687+ return 0;
69688+}
69689+
69690+int
69691+gr_check_hidden_task(const struct task_struct *tsk)
69692+{
69693+ return 0;
69694+}
69695+
69696+int
69697+gr_check_protected_task(const struct task_struct *task)
69698+{
69699+ return 0;
69700+}
69701+
69702+int
69703+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
69704+{
69705+ return 0;
69706+}
69707+
69708+void
69709+gr_copy_label(struct task_struct *tsk)
69710+{
69711+ return;
69712+}
69713+
69714+void
69715+gr_set_pax_flags(struct task_struct *task)
69716+{
69717+ return;
69718+}
69719+
69720+int
69721+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
69722+ const int unsafe_share)
69723+{
69724+ return 0;
69725+}
69726+
69727+void
69728+gr_handle_delete(const ino_t ino, const dev_t dev)
69729+{
69730+ return;
69731+}
69732+
69733+void
69734+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
69735+{
69736+ return;
69737+}
69738+
69739+void
69740+gr_handle_crash(struct task_struct *task, const int sig)
69741+{
69742+ return;
69743+}
69744+
69745+int
69746+gr_check_crash_exec(const struct file *filp)
69747+{
69748+ return 0;
69749+}
69750+
69751+int
69752+gr_check_crash_uid(const kuid_t uid)
69753+{
69754+ return 0;
69755+}
69756+
69757+void
69758+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
69759+ struct dentry *old_dentry,
69760+ struct dentry *new_dentry,
69761+ struct vfsmount *mnt, const __u8 replace)
69762+{
69763+ return;
69764+}
69765+
69766+int
69767+gr_search_socket(const int family, const int type, const int protocol)
69768+{
69769+ return 1;
69770+}
69771+
69772+int
69773+gr_search_connectbind(const int mode, const struct socket *sock,
69774+ const struct sockaddr_in *addr)
69775+{
69776+ return 0;
69777+}
69778+
69779+void
69780+gr_handle_alertkill(struct task_struct *task)
69781+{
69782+ return;
69783+}
69784+
69785+__u32
69786+gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
69787+{
69788+ return 1;
69789+}
69790+
69791+__u32
69792+gr_acl_handle_hidden_file(const struct dentry * dentry,
69793+ const struct vfsmount * mnt)
69794+{
69795+ return 1;
69796+}
69797+
69798+__u32
69799+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
69800+ int acc_mode)
69801+{
69802+ return 1;
69803+}
69804+
69805+__u32
69806+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
69807+{
69808+ return 1;
69809+}
69810+
69811+__u32
69812+gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
69813+{
69814+ return 1;
69815+}
69816+
69817+int
69818+gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
69819+ unsigned int *vm_flags)
69820+{
69821+ return 1;
69822+}
69823+
69824+__u32
69825+gr_acl_handle_truncate(const struct dentry * dentry,
69826+ const struct vfsmount * mnt)
69827+{
69828+ return 1;
69829+}
69830+
69831+__u32
69832+gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
69833+{
69834+ return 1;
69835+}
69836+
69837+__u32
69838+gr_acl_handle_access(const struct dentry * dentry,
69839+ const struct vfsmount * mnt, const int fmode)
69840+{
69841+ return 1;
69842+}
69843+
69844+__u32
69845+gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
69846+ umode_t *mode)
69847+{
69848+ return 1;
69849+}
69850+
69851+__u32
69852+gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
69853+{
69854+ return 1;
69855+}
69856+
69857+__u32
69858+gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
69859+{
69860+ return 1;
69861+}
69862+
69863+void
69864+grsecurity_init(void)
69865+{
69866+ return;
69867+}
69868+
69869+umode_t gr_acl_umask(void)
69870+{
69871+ return 0;
69872+}
69873+
69874+__u32
69875+gr_acl_handle_mknod(const struct dentry * new_dentry,
69876+ const struct dentry * parent_dentry,
69877+ const struct vfsmount * parent_mnt,
69878+ const int mode)
69879+{
69880+ return 1;
69881+}
69882+
69883+__u32
69884+gr_acl_handle_mkdir(const struct dentry * new_dentry,
69885+ const struct dentry * parent_dentry,
69886+ const struct vfsmount * parent_mnt)
69887+{
69888+ return 1;
69889+}
69890+
69891+__u32
69892+gr_acl_handle_symlink(const struct dentry * new_dentry,
69893+ const struct dentry * parent_dentry,
69894+ const struct vfsmount * parent_mnt, const struct filename *from)
69895+{
69896+ return 1;
69897+}
69898+
69899+__u32
69900+gr_acl_handle_link(const struct dentry * new_dentry,
69901+ const struct dentry * parent_dentry,
69902+ const struct vfsmount * parent_mnt,
69903+ const struct dentry * old_dentry,
69904+ const struct vfsmount * old_mnt, const struct filename *to)
69905+{
69906+ return 1;
69907+}
69908+
69909+int
69910+gr_acl_handle_rename(const struct dentry *new_dentry,
69911+ const struct dentry *parent_dentry,
69912+ const struct vfsmount *parent_mnt,
69913+ const struct dentry *old_dentry,
69914+ const struct inode *old_parent_inode,
69915+ const struct vfsmount *old_mnt, const struct filename *newname)
69916+{
69917+ return 0;
69918+}
69919+
69920+int
69921+gr_acl_handle_filldir(const struct file *file, const char *name,
69922+ const int namelen, const ino_t ino)
69923+{
69924+ return 1;
69925+}
69926+
69927+int
69928+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
69929+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
69930+{
69931+ return 1;
69932+}
69933+
69934+int
69935+gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
69936+{
69937+ return 0;
69938+}
69939+
69940+int
69941+gr_search_accept(const struct socket *sock)
69942+{
69943+ return 0;
69944+}
69945+
69946+int
69947+gr_search_listen(const struct socket *sock)
69948+{
69949+ return 0;
69950+}
69951+
69952+int
69953+gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
69954+{
69955+ return 0;
69956+}
69957+
69958+__u32
69959+gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
69960+{
69961+ return 1;
69962+}
69963+
69964+__u32
69965+gr_acl_handle_creat(const struct dentry * dentry,
69966+ const struct dentry * p_dentry,
69967+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
69968+ const int imode)
69969+{
69970+ return 1;
69971+}
69972+
69973+void
69974+gr_acl_handle_exit(void)
69975+{
69976+ return;
69977+}
69978+
69979+int
69980+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
69981+{
69982+ return 1;
69983+}
69984+
69985+void
69986+gr_set_role_label(const kuid_t uid, const kgid_t gid)
69987+{
69988+ return;
69989+}
69990+
69991+int
69992+gr_acl_handle_procpidmem(const struct task_struct *task)
69993+{
69994+ return 0;
69995+}
69996+
69997+int
69998+gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
69999+{
70000+ return 0;
70001+}
70002+
70003+int
70004+gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
70005+{
70006+ return 0;
70007+}
70008+
70009+int
70010+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
70011+{
70012+ return 0;
70013+}
70014+
70015+int
70016+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
70017+{
70018+ return 0;
70019+}
70020+
70021+int gr_acl_enable_at_secure(void)
70022+{
70023+ return 0;
70024+}
70025+
70026+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
70027+{
70028+ return dentry->d_sb->s_dev;
70029+}
70030+
70031+void gr_put_exec_file(struct task_struct *task)
70032+{
70033+ return;
70034+}
70035+
70036+#ifdef CONFIG_SECURITY
70037+EXPORT_SYMBOL(gr_check_user_change);
70038+EXPORT_SYMBOL(gr_check_group_change);
70039+#endif
70040diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
70041new file mode 100644
70042index 0000000..387032b
70043--- /dev/null
70044+++ b/grsecurity/grsec_exec.c
70045@@ -0,0 +1,187 @@
70046+#include <linux/kernel.h>
70047+#include <linux/sched.h>
70048+#include <linux/file.h>
70049+#include <linux/binfmts.h>
70050+#include <linux/fs.h>
70051+#include <linux/types.h>
70052+#include <linux/grdefs.h>
70053+#include <linux/grsecurity.h>
70054+#include <linux/grinternal.h>
70055+#include <linux/capability.h>
70056+#include <linux/module.h>
70057+#include <linux/compat.h>
70058+
70059+#include <asm/uaccess.h>
70060+
70061+#ifdef CONFIG_GRKERNSEC_EXECLOG
70062+static char gr_exec_arg_buf[132];
70063+static DEFINE_MUTEX(gr_exec_arg_mutex);
70064+#endif
70065+
70066+struct user_arg_ptr {
70067+#ifdef CONFIG_COMPAT
70068+ bool is_compat;
70069+#endif
70070+ union {
70071+ const char __user *const __user *native;
70072+#ifdef CONFIG_COMPAT
70073+ const compat_uptr_t __user *compat;
70074+#endif
70075+ } ptr;
70076+};
70077+
70078+extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
70079+
70080+void
70081+gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
70082+{
70083+#ifdef CONFIG_GRKERNSEC_EXECLOG
70084+ char *grarg = gr_exec_arg_buf;
70085+ unsigned int i, x, execlen = 0;
70086+ char c;
70087+
70088+ if (!((grsec_enable_execlog && grsec_enable_group &&
70089+ in_group_p(grsec_audit_gid))
70090+ || (grsec_enable_execlog && !grsec_enable_group)))
70091+ return;
70092+
70093+ mutex_lock(&gr_exec_arg_mutex);
70094+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
70095+
70096+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
70097+ const char __user *p;
70098+ unsigned int len;
70099+
70100+ p = get_user_arg_ptr(argv, i);
70101+ if (IS_ERR(p))
70102+ goto log;
70103+
70104+ len = strnlen_user(p, 128 - execlen);
70105+ if (len > 128 - execlen)
70106+ len = 128 - execlen;
70107+ else if (len > 0)
70108+ len--;
70109+ if (copy_from_user(grarg + execlen, p, len))
70110+ goto log;
70111+
70112+ /* rewrite unprintable characters */
70113+ for (x = 0; x < len; x++) {
70114+ c = *(grarg + execlen + x);
70115+ if (c < 32 || c > 126)
70116+ *(grarg + execlen + x) = ' ';
70117+ }
70118+
70119+ execlen += len;
70120+ *(grarg + execlen) = ' ';
70121+ *(grarg + execlen + 1) = '\0';
70122+ execlen++;
70123+ }
70124+
70125+ log:
70126+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
70127+ bprm->file->f_path.mnt, grarg);
70128+ mutex_unlock(&gr_exec_arg_mutex);
70129+#endif
70130+ return;
70131+}
70132+
70133+#ifdef CONFIG_GRKERNSEC
70134+extern int gr_acl_is_capable(const int cap);
70135+extern int gr_acl_is_capable_nolog(const int cap);
70136+extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
70137+extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
70138+extern int gr_chroot_is_capable(const int cap);
70139+extern int gr_chroot_is_capable_nolog(const int cap);
70140+extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
70141+extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
70142+#endif
70143+
70144+const char *captab_log[] = {
70145+ "CAP_CHOWN",
70146+ "CAP_DAC_OVERRIDE",
70147+ "CAP_DAC_READ_SEARCH",
70148+ "CAP_FOWNER",
70149+ "CAP_FSETID",
70150+ "CAP_KILL",
70151+ "CAP_SETGID",
70152+ "CAP_SETUID",
70153+ "CAP_SETPCAP",
70154+ "CAP_LINUX_IMMUTABLE",
70155+ "CAP_NET_BIND_SERVICE",
70156+ "CAP_NET_BROADCAST",
70157+ "CAP_NET_ADMIN",
70158+ "CAP_NET_RAW",
70159+ "CAP_IPC_LOCK",
70160+ "CAP_IPC_OWNER",
70161+ "CAP_SYS_MODULE",
70162+ "CAP_SYS_RAWIO",
70163+ "CAP_SYS_CHROOT",
70164+ "CAP_SYS_PTRACE",
70165+ "CAP_SYS_PACCT",
70166+ "CAP_SYS_ADMIN",
70167+ "CAP_SYS_BOOT",
70168+ "CAP_SYS_NICE",
70169+ "CAP_SYS_RESOURCE",
70170+ "CAP_SYS_TIME",
70171+ "CAP_SYS_TTY_CONFIG",
70172+ "CAP_MKNOD",
70173+ "CAP_LEASE",
70174+ "CAP_AUDIT_WRITE",
70175+ "CAP_AUDIT_CONTROL",
70176+ "CAP_SETFCAP",
70177+ "CAP_MAC_OVERRIDE",
70178+ "CAP_MAC_ADMIN",
70179+ "CAP_SYSLOG",
70180+ "CAP_WAKE_ALARM"
70181+};
70182+
70183+int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
70184+
70185+int gr_is_capable(const int cap)
70186+{
70187+#ifdef CONFIG_GRKERNSEC
70188+ if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
70189+ return 1;
70190+ return 0;
70191+#else
70192+ return 1;
70193+#endif
70194+}
70195+
70196+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
70197+{
70198+#ifdef CONFIG_GRKERNSEC
70199+ if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
70200+ return 1;
70201+ return 0;
70202+#else
70203+ return 1;
70204+#endif
70205+}
70206+
70207+int gr_is_capable_nolog(const int cap)
70208+{
70209+#ifdef CONFIG_GRKERNSEC
70210+ if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
70211+ return 1;
70212+ return 0;
70213+#else
70214+ return 1;
70215+#endif
70216+}
70217+
70218+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
70219+{
70220+#ifdef CONFIG_GRKERNSEC
70221+ if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
70222+ return 1;
70223+ return 0;
70224+#else
70225+ return 1;
70226+#endif
70227+}
70228+
70229+EXPORT_SYMBOL(gr_is_capable);
70230+EXPORT_SYMBOL(gr_is_capable_nolog);
70231+EXPORT_SYMBOL(gr_task_is_capable);
70232+EXPORT_SYMBOL(gr_task_is_capable_nolog);
70233diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
70234new file mode 100644
70235index 0000000..06cc6ea
70236--- /dev/null
70237+++ b/grsecurity/grsec_fifo.c
70238@@ -0,0 +1,24 @@
70239+#include <linux/kernel.h>
70240+#include <linux/sched.h>
70241+#include <linux/fs.h>
70242+#include <linux/file.h>
70243+#include <linux/grinternal.h>
70244+
70245+int
70246+gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
70247+ const struct dentry *dir, const int flag, const int acc_mode)
70248+{
70249+#ifdef CONFIG_GRKERNSEC_FIFO
70250+ const struct cred *cred = current_cred();
70251+
70252+ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
70253+ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
70254+ !uid_eq(dentry->d_inode->i_uid, dir->d_inode->i_uid) &&
70255+ !uid_eq(cred->fsuid, dentry->d_inode->i_uid)) {
70256+ if (!inode_permission(dentry->d_inode, acc_mode))
70257+ 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));
70258+ return -EACCES;
70259+ }
70260+#endif
70261+ return 0;
70262+}
70263diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
70264new file mode 100644
70265index 0000000..8ca18bf
70266--- /dev/null
70267+++ b/grsecurity/grsec_fork.c
70268@@ -0,0 +1,23 @@
70269+#include <linux/kernel.h>
70270+#include <linux/sched.h>
70271+#include <linux/grsecurity.h>
70272+#include <linux/grinternal.h>
70273+#include <linux/errno.h>
70274+
70275+void
70276+gr_log_forkfail(const int retval)
70277+{
70278+#ifdef CONFIG_GRKERNSEC_FORKFAIL
70279+ if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
70280+ switch (retval) {
70281+ case -EAGAIN:
70282+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
70283+ break;
70284+ case -ENOMEM:
70285+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
70286+ break;
70287+ }
70288+ }
70289+#endif
70290+ return;
70291+}
70292diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
70293new file mode 100644
70294index 0000000..a88e901
70295--- /dev/null
70296+++ b/grsecurity/grsec_init.c
70297@@ -0,0 +1,272 @@
70298+#include <linux/kernel.h>
70299+#include <linux/sched.h>
70300+#include <linux/mm.h>
70301+#include <linux/gracl.h>
70302+#include <linux/slab.h>
70303+#include <linux/vmalloc.h>
70304+#include <linux/percpu.h>
70305+#include <linux/module.h>
70306+
70307+int grsec_enable_ptrace_readexec;
70308+int grsec_enable_setxid;
70309+int grsec_enable_symlinkown;
70310+kgid_t grsec_symlinkown_gid;
70311+int grsec_enable_brute;
70312+int grsec_enable_link;
70313+int grsec_enable_dmesg;
70314+int grsec_enable_harden_ptrace;
70315+int grsec_enable_harden_ipc;
70316+int grsec_enable_fifo;
70317+int grsec_enable_execlog;
70318+int grsec_enable_signal;
70319+int grsec_enable_forkfail;
70320+int grsec_enable_audit_ptrace;
70321+int grsec_enable_time;
70322+int grsec_enable_group;
70323+kgid_t grsec_audit_gid;
70324+int grsec_enable_chdir;
70325+int grsec_enable_mount;
70326+int grsec_enable_rofs;
70327+int grsec_deny_new_usb;
70328+int grsec_enable_chroot_findtask;
70329+int grsec_enable_chroot_mount;
70330+int grsec_enable_chroot_shmat;
70331+int grsec_enable_chroot_fchdir;
70332+int grsec_enable_chroot_double;
70333+int grsec_enable_chroot_pivot;
70334+int grsec_enable_chroot_chdir;
70335+int grsec_enable_chroot_chmod;
70336+int grsec_enable_chroot_mknod;
70337+int grsec_enable_chroot_nice;
70338+int grsec_enable_chroot_execlog;
70339+int grsec_enable_chroot_caps;
70340+int grsec_enable_chroot_sysctl;
70341+int grsec_enable_chroot_unix;
70342+int grsec_enable_tpe;
70343+kgid_t grsec_tpe_gid;
70344+int grsec_enable_blackhole;
70345+#ifdef CONFIG_IPV6_MODULE
70346+EXPORT_SYMBOL(grsec_enable_blackhole);
70347+#endif
70348+int grsec_lastack_retries;
70349+int grsec_enable_tpe_all;
70350+int grsec_enable_tpe_invert;
70351+int grsec_enable_socket_all;
70352+kgid_t grsec_socket_all_gid;
70353+int grsec_enable_socket_client;
70354+kgid_t grsec_socket_client_gid;
70355+int grsec_enable_socket_server;
70356+kgid_t grsec_socket_server_gid;
70357+int grsec_resource_logging;
70358+int grsec_disable_privio;
70359+int grsec_enable_log_rwxmaps;
70360+int grsec_lock;
70361+
70362+DEFINE_SPINLOCK(grsec_alert_lock);
70363+unsigned long grsec_alert_wtime = 0;
70364+unsigned long grsec_alert_fyet = 0;
70365+
70366+DEFINE_SPINLOCK(grsec_audit_lock);
70367+
70368+DEFINE_RWLOCK(grsec_exec_file_lock);
70369+
70370+char *gr_shared_page[4];
70371+
70372+char *gr_alert_log_fmt;
70373+char *gr_audit_log_fmt;
70374+char *gr_alert_log_buf;
70375+char *gr_audit_log_buf;
70376+
70377+void __init
70378+grsecurity_init(void)
70379+{
70380+ int j;
70381+ /* create the per-cpu shared pages */
70382+
70383+#ifdef CONFIG_X86
70384+ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
70385+#endif
70386+
70387+ for (j = 0; j < 4; j++) {
70388+ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
70389+ if (gr_shared_page[j] == NULL) {
70390+ panic("Unable to allocate grsecurity shared page");
70391+ return;
70392+ }
70393+ }
70394+
70395+ /* allocate log buffers */
70396+ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
70397+ if (!gr_alert_log_fmt) {
70398+ panic("Unable to allocate grsecurity alert log format buffer");
70399+ return;
70400+ }
70401+ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
70402+ if (!gr_audit_log_fmt) {
70403+ panic("Unable to allocate grsecurity audit log format buffer");
70404+ return;
70405+ }
70406+ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
70407+ if (!gr_alert_log_buf) {
70408+ panic("Unable to allocate grsecurity alert log buffer");
70409+ return;
70410+ }
70411+ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
70412+ if (!gr_audit_log_buf) {
70413+ panic("Unable to allocate grsecurity audit log buffer");
70414+ return;
70415+ }
70416+
70417+#ifdef CONFIG_GRKERNSEC_IO
70418+#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
70419+ grsec_disable_privio = 1;
70420+#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
70421+ grsec_disable_privio = 1;
70422+#else
70423+ grsec_disable_privio = 0;
70424+#endif
70425+#endif
70426+
70427+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
70428+ /* for backward compatibility, tpe_invert always defaults to on if
70429+ enabled in the kernel
70430+ */
70431+ grsec_enable_tpe_invert = 1;
70432+#endif
70433+
70434+#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
70435+#ifndef CONFIG_GRKERNSEC_SYSCTL
70436+ grsec_lock = 1;
70437+#endif
70438+
70439+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
70440+ grsec_enable_log_rwxmaps = 1;
70441+#endif
70442+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
70443+ grsec_enable_group = 1;
70444+ grsec_audit_gid = KGIDT_INIT(CONFIG_GRKERNSEC_AUDIT_GID);
70445+#endif
70446+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
70447+ grsec_enable_ptrace_readexec = 1;
70448+#endif
70449+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
70450+ grsec_enable_chdir = 1;
70451+#endif
70452+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
70453+ grsec_enable_harden_ptrace = 1;
70454+#endif
70455+#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
70456+ grsec_enable_harden_ipc = 1;
70457+#endif
70458+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
70459+ grsec_enable_mount = 1;
70460+#endif
70461+#ifdef CONFIG_GRKERNSEC_LINK
70462+ grsec_enable_link = 1;
70463+#endif
70464+#ifdef CONFIG_GRKERNSEC_BRUTE
70465+ grsec_enable_brute = 1;
70466+#endif
70467+#ifdef CONFIG_GRKERNSEC_DMESG
70468+ grsec_enable_dmesg = 1;
70469+#endif
70470+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
70471+ grsec_enable_blackhole = 1;
70472+ grsec_lastack_retries = 4;
70473+#endif
70474+#ifdef CONFIG_GRKERNSEC_FIFO
70475+ grsec_enable_fifo = 1;
70476+#endif
70477+#ifdef CONFIG_GRKERNSEC_EXECLOG
70478+ grsec_enable_execlog = 1;
70479+#endif
70480+#ifdef CONFIG_GRKERNSEC_SETXID
70481+ grsec_enable_setxid = 1;
70482+#endif
70483+#ifdef CONFIG_GRKERNSEC_SIGNAL
70484+ grsec_enable_signal = 1;
70485+#endif
70486+#ifdef CONFIG_GRKERNSEC_FORKFAIL
70487+ grsec_enable_forkfail = 1;
70488+#endif
70489+#ifdef CONFIG_GRKERNSEC_TIME
70490+ grsec_enable_time = 1;
70491+#endif
70492+#ifdef CONFIG_GRKERNSEC_RESLOG
70493+ grsec_resource_logging = 1;
70494+#endif
70495+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
70496+ grsec_enable_chroot_findtask = 1;
70497+#endif
70498+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
70499+ grsec_enable_chroot_unix = 1;
70500+#endif
70501+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
70502+ grsec_enable_chroot_mount = 1;
70503+#endif
70504+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
70505+ grsec_enable_chroot_fchdir = 1;
70506+#endif
70507+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
70508+ grsec_enable_chroot_shmat = 1;
70509+#endif
70510+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
70511+ grsec_enable_audit_ptrace = 1;
70512+#endif
70513+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
70514+ grsec_enable_chroot_double = 1;
70515+#endif
70516+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
70517+ grsec_enable_chroot_pivot = 1;
70518+#endif
70519+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
70520+ grsec_enable_chroot_chdir = 1;
70521+#endif
70522+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
70523+ grsec_enable_chroot_chmod = 1;
70524+#endif
70525+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
70526+ grsec_enable_chroot_mknod = 1;
70527+#endif
70528+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
70529+ grsec_enable_chroot_nice = 1;
70530+#endif
70531+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
70532+ grsec_enable_chroot_execlog = 1;
70533+#endif
70534+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
70535+ grsec_enable_chroot_caps = 1;
70536+#endif
70537+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
70538+ grsec_enable_chroot_sysctl = 1;
70539+#endif
70540+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
70541+ grsec_enable_symlinkown = 1;
70542+ grsec_symlinkown_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SYMLINKOWN_GID);
70543+#endif
70544+#ifdef CONFIG_GRKERNSEC_TPE
70545+ grsec_enable_tpe = 1;
70546+ grsec_tpe_gid = KGIDT_INIT(CONFIG_GRKERNSEC_TPE_GID);
70547+#ifdef CONFIG_GRKERNSEC_TPE_ALL
70548+ grsec_enable_tpe_all = 1;
70549+#endif
70550+#endif
70551+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
70552+ grsec_enable_socket_all = 1;
70553+ grsec_socket_all_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_ALL_GID);
70554+#endif
70555+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
70556+ grsec_enable_socket_client = 1;
70557+ grsec_socket_client_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_CLIENT_GID);
70558+#endif
70559+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
70560+ grsec_enable_socket_server = 1;
70561+ grsec_socket_server_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_SERVER_GID);
70562+#endif
70563+#endif
70564+#ifdef CONFIG_GRKERNSEC_DENYUSB_FORCE
70565+ grsec_deny_new_usb = 1;
70566+#endif
70567+
70568+ return;
70569+}
70570diff --git a/grsecurity/grsec_ipc.c b/grsecurity/grsec_ipc.c
70571new file mode 100644
70572index 0000000..f365de0
70573--- /dev/null
70574+++ b/grsecurity/grsec_ipc.c
70575@@ -0,0 +1,22 @@
70576+#include <linux/kernel.h>
70577+#include <linux/mm.h>
70578+#include <linux/sched.h>
70579+#include <linux/file.h>
70580+#include <linux/ipc.h>
70581+#include <linux/ipc_namespace.h>
70582+#include <linux/grsecurity.h>
70583+#include <linux/grinternal.h>
70584+
70585+int
70586+gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode)
70587+{
70588+#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
70589+ int write = (requested_mode & 00002);
70590+
70591+ if (grsec_enable_harden_ipc && !(requested_mode & ~granted_mode & 0007) && !ns_capable_nolog(ns->user_ns, CAP_IPC_OWNER)) {
70592+ gr_log_str2_int(GR_DONT_AUDIT, GR_IPC_DENIED_MSG, write ? "write" : "read", write ? "writ" : "read", GR_GLOBAL_UID(ipcp->cuid));
70593+ return 0;
70594+ }
70595+#endif
70596+ return 1;
70597+}
70598diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
70599new file mode 100644
70600index 0000000..5e05e20
70601--- /dev/null
70602+++ b/grsecurity/grsec_link.c
70603@@ -0,0 +1,58 @@
70604+#include <linux/kernel.h>
70605+#include <linux/sched.h>
70606+#include <linux/fs.h>
70607+#include <linux/file.h>
70608+#include <linux/grinternal.h>
70609+
70610+int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
70611+{
70612+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
70613+ const struct inode *link_inode = link->dentry->d_inode;
70614+
70615+ if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
70616+ /* ignore root-owned links, e.g. /proc/self */
70617+ gr_is_global_nonroot(link_inode->i_uid) && target &&
70618+ !uid_eq(link_inode->i_uid, target->i_uid)) {
70619+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
70620+ return 1;
70621+ }
70622+#endif
70623+ return 0;
70624+}
70625+
70626+int
70627+gr_handle_follow_link(const struct inode *parent,
70628+ const struct inode *inode,
70629+ const struct dentry *dentry, const struct vfsmount *mnt)
70630+{
70631+#ifdef CONFIG_GRKERNSEC_LINK
70632+ const struct cred *cred = current_cred();
70633+
70634+ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
70635+ (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
70636+ (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
70637+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
70638+ return -EACCES;
70639+ }
70640+#endif
70641+ return 0;
70642+}
70643+
70644+int
70645+gr_handle_hardlink(const struct dentry *dentry,
70646+ const struct vfsmount *mnt,
70647+ struct inode *inode, const int mode, const struct filename *to)
70648+{
70649+#ifdef CONFIG_GRKERNSEC_LINK
70650+ const struct cred *cred = current_cred();
70651+
70652+ if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
70653+ (!S_ISREG(mode) || is_privileged_binary(dentry) ||
70654+ (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
70655+ !capable(CAP_FOWNER) && gr_is_global_nonroot(cred->uid)) {
70656+ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
70657+ return -EPERM;
70658+ }
70659+#endif
70660+ return 0;
70661+}
70662diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
70663new file mode 100644
70664index 0000000..dbe0a6b
70665--- /dev/null
70666+++ b/grsecurity/grsec_log.c
70667@@ -0,0 +1,341 @@
70668+#include <linux/kernel.h>
70669+#include <linux/sched.h>
70670+#include <linux/file.h>
70671+#include <linux/tty.h>
70672+#include <linux/fs.h>
70673+#include <linux/mm.h>
70674+#include <linux/grinternal.h>
70675+
70676+#ifdef CONFIG_TREE_PREEMPT_RCU
70677+#define DISABLE_PREEMPT() preempt_disable()
70678+#define ENABLE_PREEMPT() preempt_enable()
70679+#else
70680+#define DISABLE_PREEMPT()
70681+#define ENABLE_PREEMPT()
70682+#endif
70683+
70684+#define BEGIN_LOCKS(x) \
70685+ DISABLE_PREEMPT(); \
70686+ rcu_read_lock(); \
70687+ read_lock(&tasklist_lock); \
70688+ read_lock(&grsec_exec_file_lock); \
70689+ if (x != GR_DO_AUDIT) \
70690+ spin_lock(&grsec_alert_lock); \
70691+ else \
70692+ spin_lock(&grsec_audit_lock)
70693+
70694+#define END_LOCKS(x) \
70695+ if (x != GR_DO_AUDIT) \
70696+ spin_unlock(&grsec_alert_lock); \
70697+ else \
70698+ spin_unlock(&grsec_audit_lock); \
70699+ read_unlock(&grsec_exec_file_lock); \
70700+ read_unlock(&tasklist_lock); \
70701+ rcu_read_unlock(); \
70702+ ENABLE_PREEMPT(); \
70703+ if (x == GR_DONT_AUDIT) \
70704+ gr_handle_alertkill(current)
70705+
70706+enum {
70707+ FLOODING,
70708+ NO_FLOODING
70709+};
70710+
70711+extern char *gr_alert_log_fmt;
70712+extern char *gr_audit_log_fmt;
70713+extern char *gr_alert_log_buf;
70714+extern char *gr_audit_log_buf;
70715+
70716+static int gr_log_start(int audit)
70717+{
70718+ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
70719+ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
70720+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
70721+#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
70722+ unsigned long curr_secs = get_seconds();
70723+
70724+ if (audit == GR_DO_AUDIT)
70725+ goto set_fmt;
70726+
70727+ if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
70728+ grsec_alert_wtime = curr_secs;
70729+ grsec_alert_fyet = 0;
70730+ } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
70731+ && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
70732+ grsec_alert_fyet++;
70733+ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
70734+ grsec_alert_wtime = curr_secs;
70735+ grsec_alert_fyet++;
70736+ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
70737+ return FLOODING;
70738+ }
70739+ else return FLOODING;
70740+
70741+set_fmt:
70742+#endif
70743+ memset(buf, 0, PAGE_SIZE);
70744+ if (current->signal->curr_ip && gr_acl_is_enabled()) {
70745+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
70746+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
70747+ } else if (current->signal->curr_ip) {
70748+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
70749+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
70750+ } else if (gr_acl_is_enabled()) {
70751+ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
70752+ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
70753+ } else {
70754+ sprintf(fmt, "%s%s", loglevel, "grsec: ");
70755+ strcpy(buf, fmt);
70756+ }
70757+
70758+ return NO_FLOODING;
70759+}
70760+
70761+static void gr_log_middle(int audit, const char *msg, va_list ap)
70762+ __attribute__ ((format (printf, 2, 0)));
70763+
70764+static void gr_log_middle(int audit, const char *msg, va_list ap)
70765+{
70766+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
70767+ unsigned int len = strlen(buf);
70768+
70769+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
70770+
70771+ return;
70772+}
70773+
70774+static void gr_log_middle_varargs(int audit, const char *msg, ...)
70775+ __attribute__ ((format (printf, 2, 3)));
70776+
70777+static void gr_log_middle_varargs(int audit, const char *msg, ...)
70778+{
70779+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
70780+ unsigned int len = strlen(buf);
70781+ va_list ap;
70782+
70783+ va_start(ap, msg);
70784+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
70785+ va_end(ap);
70786+
70787+ return;
70788+}
70789+
70790+static void gr_log_end(int audit, int append_default)
70791+{
70792+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
70793+ if (append_default) {
70794+ struct task_struct *task = current;
70795+ struct task_struct *parent = task->real_parent;
70796+ const struct cred *cred = __task_cred(task);
70797+ const struct cred *pcred = __task_cred(parent);
70798+ unsigned int len = strlen(buf);
70799+
70800+ 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));
70801+ }
70802+
70803+ printk("%s\n", buf);
70804+
70805+ return;
70806+}
70807+
70808+void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
70809+{
70810+ int logtype;
70811+ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
70812+ char *str1 = NULL, *str2 = NULL, *str3 = NULL;
70813+ void *voidptr = NULL;
70814+ int num1 = 0, num2 = 0;
70815+ unsigned long ulong1 = 0, ulong2 = 0;
70816+ struct dentry *dentry = NULL;
70817+ struct vfsmount *mnt = NULL;
70818+ struct file *file = NULL;
70819+ struct task_struct *task = NULL;
70820+ struct vm_area_struct *vma = NULL;
70821+ const struct cred *cred, *pcred;
70822+ va_list ap;
70823+
70824+ BEGIN_LOCKS(audit);
70825+ logtype = gr_log_start(audit);
70826+ if (logtype == FLOODING) {
70827+ END_LOCKS(audit);
70828+ return;
70829+ }
70830+ va_start(ap, argtypes);
70831+ switch (argtypes) {
70832+ case GR_TTYSNIFF:
70833+ task = va_arg(ap, struct task_struct *);
70834+ 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));
70835+ break;
70836+ case GR_SYSCTL_HIDDEN:
70837+ str1 = va_arg(ap, char *);
70838+ gr_log_middle_varargs(audit, msg, result, str1);
70839+ break;
70840+ case GR_RBAC:
70841+ dentry = va_arg(ap, struct dentry *);
70842+ mnt = va_arg(ap, struct vfsmount *);
70843+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
70844+ break;
70845+ case GR_RBAC_STR:
70846+ dentry = va_arg(ap, struct dentry *);
70847+ mnt = va_arg(ap, struct vfsmount *);
70848+ str1 = va_arg(ap, char *);
70849+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
70850+ break;
70851+ case GR_STR_RBAC:
70852+ str1 = va_arg(ap, char *);
70853+ dentry = va_arg(ap, struct dentry *);
70854+ mnt = va_arg(ap, struct vfsmount *);
70855+ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
70856+ break;
70857+ case GR_RBAC_MODE2:
70858+ dentry = va_arg(ap, struct dentry *);
70859+ mnt = va_arg(ap, struct vfsmount *);
70860+ str1 = va_arg(ap, char *);
70861+ str2 = va_arg(ap, char *);
70862+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
70863+ break;
70864+ case GR_RBAC_MODE3:
70865+ dentry = va_arg(ap, struct dentry *);
70866+ mnt = va_arg(ap, struct vfsmount *);
70867+ str1 = va_arg(ap, char *);
70868+ str2 = va_arg(ap, char *);
70869+ str3 = va_arg(ap, char *);
70870+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
70871+ break;
70872+ case GR_FILENAME:
70873+ dentry = va_arg(ap, struct dentry *);
70874+ mnt = va_arg(ap, struct vfsmount *);
70875+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
70876+ break;
70877+ case GR_STR_FILENAME:
70878+ str1 = va_arg(ap, char *);
70879+ dentry = va_arg(ap, struct dentry *);
70880+ mnt = va_arg(ap, struct vfsmount *);
70881+ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
70882+ break;
70883+ case GR_FILENAME_STR:
70884+ dentry = va_arg(ap, struct dentry *);
70885+ mnt = va_arg(ap, struct vfsmount *);
70886+ str1 = va_arg(ap, char *);
70887+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
70888+ break;
70889+ case GR_FILENAME_TWO_INT:
70890+ dentry = va_arg(ap, struct dentry *);
70891+ mnt = va_arg(ap, struct vfsmount *);
70892+ num1 = va_arg(ap, int);
70893+ num2 = va_arg(ap, int);
70894+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
70895+ break;
70896+ case GR_FILENAME_TWO_INT_STR:
70897+ dentry = va_arg(ap, struct dentry *);
70898+ mnt = va_arg(ap, struct vfsmount *);
70899+ num1 = va_arg(ap, int);
70900+ num2 = va_arg(ap, int);
70901+ str1 = va_arg(ap, char *);
70902+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
70903+ break;
70904+ case GR_TEXTREL:
70905+ file = va_arg(ap, struct file *);
70906+ ulong1 = va_arg(ap, unsigned long);
70907+ ulong2 = va_arg(ap, unsigned long);
70908+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
70909+ break;
70910+ case GR_PTRACE:
70911+ task = va_arg(ap, struct task_struct *);
70912+ 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));
70913+ break;
70914+ case GR_RESOURCE:
70915+ task = va_arg(ap, struct task_struct *);
70916+ cred = __task_cred(task);
70917+ pcred = __task_cred(task->real_parent);
70918+ ulong1 = va_arg(ap, unsigned long);
70919+ str1 = va_arg(ap, char *);
70920+ ulong2 = va_arg(ap, unsigned long);
70921+ 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));
70922+ break;
70923+ case GR_CAP:
70924+ task = va_arg(ap, struct task_struct *);
70925+ cred = __task_cred(task);
70926+ pcred = __task_cred(task->real_parent);
70927+ str1 = va_arg(ap, char *);
70928+ 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));
70929+ break;
70930+ case GR_SIG:
70931+ str1 = va_arg(ap, char *);
70932+ voidptr = va_arg(ap, void *);
70933+ gr_log_middle_varargs(audit, msg, str1, voidptr);
70934+ break;
70935+ case GR_SIG2:
70936+ task = va_arg(ap, struct task_struct *);
70937+ cred = __task_cred(task);
70938+ pcred = __task_cred(task->real_parent);
70939+ num1 = va_arg(ap, int);
70940+ 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));
70941+ break;
70942+ case GR_CRASH1:
70943+ task = va_arg(ap, struct task_struct *);
70944+ cred = __task_cred(task);
70945+ pcred = __task_cred(task->real_parent);
70946+ ulong1 = va_arg(ap, unsigned long);
70947+ 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);
70948+ break;
70949+ case GR_CRASH2:
70950+ task = va_arg(ap, struct task_struct *);
70951+ cred = __task_cred(task);
70952+ pcred = __task_cred(task->real_parent);
70953+ ulong1 = va_arg(ap, unsigned long);
70954+ 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);
70955+ break;
70956+ case GR_RWXMAP:
70957+ file = va_arg(ap, struct file *);
70958+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
70959+ break;
70960+ case GR_RWXMAPVMA:
70961+ vma = va_arg(ap, struct vm_area_struct *);
70962+ if (vma->vm_file)
70963+ str1 = gr_to_filename(vma->vm_file->f_path.dentry, vma->vm_file->f_path.mnt);
70964+ else if (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
70965+ str1 = "<stack>";
70966+ else if (vma->vm_start <= current->mm->brk &&
70967+ vma->vm_end >= current->mm->start_brk)
70968+ str1 = "<heap>";
70969+ else
70970+ str1 = "<anonymous mapping>";
70971+ gr_log_middle_varargs(audit, msg, str1);
70972+ break;
70973+ case GR_PSACCT:
70974+ {
70975+ unsigned int wday, cday;
70976+ __u8 whr, chr;
70977+ __u8 wmin, cmin;
70978+ __u8 wsec, csec;
70979+ char cur_tty[64] = { 0 };
70980+ char parent_tty[64] = { 0 };
70981+
70982+ task = va_arg(ap, struct task_struct *);
70983+ wday = va_arg(ap, unsigned int);
70984+ cday = va_arg(ap, unsigned int);
70985+ whr = va_arg(ap, int);
70986+ chr = va_arg(ap, int);
70987+ wmin = va_arg(ap, int);
70988+ cmin = va_arg(ap, int);
70989+ wsec = va_arg(ap, int);
70990+ csec = va_arg(ap, int);
70991+ ulong1 = va_arg(ap, unsigned long);
70992+ cred = __task_cred(task);
70993+ pcred = __task_cred(task->real_parent);
70994+
70995+ 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));
70996+ }
70997+ break;
70998+ default:
70999+ gr_log_middle(audit, msg, ap);
71000+ }
71001+ va_end(ap);
71002+ // these don't need DEFAULTSECARGS printed on the end
71003+ if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
71004+ gr_log_end(audit, 0);
71005+ else
71006+ gr_log_end(audit, 1);
71007+ END_LOCKS(audit);
71008+}
71009diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
71010new file mode 100644
71011index 0000000..f536303
71012--- /dev/null
71013+++ b/grsecurity/grsec_mem.c
71014@@ -0,0 +1,40 @@
71015+#include <linux/kernel.h>
71016+#include <linux/sched.h>
71017+#include <linux/mm.h>
71018+#include <linux/mman.h>
71019+#include <linux/grinternal.h>
71020+
71021+void
71022+gr_handle_ioperm(void)
71023+{
71024+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
71025+ return;
71026+}
71027+
71028+void
71029+gr_handle_iopl(void)
71030+{
71031+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
71032+ return;
71033+}
71034+
71035+void
71036+gr_handle_mem_readwrite(u64 from, u64 to)
71037+{
71038+ gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
71039+ return;
71040+}
71041+
71042+void
71043+gr_handle_vm86(void)
71044+{
71045+ gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
71046+ return;
71047+}
71048+
71049+void
71050+gr_log_badprocpid(const char *entry)
71051+{
71052+ gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
71053+ return;
71054+}
71055diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
71056new file mode 100644
71057index 0000000..2131422
71058--- /dev/null
71059+++ b/grsecurity/grsec_mount.c
71060@@ -0,0 +1,62 @@
71061+#include <linux/kernel.h>
71062+#include <linux/sched.h>
71063+#include <linux/mount.h>
71064+#include <linux/grsecurity.h>
71065+#include <linux/grinternal.h>
71066+
71067+void
71068+gr_log_remount(const char *devname, const int retval)
71069+{
71070+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
71071+ if (grsec_enable_mount && (retval >= 0))
71072+ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
71073+#endif
71074+ return;
71075+}
71076+
71077+void
71078+gr_log_unmount(const char *devname, const int retval)
71079+{
71080+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
71081+ if (grsec_enable_mount && (retval >= 0))
71082+ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
71083+#endif
71084+ return;
71085+}
71086+
71087+void
71088+gr_log_mount(const char *from, const char *to, const int retval)
71089+{
71090+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
71091+ if (grsec_enable_mount && (retval >= 0))
71092+ gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
71093+#endif
71094+ return;
71095+}
71096+
71097+int
71098+gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
71099+{
71100+#ifdef CONFIG_GRKERNSEC_ROFS
71101+ if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
71102+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
71103+ return -EPERM;
71104+ } else
71105+ return 0;
71106+#endif
71107+ return 0;
71108+}
71109+
71110+int
71111+gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
71112+{
71113+#ifdef CONFIG_GRKERNSEC_ROFS
71114+ if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
71115+ dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
71116+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
71117+ return -EPERM;
71118+ } else
71119+ return 0;
71120+#endif
71121+ return 0;
71122+}
71123diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
71124new file mode 100644
71125index 0000000..6ee9d50
71126--- /dev/null
71127+++ b/grsecurity/grsec_pax.c
71128@@ -0,0 +1,45 @@
71129+#include <linux/kernel.h>
71130+#include <linux/sched.h>
71131+#include <linux/mm.h>
71132+#include <linux/file.h>
71133+#include <linux/grinternal.h>
71134+#include <linux/grsecurity.h>
71135+
71136+void
71137+gr_log_textrel(struct vm_area_struct * vma)
71138+{
71139+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
71140+ if (grsec_enable_log_rwxmaps)
71141+ gr_log_textrel_ulong_ulong(GR_DONT_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
71142+#endif
71143+ return;
71144+}
71145+
71146+void gr_log_ptgnustack(struct file *file)
71147+{
71148+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
71149+ if (grsec_enable_log_rwxmaps)
71150+ gr_log_rwxmap(GR_DONT_AUDIT, GR_PTGNUSTACK_MSG, file);
71151+#endif
71152+ return;
71153+}
71154+
71155+void
71156+gr_log_rwxmmap(struct file *file)
71157+{
71158+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
71159+ if (grsec_enable_log_rwxmaps)
71160+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
71161+#endif
71162+ return;
71163+}
71164+
71165+void
71166+gr_log_rwxmprotect(struct vm_area_struct *vma)
71167+{
71168+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
71169+ if (grsec_enable_log_rwxmaps)
71170+ gr_log_rwxmap_vma(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, vma);
71171+#endif
71172+ return;
71173+}
71174diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
71175new file mode 100644
71176index 0000000..f7f29aa
71177--- /dev/null
71178+++ b/grsecurity/grsec_ptrace.c
71179@@ -0,0 +1,30 @@
71180+#include <linux/kernel.h>
71181+#include <linux/sched.h>
71182+#include <linux/grinternal.h>
71183+#include <linux/security.h>
71184+
71185+void
71186+gr_audit_ptrace(struct task_struct *task)
71187+{
71188+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
71189+ if (grsec_enable_audit_ptrace)
71190+ gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
71191+#endif
71192+ return;
71193+}
71194+
71195+int
71196+gr_ptrace_readexec(struct file *file, int unsafe_flags)
71197+{
71198+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
71199+ const struct dentry *dentry = file->f_path.dentry;
71200+ const struct vfsmount *mnt = file->f_path.mnt;
71201+
71202+ if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
71203+ (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
71204+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
71205+ return -EACCES;
71206+ }
71207+#endif
71208+ return 0;
71209+}
71210diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
71211new file mode 100644
71212index 0000000..4e29cc7
71213--- /dev/null
71214+++ b/grsecurity/grsec_sig.c
71215@@ -0,0 +1,246 @@
71216+#include <linux/kernel.h>
71217+#include <linux/sched.h>
71218+#include <linux/fs.h>
71219+#include <linux/delay.h>
71220+#include <linux/grsecurity.h>
71221+#include <linux/grinternal.h>
71222+#include <linux/hardirq.h>
71223+
71224+char *signames[] = {
71225+ [SIGSEGV] = "Segmentation fault",
71226+ [SIGILL] = "Illegal instruction",
71227+ [SIGABRT] = "Abort",
71228+ [SIGBUS] = "Invalid alignment/Bus error"
71229+};
71230+
71231+void
71232+gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
71233+{
71234+#ifdef CONFIG_GRKERNSEC_SIGNAL
71235+ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
71236+ (sig == SIGABRT) || (sig == SIGBUS))) {
71237+ if (task_pid_nr(t) == task_pid_nr(current)) {
71238+ gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
71239+ } else {
71240+ gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
71241+ }
71242+ }
71243+#endif
71244+ return;
71245+}
71246+
71247+int
71248+gr_handle_signal(const struct task_struct *p, const int sig)
71249+{
71250+#ifdef CONFIG_GRKERNSEC
71251+ /* ignore the 0 signal for protected task checks */
71252+ if (task_pid_nr(current) > 1 && sig && gr_check_protected_task(p)) {
71253+ gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
71254+ return -EPERM;
71255+ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
71256+ return -EPERM;
71257+ }
71258+#endif
71259+ return 0;
71260+}
71261+
71262+#ifdef CONFIG_GRKERNSEC
71263+extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
71264+
71265+int gr_fake_force_sig(int sig, struct task_struct *t)
71266+{
71267+ unsigned long int flags;
71268+ int ret, blocked, ignored;
71269+ struct k_sigaction *action;
71270+
71271+ spin_lock_irqsave(&t->sighand->siglock, flags);
71272+ action = &t->sighand->action[sig-1];
71273+ ignored = action->sa.sa_handler == SIG_IGN;
71274+ blocked = sigismember(&t->blocked, sig);
71275+ if (blocked || ignored) {
71276+ action->sa.sa_handler = SIG_DFL;
71277+ if (blocked) {
71278+ sigdelset(&t->blocked, sig);
71279+ recalc_sigpending_and_wake(t);
71280+ }
71281+ }
71282+ if (action->sa.sa_handler == SIG_DFL)
71283+ t->signal->flags &= ~SIGNAL_UNKILLABLE;
71284+ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
71285+
71286+ spin_unlock_irqrestore(&t->sighand->siglock, flags);
71287+
71288+ return ret;
71289+}
71290+#endif
71291+
71292+#ifdef CONFIG_GRKERNSEC_BRUTE
71293+#define GR_USER_BAN_TIME (15 * 60)
71294+#define GR_DAEMON_BRUTE_TIME (30 * 60)
71295+
71296+static int __get_dumpable(unsigned long mm_flags)
71297+{
71298+ int ret;
71299+
71300+ ret = mm_flags & MMF_DUMPABLE_MASK;
71301+ return (ret >= 2) ? 2 : ret;
71302+}
71303+#endif
71304+
71305+void gr_handle_brute_attach(unsigned long mm_flags)
71306+{
71307+#ifdef CONFIG_GRKERNSEC_BRUTE
71308+ struct task_struct *p = current;
71309+ kuid_t uid = GLOBAL_ROOT_UID;
71310+ int daemon = 0;
71311+
71312+ if (!grsec_enable_brute)
71313+ return;
71314+
71315+ rcu_read_lock();
71316+ read_lock(&tasklist_lock);
71317+ read_lock(&grsec_exec_file_lock);
71318+ if (p->real_parent && gr_is_same_file(p->real_parent->exec_file, p->exec_file)) {
71319+ p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
71320+ p->real_parent->brute = 1;
71321+ daemon = 1;
71322+ } else {
71323+ const struct cred *cred = __task_cred(p), *cred2;
71324+ struct task_struct *tsk, *tsk2;
71325+
71326+ if (!__get_dumpable(mm_flags) && gr_is_global_nonroot(cred->uid)) {
71327+ struct user_struct *user;
71328+
71329+ uid = cred->uid;
71330+
71331+ /* this is put upon execution past expiration */
71332+ user = find_user(uid);
71333+ if (user == NULL)
71334+ goto unlock;
71335+ user->suid_banned = 1;
71336+ user->suid_ban_expires = get_seconds() + GR_USER_BAN_TIME;
71337+ if (user->suid_ban_expires == ~0UL)
71338+ user->suid_ban_expires--;
71339+
71340+ /* only kill other threads of the same binary, from the same user */
71341+ do_each_thread(tsk2, tsk) {
71342+ cred2 = __task_cred(tsk);
71343+ if (tsk != p && uid_eq(cred2->uid, uid) && gr_is_same_file(tsk->exec_file, p->exec_file))
71344+ gr_fake_force_sig(SIGKILL, tsk);
71345+ } while_each_thread(tsk2, tsk);
71346+ }
71347+ }
71348+unlock:
71349+ read_unlock(&grsec_exec_file_lock);
71350+ read_unlock(&tasklist_lock);
71351+ rcu_read_unlock();
71352+
71353+ if (gr_is_global_nonroot(uid))
71354+ 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);
71355+ else if (daemon)
71356+ gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
71357+
71358+#endif
71359+ return;
71360+}
71361+
71362+void gr_handle_brute_check(void)
71363+{
71364+#ifdef CONFIG_GRKERNSEC_BRUTE
71365+ struct task_struct *p = current;
71366+
71367+ if (unlikely(p->brute)) {
71368+ if (!grsec_enable_brute)
71369+ p->brute = 0;
71370+ else if (time_before(get_seconds(), p->brute_expires))
71371+ msleep(30 * 1000);
71372+ }
71373+#endif
71374+ return;
71375+}
71376+
71377+void gr_handle_kernel_exploit(void)
71378+{
71379+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
71380+ const struct cred *cred;
71381+ struct task_struct *tsk, *tsk2;
71382+ struct user_struct *user;
71383+ kuid_t uid;
71384+
71385+ if (in_irq() || in_serving_softirq() || in_nmi())
71386+ panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
71387+
71388+ uid = current_uid();
71389+
71390+ if (gr_is_global_root(uid))
71391+ panic("grsec: halting the system due to suspicious kernel crash caused by root");
71392+ else {
71393+ /* kill all the processes of this user, hold a reference
71394+ to their creds struct, and prevent them from creating
71395+ another process until system reset
71396+ */
71397+ printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
71398+ GR_GLOBAL_UID(uid));
71399+ /* we intentionally leak this ref */
71400+ user = get_uid(current->cred->user);
71401+ if (user)
71402+ user->kernel_banned = 1;
71403+
71404+ /* kill all processes of this user */
71405+ read_lock(&tasklist_lock);
71406+ do_each_thread(tsk2, tsk) {
71407+ cred = __task_cred(tsk);
71408+ if (uid_eq(cred->uid, uid))
71409+ gr_fake_force_sig(SIGKILL, tsk);
71410+ } while_each_thread(tsk2, tsk);
71411+ read_unlock(&tasklist_lock);
71412+ }
71413+#endif
71414+}
71415+
71416+#ifdef CONFIG_GRKERNSEC_BRUTE
71417+static bool suid_ban_expired(struct user_struct *user)
71418+{
71419+ if (user->suid_ban_expires != ~0UL && time_after_eq(get_seconds(), user->suid_ban_expires)) {
71420+ user->suid_banned = 0;
71421+ user->suid_ban_expires = 0;
71422+ free_uid(user);
71423+ return true;
71424+ }
71425+
71426+ return false;
71427+}
71428+#endif
71429+
71430+int gr_process_kernel_exec_ban(void)
71431+{
71432+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
71433+ if (unlikely(current->cred->user->kernel_banned))
71434+ return -EPERM;
71435+#endif
71436+ return 0;
71437+}
71438+
71439+int gr_process_kernel_setuid_ban(struct user_struct *user)
71440+{
71441+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
71442+ if (unlikely(user->kernel_banned))
71443+ gr_fake_force_sig(SIGKILL, current);
71444+#endif
71445+ return 0;
71446+}
71447+
71448+int gr_process_suid_exec_ban(const struct linux_binprm *bprm)
71449+{
71450+#ifdef CONFIG_GRKERNSEC_BRUTE
71451+ struct user_struct *user = current->cred->user;
71452+ if (unlikely(user->suid_banned)) {
71453+ if (suid_ban_expired(user))
71454+ return 0;
71455+ /* disallow execution of suid binaries only */
71456+ else if (!uid_eq(bprm->cred->euid, current->cred->uid))
71457+ return -EPERM;
71458+ }
71459+#endif
71460+ return 0;
71461+}
71462diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
71463new file mode 100644
71464index 0000000..4030d57
71465--- /dev/null
71466+++ b/grsecurity/grsec_sock.c
71467@@ -0,0 +1,244 @@
71468+#include <linux/kernel.h>
71469+#include <linux/module.h>
71470+#include <linux/sched.h>
71471+#include <linux/file.h>
71472+#include <linux/net.h>
71473+#include <linux/in.h>
71474+#include <linux/ip.h>
71475+#include <net/sock.h>
71476+#include <net/inet_sock.h>
71477+#include <linux/grsecurity.h>
71478+#include <linux/grinternal.h>
71479+#include <linux/gracl.h>
71480+
71481+extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
71482+extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
71483+
71484+EXPORT_SYMBOL(gr_search_udp_recvmsg);
71485+EXPORT_SYMBOL(gr_search_udp_sendmsg);
71486+
71487+#ifdef CONFIG_UNIX_MODULE
71488+EXPORT_SYMBOL(gr_acl_handle_unix);
71489+EXPORT_SYMBOL(gr_acl_handle_mknod);
71490+EXPORT_SYMBOL(gr_handle_chroot_unix);
71491+EXPORT_SYMBOL(gr_handle_create);
71492+#endif
71493+
71494+#ifdef CONFIG_GRKERNSEC
71495+#define gr_conn_table_size 32749
71496+struct conn_table_entry {
71497+ struct conn_table_entry *next;
71498+ struct signal_struct *sig;
71499+};
71500+
71501+struct conn_table_entry *gr_conn_table[gr_conn_table_size];
71502+DEFINE_SPINLOCK(gr_conn_table_lock);
71503+
71504+extern const char * gr_socktype_to_name(unsigned char type);
71505+extern const char * gr_proto_to_name(unsigned char proto);
71506+extern const char * gr_sockfamily_to_name(unsigned char family);
71507+
71508+static __inline__ int
71509+conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
71510+{
71511+ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
71512+}
71513+
71514+static __inline__ int
71515+conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
71516+ __u16 sport, __u16 dport)
71517+{
71518+ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
71519+ sig->gr_sport == sport && sig->gr_dport == dport))
71520+ return 1;
71521+ else
71522+ return 0;
71523+}
71524+
71525+static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
71526+{
71527+ struct conn_table_entry **match;
71528+ unsigned int index;
71529+
71530+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
71531+ sig->gr_sport, sig->gr_dport,
71532+ gr_conn_table_size);
71533+
71534+ newent->sig = sig;
71535+
71536+ match = &gr_conn_table[index];
71537+ newent->next = *match;
71538+ *match = newent;
71539+
71540+ return;
71541+}
71542+
71543+static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
71544+{
71545+ struct conn_table_entry *match, *last = NULL;
71546+ unsigned int index;
71547+
71548+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
71549+ sig->gr_sport, sig->gr_dport,
71550+ gr_conn_table_size);
71551+
71552+ match = gr_conn_table[index];
71553+ while (match && !conn_match(match->sig,
71554+ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
71555+ sig->gr_dport)) {
71556+ last = match;
71557+ match = match->next;
71558+ }
71559+
71560+ if (match) {
71561+ if (last)
71562+ last->next = match->next;
71563+ else
71564+ gr_conn_table[index] = NULL;
71565+ kfree(match);
71566+ }
71567+
71568+ return;
71569+}
71570+
71571+static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
71572+ __u16 sport, __u16 dport)
71573+{
71574+ struct conn_table_entry *match;
71575+ unsigned int index;
71576+
71577+ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
71578+
71579+ match = gr_conn_table[index];
71580+ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
71581+ match = match->next;
71582+
71583+ if (match)
71584+ return match->sig;
71585+ else
71586+ return NULL;
71587+}
71588+
71589+#endif
71590+
71591+void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
71592+{
71593+#ifdef CONFIG_GRKERNSEC
71594+ struct signal_struct *sig = task->signal;
71595+ struct conn_table_entry *newent;
71596+
71597+ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
71598+ if (newent == NULL)
71599+ return;
71600+ /* no bh lock needed since we are called with bh disabled */
71601+ spin_lock(&gr_conn_table_lock);
71602+ gr_del_task_from_ip_table_nolock(sig);
71603+ sig->gr_saddr = inet->inet_rcv_saddr;
71604+ sig->gr_daddr = inet->inet_daddr;
71605+ sig->gr_sport = inet->inet_sport;
71606+ sig->gr_dport = inet->inet_dport;
71607+ gr_add_to_task_ip_table_nolock(sig, newent);
71608+ spin_unlock(&gr_conn_table_lock);
71609+#endif
71610+ return;
71611+}
71612+
71613+void gr_del_task_from_ip_table(struct task_struct *task)
71614+{
71615+#ifdef CONFIG_GRKERNSEC
71616+ spin_lock_bh(&gr_conn_table_lock);
71617+ gr_del_task_from_ip_table_nolock(task->signal);
71618+ spin_unlock_bh(&gr_conn_table_lock);
71619+#endif
71620+ return;
71621+}
71622+
71623+void
71624+gr_attach_curr_ip(const struct sock *sk)
71625+{
71626+#ifdef CONFIG_GRKERNSEC
71627+ struct signal_struct *p, *set;
71628+ const struct inet_sock *inet = inet_sk(sk);
71629+
71630+ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
71631+ return;
71632+
71633+ set = current->signal;
71634+
71635+ spin_lock_bh(&gr_conn_table_lock);
71636+ p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
71637+ inet->inet_dport, inet->inet_sport);
71638+ if (unlikely(p != NULL)) {
71639+ set->curr_ip = p->curr_ip;
71640+ set->used_accept = 1;
71641+ gr_del_task_from_ip_table_nolock(p);
71642+ spin_unlock_bh(&gr_conn_table_lock);
71643+ return;
71644+ }
71645+ spin_unlock_bh(&gr_conn_table_lock);
71646+
71647+ set->curr_ip = inet->inet_daddr;
71648+ set->used_accept = 1;
71649+#endif
71650+ return;
71651+}
71652+
71653+int
71654+gr_handle_sock_all(const int family, const int type, const int protocol)
71655+{
71656+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
71657+ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
71658+ (family != AF_UNIX)) {
71659+ if (family == AF_INET)
71660+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
71661+ else
71662+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
71663+ return -EACCES;
71664+ }
71665+#endif
71666+ return 0;
71667+}
71668+
71669+int
71670+gr_handle_sock_server(const struct sockaddr *sck)
71671+{
71672+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
71673+ if (grsec_enable_socket_server &&
71674+ in_group_p(grsec_socket_server_gid) &&
71675+ sck && (sck->sa_family != AF_UNIX) &&
71676+ (sck->sa_family != AF_LOCAL)) {
71677+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
71678+ return -EACCES;
71679+ }
71680+#endif
71681+ return 0;
71682+}
71683+
71684+int
71685+gr_handle_sock_server_other(const struct sock *sck)
71686+{
71687+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
71688+ if (grsec_enable_socket_server &&
71689+ in_group_p(grsec_socket_server_gid) &&
71690+ sck && (sck->sk_family != AF_UNIX) &&
71691+ (sck->sk_family != AF_LOCAL)) {
71692+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
71693+ return -EACCES;
71694+ }
71695+#endif
71696+ return 0;
71697+}
71698+
71699+int
71700+gr_handle_sock_client(const struct sockaddr *sck)
71701+{
71702+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
71703+ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
71704+ sck && (sck->sa_family != AF_UNIX) &&
71705+ (sck->sa_family != AF_LOCAL)) {
71706+ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
71707+ return -EACCES;
71708+ }
71709+#endif
71710+ return 0;
71711+}
71712diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
71713new file mode 100644
71714index 0000000..8159888
71715--- /dev/null
71716+++ b/grsecurity/grsec_sysctl.c
71717@@ -0,0 +1,479 @@
71718+#include <linux/kernel.h>
71719+#include <linux/sched.h>
71720+#include <linux/sysctl.h>
71721+#include <linux/grsecurity.h>
71722+#include <linux/grinternal.h>
71723+
71724+int
71725+gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
71726+{
71727+#ifdef CONFIG_GRKERNSEC_SYSCTL
71728+ if (dirname == NULL || name == NULL)
71729+ return 0;
71730+ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
71731+ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
71732+ return -EACCES;
71733+ }
71734+#endif
71735+ return 0;
71736+}
71737+
71738+#if defined(CONFIG_GRKERNSEC_ROFS) || defined(CONFIG_GRKERNSEC_DENYUSB)
71739+static int __maybe_unused __read_only one = 1;
71740+#endif
71741+
71742+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS) || \
71743+ defined(CONFIG_GRKERNSEC_DENYUSB)
71744+struct ctl_table grsecurity_table[] = {
71745+#ifdef CONFIG_GRKERNSEC_SYSCTL
71746+#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
71747+#ifdef CONFIG_GRKERNSEC_IO
71748+ {
71749+ .procname = "disable_priv_io",
71750+ .data = &grsec_disable_privio,
71751+ .maxlen = sizeof(int),
71752+ .mode = 0600,
71753+ .proc_handler = &proc_dointvec,
71754+ },
71755+#endif
71756+#endif
71757+#ifdef CONFIG_GRKERNSEC_LINK
71758+ {
71759+ .procname = "linking_restrictions",
71760+ .data = &grsec_enable_link,
71761+ .maxlen = sizeof(int),
71762+ .mode = 0600,
71763+ .proc_handler = &proc_dointvec,
71764+ },
71765+#endif
71766+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
71767+ {
71768+ .procname = "enforce_symlinksifowner",
71769+ .data = &grsec_enable_symlinkown,
71770+ .maxlen = sizeof(int),
71771+ .mode = 0600,
71772+ .proc_handler = &proc_dointvec,
71773+ },
71774+ {
71775+ .procname = "symlinkown_gid",
71776+ .data = &grsec_symlinkown_gid,
71777+ .maxlen = sizeof(int),
71778+ .mode = 0600,
71779+ .proc_handler = &proc_dointvec,
71780+ },
71781+#endif
71782+#ifdef CONFIG_GRKERNSEC_BRUTE
71783+ {
71784+ .procname = "deter_bruteforce",
71785+ .data = &grsec_enable_brute,
71786+ .maxlen = sizeof(int),
71787+ .mode = 0600,
71788+ .proc_handler = &proc_dointvec,
71789+ },
71790+#endif
71791+#ifdef CONFIG_GRKERNSEC_FIFO
71792+ {
71793+ .procname = "fifo_restrictions",
71794+ .data = &grsec_enable_fifo,
71795+ .maxlen = sizeof(int),
71796+ .mode = 0600,
71797+ .proc_handler = &proc_dointvec,
71798+ },
71799+#endif
71800+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
71801+ {
71802+ .procname = "ptrace_readexec",
71803+ .data = &grsec_enable_ptrace_readexec,
71804+ .maxlen = sizeof(int),
71805+ .mode = 0600,
71806+ .proc_handler = &proc_dointvec,
71807+ },
71808+#endif
71809+#ifdef CONFIG_GRKERNSEC_SETXID
71810+ {
71811+ .procname = "consistent_setxid",
71812+ .data = &grsec_enable_setxid,
71813+ .maxlen = sizeof(int),
71814+ .mode = 0600,
71815+ .proc_handler = &proc_dointvec,
71816+ },
71817+#endif
71818+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
71819+ {
71820+ .procname = "ip_blackhole",
71821+ .data = &grsec_enable_blackhole,
71822+ .maxlen = sizeof(int),
71823+ .mode = 0600,
71824+ .proc_handler = &proc_dointvec,
71825+ },
71826+ {
71827+ .procname = "lastack_retries",
71828+ .data = &grsec_lastack_retries,
71829+ .maxlen = sizeof(int),
71830+ .mode = 0600,
71831+ .proc_handler = &proc_dointvec,
71832+ },
71833+#endif
71834+#ifdef CONFIG_GRKERNSEC_EXECLOG
71835+ {
71836+ .procname = "exec_logging",
71837+ .data = &grsec_enable_execlog,
71838+ .maxlen = sizeof(int),
71839+ .mode = 0600,
71840+ .proc_handler = &proc_dointvec,
71841+ },
71842+#endif
71843+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
71844+ {
71845+ .procname = "rwxmap_logging",
71846+ .data = &grsec_enable_log_rwxmaps,
71847+ .maxlen = sizeof(int),
71848+ .mode = 0600,
71849+ .proc_handler = &proc_dointvec,
71850+ },
71851+#endif
71852+#ifdef CONFIG_GRKERNSEC_SIGNAL
71853+ {
71854+ .procname = "signal_logging",
71855+ .data = &grsec_enable_signal,
71856+ .maxlen = sizeof(int),
71857+ .mode = 0600,
71858+ .proc_handler = &proc_dointvec,
71859+ },
71860+#endif
71861+#ifdef CONFIG_GRKERNSEC_FORKFAIL
71862+ {
71863+ .procname = "forkfail_logging",
71864+ .data = &grsec_enable_forkfail,
71865+ .maxlen = sizeof(int),
71866+ .mode = 0600,
71867+ .proc_handler = &proc_dointvec,
71868+ },
71869+#endif
71870+#ifdef CONFIG_GRKERNSEC_TIME
71871+ {
71872+ .procname = "timechange_logging",
71873+ .data = &grsec_enable_time,
71874+ .maxlen = sizeof(int),
71875+ .mode = 0600,
71876+ .proc_handler = &proc_dointvec,
71877+ },
71878+#endif
71879+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
71880+ {
71881+ .procname = "chroot_deny_shmat",
71882+ .data = &grsec_enable_chroot_shmat,
71883+ .maxlen = sizeof(int),
71884+ .mode = 0600,
71885+ .proc_handler = &proc_dointvec,
71886+ },
71887+#endif
71888+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
71889+ {
71890+ .procname = "chroot_deny_unix",
71891+ .data = &grsec_enable_chroot_unix,
71892+ .maxlen = sizeof(int),
71893+ .mode = 0600,
71894+ .proc_handler = &proc_dointvec,
71895+ },
71896+#endif
71897+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
71898+ {
71899+ .procname = "chroot_deny_mount",
71900+ .data = &grsec_enable_chroot_mount,
71901+ .maxlen = sizeof(int),
71902+ .mode = 0600,
71903+ .proc_handler = &proc_dointvec,
71904+ },
71905+#endif
71906+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
71907+ {
71908+ .procname = "chroot_deny_fchdir",
71909+ .data = &grsec_enable_chroot_fchdir,
71910+ .maxlen = sizeof(int),
71911+ .mode = 0600,
71912+ .proc_handler = &proc_dointvec,
71913+ },
71914+#endif
71915+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
71916+ {
71917+ .procname = "chroot_deny_chroot",
71918+ .data = &grsec_enable_chroot_double,
71919+ .maxlen = sizeof(int),
71920+ .mode = 0600,
71921+ .proc_handler = &proc_dointvec,
71922+ },
71923+#endif
71924+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
71925+ {
71926+ .procname = "chroot_deny_pivot",
71927+ .data = &grsec_enable_chroot_pivot,
71928+ .maxlen = sizeof(int),
71929+ .mode = 0600,
71930+ .proc_handler = &proc_dointvec,
71931+ },
71932+#endif
71933+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
71934+ {
71935+ .procname = "chroot_enforce_chdir",
71936+ .data = &grsec_enable_chroot_chdir,
71937+ .maxlen = sizeof(int),
71938+ .mode = 0600,
71939+ .proc_handler = &proc_dointvec,
71940+ },
71941+#endif
71942+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
71943+ {
71944+ .procname = "chroot_deny_chmod",
71945+ .data = &grsec_enable_chroot_chmod,
71946+ .maxlen = sizeof(int),
71947+ .mode = 0600,
71948+ .proc_handler = &proc_dointvec,
71949+ },
71950+#endif
71951+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
71952+ {
71953+ .procname = "chroot_deny_mknod",
71954+ .data = &grsec_enable_chroot_mknod,
71955+ .maxlen = sizeof(int),
71956+ .mode = 0600,
71957+ .proc_handler = &proc_dointvec,
71958+ },
71959+#endif
71960+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
71961+ {
71962+ .procname = "chroot_restrict_nice",
71963+ .data = &grsec_enable_chroot_nice,
71964+ .maxlen = sizeof(int),
71965+ .mode = 0600,
71966+ .proc_handler = &proc_dointvec,
71967+ },
71968+#endif
71969+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
71970+ {
71971+ .procname = "chroot_execlog",
71972+ .data = &grsec_enable_chroot_execlog,
71973+ .maxlen = sizeof(int),
71974+ .mode = 0600,
71975+ .proc_handler = &proc_dointvec,
71976+ },
71977+#endif
71978+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
71979+ {
71980+ .procname = "chroot_caps",
71981+ .data = &grsec_enable_chroot_caps,
71982+ .maxlen = sizeof(int),
71983+ .mode = 0600,
71984+ .proc_handler = &proc_dointvec,
71985+ },
71986+#endif
71987+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
71988+ {
71989+ .procname = "chroot_deny_sysctl",
71990+ .data = &grsec_enable_chroot_sysctl,
71991+ .maxlen = sizeof(int),
71992+ .mode = 0600,
71993+ .proc_handler = &proc_dointvec,
71994+ },
71995+#endif
71996+#ifdef CONFIG_GRKERNSEC_TPE
71997+ {
71998+ .procname = "tpe",
71999+ .data = &grsec_enable_tpe,
72000+ .maxlen = sizeof(int),
72001+ .mode = 0600,
72002+ .proc_handler = &proc_dointvec,
72003+ },
72004+ {
72005+ .procname = "tpe_gid",
72006+ .data = &grsec_tpe_gid,
72007+ .maxlen = sizeof(int),
72008+ .mode = 0600,
72009+ .proc_handler = &proc_dointvec,
72010+ },
72011+#endif
72012+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
72013+ {
72014+ .procname = "tpe_invert",
72015+ .data = &grsec_enable_tpe_invert,
72016+ .maxlen = sizeof(int),
72017+ .mode = 0600,
72018+ .proc_handler = &proc_dointvec,
72019+ },
72020+#endif
72021+#ifdef CONFIG_GRKERNSEC_TPE_ALL
72022+ {
72023+ .procname = "tpe_restrict_all",
72024+ .data = &grsec_enable_tpe_all,
72025+ .maxlen = sizeof(int),
72026+ .mode = 0600,
72027+ .proc_handler = &proc_dointvec,
72028+ },
72029+#endif
72030+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
72031+ {
72032+ .procname = "socket_all",
72033+ .data = &grsec_enable_socket_all,
72034+ .maxlen = sizeof(int),
72035+ .mode = 0600,
72036+ .proc_handler = &proc_dointvec,
72037+ },
72038+ {
72039+ .procname = "socket_all_gid",
72040+ .data = &grsec_socket_all_gid,
72041+ .maxlen = sizeof(int),
72042+ .mode = 0600,
72043+ .proc_handler = &proc_dointvec,
72044+ },
72045+#endif
72046+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
72047+ {
72048+ .procname = "socket_client",
72049+ .data = &grsec_enable_socket_client,
72050+ .maxlen = sizeof(int),
72051+ .mode = 0600,
72052+ .proc_handler = &proc_dointvec,
72053+ },
72054+ {
72055+ .procname = "socket_client_gid",
72056+ .data = &grsec_socket_client_gid,
72057+ .maxlen = sizeof(int),
72058+ .mode = 0600,
72059+ .proc_handler = &proc_dointvec,
72060+ },
72061+#endif
72062+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
72063+ {
72064+ .procname = "socket_server",
72065+ .data = &grsec_enable_socket_server,
72066+ .maxlen = sizeof(int),
72067+ .mode = 0600,
72068+ .proc_handler = &proc_dointvec,
72069+ },
72070+ {
72071+ .procname = "socket_server_gid",
72072+ .data = &grsec_socket_server_gid,
72073+ .maxlen = sizeof(int),
72074+ .mode = 0600,
72075+ .proc_handler = &proc_dointvec,
72076+ },
72077+#endif
72078+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
72079+ {
72080+ .procname = "audit_group",
72081+ .data = &grsec_enable_group,
72082+ .maxlen = sizeof(int),
72083+ .mode = 0600,
72084+ .proc_handler = &proc_dointvec,
72085+ },
72086+ {
72087+ .procname = "audit_gid",
72088+ .data = &grsec_audit_gid,
72089+ .maxlen = sizeof(int),
72090+ .mode = 0600,
72091+ .proc_handler = &proc_dointvec,
72092+ },
72093+#endif
72094+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
72095+ {
72096+ .procname = "audit_chdir",
72097+ .data = &grsec_enable_chdir,
72098+ .maxlen = sizeof(int),
72099+ .mode = 0600,
72100+ .proc_handler = &proc_dointvec,
72101+ },
72102+#endif
72103+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
72104+ {
72105+ .procname = "audit_mount",
72106+ .data = &grsec_enable_mount,
72107+ .maxlen = sizeof(int),
72108+ .mode = 0600,
72109+ .proc_handler = &proc_dointvec,
72110+ },
72111+#endif
72112+#ifdef CONFIG_GRKERNSEC_DMESG
72113+ {
72114+ .procname = "dmesg",
72115+ .data = &grsec_enable_dmesg,
72116+ .maxlen = sizeof(int),
72117+ .mode = 0600,
72118+ .proc_handler = &proc_dointvec,
72119+ },
72120+#endif
72121+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
72122+ {
72123+ .procname = "chroot_findtask",
72124+ .data = &grsec_enable_chroot_findtask,
72125+ .maxlen = sizeof(int),
72126+ .mode = 0600,
72127+ .proc_handler = &proc_dointvec,
72128+ },
72129+#endif
72130+#ifdef CONFIG_GRKERNSEC_RESLOG
72131+ {
72132+ .procname = "resource_logging",
72133+ .data = &grsec_resource_logging,
72134+ .maxlen = sizeof(int),
72135+ .mode = 0600,
72136+ .proc_handler = &proc_dointvec,
72137+ },
72138+#endif
72139+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
72140+ {
72141+ .procname = "audit_ptrace",
72142+ .data = &grsec_enable_audit_ptrace,
72143+ .maxlen = sizeof(int),
72144+ .mode = 0600,
72145+ .proc_handler = &proc_dointvec,
72146+ },
72147+#endif
72148+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
72149+ {
72150+ .procname = "harden_ptrace",
72151+ .data = &grsec_enable_harden_ptrace,
72152+ .maxlen = sizeof(int),
72153+ .mode = 0600,
72154+ .proc_handler = &proc_dointvec,
72155+ },
72156+#endif
72157+#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
72158+ {
72159+ .procname = "harden_ipc",
72160+ .data = &grsec_enable_harden_ipc,
72161+ .maxlen = sizeof(int),
72162+ .mode = 0600,
72163+ .proc_handler = &proc_dointvec,
72164+ },
72165+#endif
72166+ {
72167+ .procname = "grsec_lock",
72168+ .data = &grsec_lock,
72169+ .maxlen = sizeof(int),
72170+ .mode = 0600,
72171+ .proc_handler = &proc_dointvec,
72172+ },
72173+#endif
72174+#ifdef CONFIG_GRKERNSEC_ROFS
72175+ {
72176+ .procname = "romount_protect",
72177+ .data = &grsec_enable_rofs,
72178+ .maxlen = sizeof(int),
72179+ .mode = 0600,
72180+ .proc_handler = &proc_dointvec_minmax,
72181+ .extra1 = &one,
72182+ .extra2 = &one,
72183+ },
72184+#endif
72185+#if defined(CONFIG_GRKERNSEC_DENYUSB) && !defined(CONFIG_GRKERNSEC_DENYUSB_FORCE)
72186+ {
72187+ .procname = "deny_new_usb",
72188+ .data = &grsec_deny_new_usb,
72189+ .maxlen = sizeof(int),
72190+ .mode = 0600,
72191+ .proc_handler = &proc_dointvec,
72192+ },
72193+#endif
72194+ { }
72195+};
72196+#endif
72197diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
72198new file mode 100644
72199index 0000000..0dc13c3
72200--- /dev/null
72201+++ b/grsecurity/grsec_time.c
72202@@ -0,0 +1,16 @@
72203+#include <linux/kernel.h>
72204+#include <linux/sched.h>
72205+#include <linux/grinternal.h>
72206+#include <linux/module.h>
72207+
72208+void
72209+gr_log_timechange(void)
72210+{
72211+#ifdef CONFIG_GRKERNSEC_TIME
72212+ if (grsec_enable_time)
72213+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
72214+#endif
72215+ return;
72216+}
72217+
72218+EXPORT_SYMBOL(gr_log_timechange);
72219diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
72220new file mode 100644
72221index 0000000..ee57dcf
72222--- /dev/null
72223+++ b/grsecurity/grsec_tpe.c
72224@@ -0,0 +1,73 @@
72225+#include <linux/kernel.h>
72226+#include <linux/sched.h>
72227+#include <linux/file.h>
72228+#include <linux/fs.h>
72229+#include <linux/grinternal.h>
72230+
72231+extern int gr_acl_tpe_check(void);
72232+
72233+int
72234+gr_tpe_allow(const struct file *file)
72235+{
72236+#ifdef CONFIG_GRKERNSEC
72237+ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
72238+ const struct cred *cred = current_cred();
72239+ char *msg = NULL;
72240+ char *msg2 = NULL;
72241+
72242+ // never restrict root
72243+ if (gr_is_global_root(cred->uid))
72244+ return 1;
72245+
72246+ if (grsec_enable_tpe) {
72247+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
72248+ if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
72249+ msg = "not being in trusted group";
72250+ else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
72251+ msg = "being in untrusted group";
72252+#else
72253+ if (in_group_p(grsec_tpe_gid))
72254+ msg = "being in untrusted group";
72255+#endif
72256+ }
72257+ if (!msg && gr_acl_tpe_check())
72258+ msg = "being in untrusted role";
72259+
72260+ // not in any affected group/role
72261+ if (!msg)
72262+ goto next_check;
72263+
72264+ if (gr_is_global_nonroot(inode->i_uid))
72265+ msg2 = "file in non-root-owned directory";
72266+ else if (inode->i_mode & S_IWOTH)
72267+ msg2 = "file in world-writable directory";
72268+ else if (inode->i_mode & S_IWGRP)
72269+ msg2 = "file in group-writable directory";
72270+
72271+ if (msg && msg2) {
72272+ char fullmsg[70] = {0};
72273+ snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
72274+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
72275+ return 0;
72276+ }
72277+ msg = NULL;
72278+next_check:
72279+#ifdef CONFIG_GRKERNSEC_TPE_ALL
72280+ if (!grsec_enable_tpe || !grsec_enable_tpe_all)
72281+ return 1;
72282+
72283+ if (gr_is_global_nonroot(inode->i_uid) && !uid_eq(inode->i_uid, cred->uid))
72284+ msg = "directory not owned by user";
72285+ else if (inode->i_mode & S_IWOTH)
72286+ msg = "file in world-writable directory";
72287+ else if (inode->i_mode & S_IWGRP)
72288+ msg = "file in group-writable directory";
72289+
72290+ if (msg) {
72291+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
72292+ return 0;
72293+ }
72294+#endif
72295+#endif
72296+ return 1;
72297+}
72298diff --git a/grsecurity/grsec_usb.c b/grsecurity/grsec_usb.c
72299new file mode 100644
72300index 0000000..ae02d8e
72301--- /dev/null
72302+++ b/grsecurity/grsec_usb.c
72303@@ -0,0 +1,15 @@
72304+#include <linux/kernel.h>
72305+#include <linux/grinternal.h>
72306+#include <linux/module.h>
72307+
72308+int gr_handle_new_usb(void)
72309+{
72310+#ifdef CONFIG_GRKERNSEC_DENYUSB
72311+ if (grsec_deny_new_usb) {
72312+ printk(KERN_ALERT "grsec: denied insert of new USB device\n");
72313+ return 1;
72314+ }
72315+#endif
72316+ return 0;
72317+}
72318+EXPORT_SYMBOL_GPL(gr_handle_new_usb);
72319diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
72320new file mode 100644
72321index 0000000..9f7b1ac
72322--- /dev/null
72323+++ b/grsecurity/grsum.c
72324@@ -0,0 +1,61 @@
72325+#include <linux/err.h>
72326+#include <linux/kernel.h>
72327+#include <linux/sched.h>
72328+#include <linux/mm.h>
72329+#include <linux/scatterlist.h>
72330+#include <linux/crypto.h>
72331+#include <linux/gracl.h>
72332+
72333+
72334+#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
72335+#error "crypto and sha256 must be built into the kernel"
72336+#endif
72337+
72338+int
72339+chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
72340+{
72341+ char *p;
72342+ struct crypto_hash *tfm;
72343+ struct hash_desc desc;
72344+ struct scatterlist sg;
72345+ unsigned char temp_sum[GR_SHA_LEN];
72346+ volatile int retval = 0;
72347+ volatile int dummy = 0;
72348+ unsigned int i;
72349+
72350+ sg_init_table(&sg, 1);
72351+
72352+ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
72353+ if (IS_ERR(tfm)) {
72354+ /* should never happen, since sha256 should be built in */
72355+ return 1;
72356+ }
72357+
72358+ desc.tfm = tfm;
72359+ desc.flags = 0;
72360+
72361+ crypto_hash_init(&desc);
72362+
72363+ p = salt;
72364+ sg_set_buf(&sg, p, GR_SALT_LEN);
72365+ crypto_hash_update(&desc, &sg, sg.length);
72366+
72367+ p = entry->pw;
72368+ sg_set_buf(&sg, p, strlen(p));
72369+
72370+ crypto_hash_update(&desc, &sg, sg.length);
72371+
72372+ crypto_hash_final(&desc, temp_sum);
72373+
72374+ memset(entry->pw, 0, GR_PW_LEN);
72375+
72376+ for (i = 0; i < GR_SHA_LEN; i++)
72377+ if (sum[i] != temp_sum[i])
72378+ retval = 1;
72379+ else
72380+ dummy = 1; // waste a cycle
72381+
72382+ crypto_free_hash(tfm);
72383+
72384+ return retval;
72385+}
72386diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
72387index 77ff547..181834f 100644
72388--- a/include/asm-generic/4level-fixup.h
72389+++ b/include/asm-generic/4level-fixup.h
72390@@ -13,8 +13,10 @@
72391 #define pmd_alloc(mm, pud, address) \
72392 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
72393 NULL: pmd_offset(pud, address))
72394+#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
72395
72396 #define pud_alloc(mm, pgd, address) (pgd)
72397+#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
72398 #define pud_offset(pgd, start) (pgd)
72399 #define pud_none(pud) 0
72400 #define pud_bad(pud) 0
72401diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
72402index b7babf0..04ad282 100644
72403--- a/include/asm-generic/atomic-long.h
72404+++ b/include/asm-generic/atomic-long.h
72405@@ -22,6 +22,12 @@
72406
72407 typedef atomic64_t atomic_long_t;
72408
72409+#ifdef CONFIG_PAX_REFCOUNT
72410+typedef atomic64_unchecked_t atomic_long_unchecked_t;
72411+#else
72412+typedef atomic64_t atomic_long_unchecked_t;
72413+#endif
72414+
72415 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
72416
72417 static inline long atomic_long_read(atomic_long_t *l)
72418@@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
72419 return (long)atomic64_read(v);
72420 }
72421
72422+#ifdef CONFIG_PAX_REFCOUNT
72423+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
72424+{
72425+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
72426+
72427+ return (long)atomic64_read_unchecked(v);
72428+}
72429+#endif
72430+
72431 static inline void atomic_long_set(atomic_long_t *l, long i)
72432 {
72433 atomic64_t *v = (atomic64_t *)l;
72434@@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
72435 atomic64_set(v, i);
72436 }
72437
72438+#ifdef CONFIG_PAX_REFCOUNT
72439+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
72440+{
72441+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
72442+
72443+ atomic64_set_unchecked(v, i);
72444+}
72445+#endif
72446+
72447 static inline void atomic_long_inc(atomic_long_t *l)
72448 {
72449 atomic64_t *v = (atomic64_t *)l;
72450@@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
72451 atomic64_inc(v);
72452 }
72453
72454+#ifdef CONFIG_PAX_REFCOUNT
72455+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
72456+{
72457+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
72458+
72459+ atomic64_inc_unchecked(v);
72460+}
72461+#endif
72462+
72463 static inline void atomic_long_dec(atomic_long_t *l)
72464 {
72465 atomic64_t *v = (atomic64_t *)l;
72466@@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
72467 atomic64_dec(v);
72468 }
72469
72470+#ifdef CONFIG_PAX_REFCOUNT
72471+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
72472+{
72473+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
72474+
72475+ atomic64_dec_unchecked(v);
72476+}
72477+#endif
72478+
72479 static inline void atomic_long_add(long i, atomic_long_t *l)
72480 {
72481 atomic64_t *v = (atomic64_t *)l;
72482@@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
72483 atomic64_add(i, v);
72484 }
72485
72486+#ifdef CONFIG_PAX_REFCOUNT
72487+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
72488+{
72489+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
72490+
72491+ atomic64_add_unchecked(i, v);
72492+}
72493+#endif
72494+
72495 static inline void atomic_long_sub(long i, atomic_long_t *l)
72496 {
72497 atomic64_t *v = (atomic64_t *)l;
72498@@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
72499 atomic64_sub(i, v);
72500 }
72501
72502+#ifdef CONFIG_PAX_REFCOUNT
72503+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
72504+{
72505+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
72506+
72507+ atomic64_sub_unchecked(i, v);
72508+}
72509+#endif
72510+
72511 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
72512 {
72513 atomic64_t *v = (atomic64_t *)l;
72514@@ -101,6 +161,15 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
72515 return (long)atomic64_add_return(i, v);
72516 }
72517
72518+#ifdef CONFIG_PAX_REFCOUNT
72519+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
72520+{
72521+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
72522+
72523+ return (long)atomic64_add_return_unchecked(i, v);
72524+}
72525+#endif
72526+
72527 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
72528 {
72529 atomic64_t *v = (atomic64_t *)l;
72530@@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
72531 return (long)atomic64_inc_return(v);
72532 }
72533
72534+#ifdef CONFIG_PAX_REFCOUNT
72535+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
72536+{
72537+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
72538+
72539+ return (long)atomic64_inc_return_unchecked(v);
72540+}
72541+#endif
72542+
72543 static inline long atomic_long_dec_return(atomic_long_t *l)
72544 {
72545 atomic64_t *v = (atomic64_t *)l;
72546@@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
72547
72548 typedef atomic_t atomic_long_t;
72549
72550+#ifdef CONFIG_PAX_REFCOUNT
72551+typedef atomic_unchecked_t atomic_long_unchecked_t;
72552+#else
72553+typedef atomic_t atomic_long_unchecked_t;
72554+#endif
72555+
72556 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
72557 static inline long atomic_long_read(atomic_long_t *l)
72558 {
72559@@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
72560 return (long)atomic_read(v);
72561 }
72562
72563+#ifdef CONFIG_PAX_REFCOUNT
72564+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
72565+{
72566+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
72567+
72568+ return (long)atomic_read_unchecked(v);
72569+}
72570+#endif
72571+
72572 static inline void atomic_long_set(atomic_long_t *l, long i)
72573 {
72574 atomic_t *v = (atomic_t *)l;
72575@@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
72576 atomic_set(v, i);
72577 }
72578
72579+#ifdef CONFIG_PAX_REFCOUNT
72580+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
72581+{
72582+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
72583+
72584+ atomic_set_unchecked(v, i);
72585+}
72586+#endif
72587+
72588 static inline void atomic_long_inc(atomic_long_t *l)
72589 {
72590 atomic_t *v = (atomic_t *)l;
72591@@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
72592 atomic_inc(v);
72593 }
72594
72595+#ifdef CONFIG_PAX_REFCOUNT
72596+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
72597+{
72598+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
72599+
72600+ atomic_inc_unchecked(v);
72601+}
72602+#endif
72603+
72604 static inline void atomic_long_dec(atomic_long_t *l)
72605 {
72606 atomic_t *v = (atomic_t *)l;
72607@@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
72608 atomic_dec(v);
72609 }
72610
72611+#ifdef CONFIG_PAX_REFCOUNT
72612+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
72613+{
72614+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
72615+
72616+ atomic_dec_unchecked(v);
72617+}
72618+#endif
72619+
72620 static inline void atomic_long_add(long i, atomic_long_t *l)
72621 {
72622 atomic_t *v = (atomic_t *)l;
72623@@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
72624 atomic_add(i, v);
72625 }
72626
72627+#ifdef CONFIG_PAX_REFCOUNT
72628+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
72629+{
72630+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
72631+
72632+ atomic_add_unchecked(i, v);
72633+}
72634+#endif
72635+
72636 static inline void atomic_long_sub(long i, atomic_long_t *l)
72637 {
72638 atomic_t *v = (atomic_t *)l;
72639@@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
72640 atomic_sub(i, v);
72641 }
72642
72643+#ifdef CONFIG_PAX_REFCOUNT
72644+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
72645+{
72646+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
72647+
72648+ atomic_sub_unchecked(i, v);
72649+}
72650+#endif
72651+
72652 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
72653 {
72654 atomic_t *v = (atomic_t *)l;
72655@@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
72656 return (long)atomic_add_return(i, v);
72657 }
72658
72659+#ifdef CONFIG_PAX_REFCOUNT
72660+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
72661+{
72662+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
72663+
72664+ return (long)atomic_add_return_unchecked(i, v);
72665+}
72666+
72667+#endif
72668+
72669 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
72670 {
72671 atomic_t *v = (atomic_t *)l;
72672@@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
72673 return (long)atomic_inc_return(v);
72674 }
72675
72676+#ifdef CONFIG_PAX_REFCOUNT
72677+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
72678+{
72679+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
72680+
72681+ return (long)atomic_inc_return_unchecked(v);
72682+}
72683+#endif
72684+
72685 static inline long atomic_long_dec_return(atomic_long_t *l)
72686 {
72687 atomic_t *v = (atomic_t *)l;
72688@@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
72689
72690 #endif /* BITS_PER_LONG == 64 */
72691
72692+#ifdef CONFIG_PAX_REFCOUNT
72693+static inline void pax_refcount_needs_these_functions(void)
72694+{
72695+ atomic_read_unchecked((atomic_unchecked_t *)NULL);
72696+ atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
72697+ atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
72698+ atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
72699+ atomic_inc_unchecked((atomic_unchecked_t *)NULL);
72700+ (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
72701+ atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
72702+ atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
72703+ atomic_dec_unchecked((atomic_unchecked_t *)NULL);
72704+ atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
72705+ (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
72706+#ifdef CONFIG_X86
72707+ atomic_clear_mask_unchecked(0, NULL);
72708+ atomic_set_mask_unchecked(0, NULL);
72709+#endif
72710+
72711+ atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
72712+ atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
72713+ atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
72714+ atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
72715+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
72716+ atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
72717+ atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
72718+ atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
72719+}
72720+#else
72721+#define atomic_read_unchecked(v) atomic_read(v)
72722+#define atomic_set_unchecked(v, i) atomic_set((v), (i))
72723+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
72724+#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
72725+#define atomic_inc_unchecked(v) atomic_inc(v)
72726+#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
72727+#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
72728+#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
72729+#define atomic_dec_unchecked(v) atomic_dec(v)
72730+#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
72731+#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
72732+#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
72733+#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
72734+
72735+#define atomic_long_read_unchecked(v) atomic_long_read(v)
72736+#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
72737+#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
72738+#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
72739+#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
72740+#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
72741+#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
72742+#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
72743+#endif
72744+
72745 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
72746diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
72747index 33bd2de..f31bff97 100644
72748--- a/include/asm-generic/atomic.h
72749+++ b/include/asm-generic/atomic.h
72750@@ -153,7 +153,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
72751 * Atomically clears the bits set in @mask from @v
72752 */
72753 #ifndef atomic_clear_mask
72754-static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
72755+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
72756 {
72757 unsigned long flags;
72758
72759diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
72760index b18ce4f..2ee2843 100644
72761--- a/include/asm-generic/atomic64.h
72762+++ b/include/asm-generic/atomic64.h
72763@@ -16,6 +16,8 @@ typedef struct {
72764 long long counter;
72765 } atomic64_t;
72766
72767+typedef atomic64_t atomic64_unchecked_t;
72768+
72769 #define ATOMIC64_INIT(i) { (i) }
72770
72771 extern long long atomic64_read(const atomic64_t *v);
72772@@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
72773 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
72774 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
72775
72776+#define atomic64_read_unchecked(v) atomic64_read(v)
72777+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
72778+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
72779+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
72780+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
72781+#define atomic64_inc_unchecked(v) atomic64_inc(v)
72782+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
72783+#define atomic64_dec_unchecked(v) atomic64_dec(v)
72784+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
72785+
72786 #endif /* _ASM_GENERIC_ATOMIC64_H */
72787diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
72788index 1bfcfe5..e04c5c9 100644
72789--- a/include/asm-generic/cache.h
72790+++ b/include/asm-generic/cache.h
72791@@ -6,7 +6,7 @@
72792 * cache lines need to provide their own cache.h.
72793 */
72794
72795-#define L1_CACHE_SHIFT 5
72796-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
72797+#define L1_CACHE_SHIFT 5UL
72798+#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
72799
72800 #endif /* __ASM_GENERIC_CACHE_H */
72801diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
72802index 0d68a1e..b74a761 100644
72803--- a/include/asm-generic/emergency-restart.h
72804+++ b/include/asm-generic/emergency-restart.h
72805@@ -1,7 +1,7 @@
72806 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
72807 #define _ASM_GENERIC_EMERGENCY_RESTART_H
72808
72809-static inline void machine_emergency_restart(void)
72810+static inline __noreturn void machine_emergency_restart(void)
72811 {
72812 machine_restart(NULL);
72813 }
72814diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
72815index 90f99c7..00ce236 100644
72816--- a/include/asm-generic/kmap_types.h
72817+++ b/include/asm-generic/kmap_types.h
72818@@ -2,9 +2,9 @@
72819 #define _ASM_GENERIC_KMAP_TYPES_H
72820
72821 #ifdef __WITH_KM_FENCE
72822-# define KM_TYPE_NR 41
72823+# define KM_TYPE_NR 42
72824 #else
72825-# define KM_TYPE_NR 20
72826+# define KM_TYPE_NR 21
72827 #endif
72828
72829 #endif
72830diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
72831index 9ceb03b..62b0b8f 100644
72832--- a/include/asm-generic/local.h
72833+++ b/include/asm-generic/local.h
72834@@ -23,24 +23,37 @@ typedef struct
72835 atomic_long_t a;
72836 } local_t;
72837
72838+typedef struct {
72839+ atomic_long_unchecked_t a;
72840+} local_unchecked_t;
72841+
72842 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
72843
72844 #define local_read(l) atomic_long_read(&(l)->a)
72845+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
72846 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
72847+#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
72848 #define local_inc(l) atomic_long_inc(&(l)->a)
72849+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
72850 #define local_dec(l) atomic_long_dec(&(l)->a)
72851+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
72852 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
72853+#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
72854 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
72855+#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
72856
72857 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
72858 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
72859 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
72860 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
72861 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
72862+#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
72863 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
72864 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
72865+#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
72866
72867 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
72868+#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
72869 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
72870 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
72871 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
72872diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
72873index 725612b..9cc513a 100644
72874--- a/include/asm-generic/pgtable-nopmd.h
72875+++ b/include/asm-generic/pgtable-nopmd.h
72876@@ -1,14 +1,19 @@
72877 #ifndef _PGTABLE_NOPMD_H
72878 #define _PGTABLE_NOPMD_H
72879
72880-#ifndef __ASSEMBLY__
72881-
72882 #include <asm-generic/pgtable-nopud.h>
72883
72884-struct mm_struct;
72885-
72886 #define __PAGETABLE_PMD_FOLDED
72887
72888+#define PMD_SHIFT PUD_SHIFT
72889+#define PTRS_PER_PMD 1
72890+#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
72891+#define PMD_MASK (~(PMD_SIZE-1))
72892+
72893+#ifndef __ASSEMBLY__
72894+
72895+struct mm_struct;
72896+
72897 /*
72898 * Having the pmd type consist of a pud gets the size right, and allows
72899 * us to conceptually access the pud entry that this pmd is folded into
72900@@ -16,11 +21,6 @@ struct mm_struct;
72901 */
72902 typedef struct { pud_t pud; } pmd_t;
72903
72904-#define PMD_SHIFT PUD_SHIFT
72905-#define PTRS_PER_PMD 1
72906-#define PMD_SIZE (1UL << PMD_SHIFT)
72907-#define PMD_MASK (~(PMD_SIZE-1))
72908-
72909 /*
72910 * The "pud_xxx()" functions here are trivial for a folded two-level
72911 * setup: the pmd is never bad, and a pmd always exists (as it's folded
72912diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
72913index 810431d..0ec4804f 100644
72914--- a/include/asm-generic/pgtable-nopud.h
72915+++ b/include/asm-generic/pgtable-nopud.h
72916@@ -1,10 +1,15 @@
72917 #ifndef _PGTABLE_NOPUD_H
72918 #define _PGTABLE_NOPUD_H
72919
72920-#ifndef __ASSEMBLY__
72921-
72922 #define __PAGETABLE_PUD_FOLDED
72923
72924+#define PUD_SHIFT PGDIR_SHIFT
72925+#define PTRS_PER_PUD 1
72926+#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
72927+#define PUD_MASK (~(PUD_SIZE-1))
72928+
72929+#ifndef __ASSEMBLY__
72930+
72931 /*
72932 * Having the pud type consist of a pgd gets the size right, and allows
72933 * us to conceptually access the pgd entry that this pud is folded into
72934@@ -12,11 +17,6 @@
72935 */
72936 typedef struct { pgd_t pgd; } pud_t;
72937
72938-#define PUD_SHIFT PGDIR_SHIFT
72939-#define PTRS_PER_PUD 1
72940-#define PUD_SIZE (1UL << PUD_SHIFT)
72941-#define PUD_MASK (~(PUD_SIZE-1))
72942-
72943 /*
72944 * The "pgd_xxx()" functions here are trivial for a folded two-level
72945 * setup: the pud is never bad, and a pud always exists (as it's folded
72946@@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
72947 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
72948
72949 #define pgd_populate(mm, pgd, pud) do { } while (0)
72950+#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
72951 /*
72952 * (puds are folded into pgds so this doesn't get actually called,
72953 * but the define is needed for a generic inline function.)
72954diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
72955index f330d28..83ce28f 100644
72956--- a/include/asm-generic/pgtable.h
72957+++ b/include/asm-generic/pgtable.h
72958@@ -737,6 +737,22 @@ static inline pmd_t pmd_mknuma(pmd_t pmd)
72959 }
72960 #endif /* CONFIG_NUMA_BALANCING */
72961
72962+#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
72963+#ifdef CONFIG_PAX_KERNEXEC
72964+#error KERNEXEC requires pax_open_kernel
72965+#else
72966+static inline unsigned long pax_open_kernel(void) { return 0; }
72967+#endif
72968+#endif
72969+
72970+#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
72971+#ifdef CONFIG_PAX_KERNEXEC
72972+#error KERNEXEC requires pax_close_kernel
72973+#else
72974+static inline unsigned long pax_close_kernel(void) { return 0; }
72975+#endif
72976+#endif
72977+
72978 #endif /* CONFIG_MMU */
72979
72980 #endif /* !__ASSEMBLY__ */
72981diff --git a/include/asm-generic/uaccess.h b/include/asm-generic/uaccess.h
72982index dc1269c..48a4f51 100644
72983--- a/include/asm-generic/uaccess.h
72984+++ b/include/asm-generic/uaccess.h
72985@@ -343,4 +343,20 @@ clear_user(void __user *to, unsigned long n)
72986 return __clear_user(to, n);
72987 }
72988
72989+#ifndef __HAVE_ARCH_PAX_OPEN_USERLAND
72990+#ifdef CONFIG_PAX_MEMORY_UDEREF
72991+#error UDEREF requires pax_open_userland
72992+#else
72993+static inline unsigned long pax_open_userland(void) { return 0; }
72994+#endif
72995+#endif
72996+
72997+#ifndef __HAVE_ARCH_PAX_CLOSE_USERLAND
72998+#ifdef CONFIG_PAX_MEMORY_UDEREF
72999+#error UDEREF requires pax_close_userland
73000+#else
73001+static inline unsigned long pax_close_userland(void) { return 0; }
73002+#endif
73003+#endif
73004+
73005 #endif /* __ASM_GENERIC_UACCESS_H */
73006diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
73007index 83e2c31..eeb4a04 100644
73008--- a/include/asm-generic/vmlinux.lds.h
73009+++ b/include/asm-generic/vmlinux.lds.h
73010@@ -232,6 +232,7 @@
73011 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
73012 VMLINUX_SYMBOL(__start_rodata) = .; \
73013 *(.rodata) *(.rodata.*) \
73014+ *(.data..read_only) \
73015 *(__vermagic) /* Kernel version magic */ \
73016 . = ALIGN(8); \
73017 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
73018@@ -715,17 +716,18 @@
73019 * section in the linker script will go there too. @phdr should have
73020 * a leading colon.
73021 *
73022- * Note that this macros defines __per_cpu_load as an absolute symbol.
73023+ * Note that this macros defines per_cpu_load as an absolute symbol.
73024 * If there is no need to put the percpu section at a predetermined
73025 * address, use PERCPU_SECTION.
73026 */
73027 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
73028- VMLINUX_SYMBOL(__per_cpu_load) = .; \
73029- .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
73030+ per_cpu_load = .; \
73031+ .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
73032 - LOAD_OFFSET) { \
73033+ VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
73034 PERCPU_INPUT(cacheline) \
73035 } phdr \
73036- . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
73037+ . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
73038
73039 /**
73040 * PERCPU_SECTION - define output section for percpu area, simple version
73041diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
73042index 418d270..bfd2794 100644
73043--- a/include/crypto/algapi.h
73044+++ b/include/crypto/algapi.h
73045@@ -34,7 +34,7 @@ struct crypto_type {
73046 unsigned int maskclear;
73047 unsigned int maskset;
73048 unsigned int tfmsize;
73049-};
73050+} __do_const;
73051
73052 struct crypto_instance {
73053 struct crypto_alg alg;
73054diff --git a/include/drm/drmP.h b/include/drm/drmP.h
73055index b46fb45..b30d6d5 100644
73056--- a/include/drm/drmP.h
73057+++ b/include/drm/drmP.h
73058@@ -66,6 +66,7 @@
73059 #include <linux/workqueue.h>
73060 #include <linux/poll.h>
73061 #include <asm/pgalloc.h>
73062+#include <asm/local.h>
73063 #include <drm/drm.h>
73064 #include <drm/drm_sarea.h>
73065 #include <drm/drm_vma_manager.h>
73066@@ -277,10 +278,12 @@ do { \
73067 * \param cmd command.
73068 * \param arg argument.
73069 */
73070-typedef int drm_ioctl_t(struct drm_device *dev, void *data,
73071+typedef int (* const drm_ioctl_t)(struct drm_device *dev, void *data,
73072+ struct drm_file *file_priv);
73073+typedef int (* drm_ioctl_no_const_t)(struct drm_device *dev, void *data,
73074 struct drm_file *file_priv);
73075
73076-typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
73077+typedef int (* const drm_ioctl_compat_t)(struct file *filp, unsigned int cmd,
73078 unsigned long arg);
73079
73080 #define DRM_IOCTL_NR(n) _IOC_NR(n)
73081@@ -296,10 +299,10 @@ typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
73082 struct drm_ioctl_desc {
73083 unsigned int cmd;
73084 int flags;
73085- drm_ioctl_t *func;
73086+ drm_ioctl_t func;
73087 unsigned int cmd_drv;
73088 const char *name;
73089-};
73090+} __do_const;
73091
73092 /**
73093 * Creates a driver or general drm_ioctl_desc array entry for the given
73094@@ -1027,7 +1030,7 @@ struct drm_info_list {
73095 int (*show)(struct seq_file*, void*); /** show callback */
73096 u32 driver_features; /**< Required driver features for this entry */
73097 void *data;
73098-};
73099+} __do_const;
73100
73101 /**
73102 * debugfs node structure. This structure represents a debugfs file.
73103@@ -1098,7 +1101,7 @@ struct drm_device {
73104
73105 /** \name Usage Counters */
73106 /*@{ */
73107- int open_count; /**< Outstanding files open */
73108+ local_t open_count; /**< Outstanding files open */
73109 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
73110 atomic_t vma_count; /**< Outstanding vma areas open */
73111 int buf_use; /**< Buffers in use -- cannot alloc */
73112@@ -1109,7 +1112,7 @@ struct drm_device {
73113 /*@{ */
73114 unsigned long counters;
73115 enum drm_stat_type types[15];
73116- atomic_t counts[15];
73117+ atomic_unchecked_t counts[15];
73118 /*@} */
73119
73120 struct list_head filelist;
73121diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
73122index f43d556..94d9343 100644
73123--- a/include/drm/drm_crtc_helper.h
73124+++ b/include/drm/drm_crtc_helper.h
73125@@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
73126 struct drm_connector *connector);
73127 /* disable encoder when not in use - more explicit than dpms off */
73128 void (*disable)(struct drm_encoder *encoder);
73129-};
73130+} __no_const;
73131
73132 /**
73133 * drm_connector_helper_funcs - helper operations for connectors
73134diff --git a/include/drm/i915_pciids.h b/include/drm/i915_pciids.h
73135index 8a10f5c..5de7f5c 100644
73136--- a/include/drm/i915_pciids.h
73137+++ b/include/drm/i915_pciids.h
73138@@ -37,7 +37,7 @@
73139 */
73140 #define INTEL_VGA_DEVICE(id, info) { \
73141 0x8086, id, \
73142- ~0, ~0, \
73143+ PCI_ANY_ID, PCI_ANY_ID, \
73144 0x030000, 0xff0000, \
73145 (unsigned long) info }
73146
73147diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
73148index 72dcbe8..8db58d7 100644
73149--- a/include/drm/ttm/ttm_memory.h
73150+++ b/include/drm/ttm/ttm_memory.h
73151@@ -48,7 +48,7 @@
73152
73153 struct ttm_mem_shrink {
73154 int (*do_shrink) (struct ttm_mem_shrink *);
73155-};
73156+} __no_const;
73157
73158 /**
73159 * struct ttm_mem_global - Global memory accounting structure.
73160diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-subtype.h
73161index 4b840e8..155d235 100644
73162--- a/include/keys/asymmetric-subtype.h
73163+++ b/include/keys/asymmetric-subtype.h
73164@@ -37,7 +37,7 @@ struct asymmetric_key_subtype {
73165 /* Verify the signature on a key of this subtype (optional) */
73166 int (*verify_signature)(const struct key *key,
73167 const struct public_key_signature *sig);
73168-};
73169+} __do_const;
73170
73171 /**
73172 * asymmetric_key_subtype - Get the subtype from an asymmetric key
73173diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
73174index c1da539..1dcec55 100644
73175--- a/include/linux/atmdev.h
73176+++ b/include/linux/atmdev.h
73177@@ -28,7 +28,7 @@ struct compat_atm_iobuf {
73178 #endif
73179
73180 struct k_atm_aal_stats {
73181-#define __HANDLE_ITEM(i) atomic_t i
73182+#define __HANDLE_ITEM(i) atomic_unchecked_t i
73183 __AAL_STAT_ITEMS
73184 #undef __HANDLE_ITEM
73185 };
73186@@ -200,7 +200,7 @@ struct atmdev_ops { /* only send is required */
73187 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
73188 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
73189 struct module *owner;
73190-};
73191+} __do_const ;
73192
73193 struct atmphy_ops {
73194 int (*start)(struct atm_dev *dev);
73195diff --git a/include/linux/audit.h b/include/linux/audit.h
73196index 729a4d1..9b304ae 100644
73197--- a/include/linux/audit.h
73198+++ b/include/linux/audit.h
73199@@ -193,7 +193,7 @@ static inline void audit_ptrace(struct task_struct *t)
73200 extern unsigned int audit_serial(void);
73201 extern int auditsc_get_stamp(struct audit_context *ctx,
73202 struct timespec *t, unsigned int *serial);
73203-extern int audit_set_loginuid(kuid_t loginuid);
73204+extern int __intentional_overflow(-1) audit_set_loginuid(kuid_t loginuid);
73205
73206 static inline kuid_t audit_get_loginuid(struct task_struct *tsk)
73207 {
73208diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
73209index e8112ae..05b8e7f 100644
73210--- a/include/linux/binfmts.h
73211+++ b/include/linux/binfmts.h
73212@@ -73,8 +73,10 @@ struct linux_binfmt {
73213 int (*load_binary)(struct linux_binprm *);
73214 int (*load_shlib)(struct file *);
73215 int (*core_dump)(struct coredump_params *cprm);
73216+ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
73217+ void (*handle_mmap)(struct file *);
73218 unsigned long min_coredump; /* minimal dump size */
73219-};
73220+} __do_const;
73221
73222 extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
73223
73224diff --git a/include/linux/bitops.h b/include/linux/bitops.h
73225index a3b6b82..cd8f69c 100644
73226--- a/include/linux/bitops.h
73227+++ b/include/linux/bitops.h
73228@@ -91,7 +91,7 @@ static inline __u64 ror64(__u64 word, unsigned int shift)
73229 * @word: value to rotate
73230 * @shift: bits to roll
73231 */
73232-static inline __u32 rol32(__u32 word, unsigned int shift)
73233+static inline __u32 __intentional_overflow(-1) rol32(__u32 word, unsigned int shift)
73234 {
73235 return (word << shift) | (word >> (32 - shift));
73236 }
73237@@ -101,7 +101,7 @@ static inline __u32 rol32(__u32 word, unsigned int shift)
73238 * @word: value to rotate
73239 * @shift: bits to roll
73240 */
73241-static inline __u32 ror32(__u32 word, unsigned int shift)
73242+static inline __u32 __intentional_overflow(-1) ror32(__u32 word, unsigned int shift)
73243 {
73244 return (word >> shift) | (word << (32 - shift));
73245 }
73246diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
73247index 0e6f765..885bb2b 100644
73248--- a/include/linux/blkdev.h
73249+++ b/include/linux/blkdev.h
73250@@ -1537,7 +1537,7 @@ struct block_device_operations {
73251 /* this callback is with swap_lock and sometimes page table lock held */
73252 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
73253 struct module *owner;
73254-};
73255+} __do_const;
73256
73257 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
73258 unsigned long);
73259diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
73260index 7c2e030..b72475d 100644
73261--- a/include/linux/blktrace_api.h
73262+++ b/include/linux/blktrace_api.h
73263@@ -23,7 +23,7 @@ struct blk_trace {
73264 struct dentry *dir;
73265 struct dentry *dropped_file;
73266 struct dentry *msg_file;
73267- atomic_t dropped;
73268+ atomic_unchecked_t dropped;
73269 };
73270
73271 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
73272diff --git a/include/linux/cache.h b/include/linux/cache.h
73273index 4c57065..40346da 100644
73274--- a/include/linux/cache.h
73275+++ b/include/linux/cache.h
73276@@ -16,6 +16,14 @@
73277 #define __read_mostly
73278 #endif
73279
73280+#ifndef __read_only
73281+#ifdef CONFIG_PAX_KERNEXEC
73282+#error KERNEXEC requires __read_only
73283+#else
73284+#define __read_only __read_mostly
73285+#endif
73286+#endif
73287+
73288 #ifndef ____cacheline_aligned
73289 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
73290 #endif
73291diff --git a/include/linux/capability.h b/include/linux/capability.h
73292index a6ee1f9..e1ca49d 100644
73293--- a/include/linux/capability.h
73294+++ b/include/linux/capability.h
73295@@ -212,8 +212,13 @@ extern bool capable(int cap);
73296 extern bool ns_capable(struct user_namespace *ns, int cap);
73297 extern bool inode_capable(const struct inode *inode, int cap);
73298 extern bool file_ns_capable(const struct file *file, struct user_namespace *ns, int cap);
73299+extern bool capable_nolog(int cap);
73300+extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
73301+extern bool inode_capable_nolog(const struct inode *inode, int cap);
73302
73303 /* audit system wants to get cap info from files as well */
73304 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
73305
73306+extern int is_privileged_binary(const struct dentry *dentry);
73307+
73308 #endif /* !_LINUX_CAPABILITY_H */
73309diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
73310index 8609d57..86e4d79 100644
73311--- a/include/linux/cdrom.h
73312+++ b/include/linux/cdrom.h
73313@@ -87,7 +87,6 @@ struct cdrom_device_ops {
73314
73315 /* driver specifications */
73316 const int capability; /* capability flags */
73317- int n_minors; /* number of active minor devices */
73318 /* handle uniform packets for scsi type devices (scsi,atapi) */
73319 int (*generic_packet) (struct cdrom_device_info *,
73320 struct packet_command *);
73321diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
73322index 4ce9056..86caac6 100644
73323--- a/include/linux/cleancache.h
73324+++ b/include/linux/cleancache.h
73325@@ -31,7 +31,7 @@ struct cleancache_ops {
73326 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
73327 void (*invalidate_inode)(int, struct cleancache_filekey);
73328 void (*invalidate_fs)(int);
73329-};
73330+} __no_const;
73331
73332 extern struct cleancache_ops *
73333 cleancache_register_ops(struct cleancache_ops *ops);
73334diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
73335index 73bdb69..d66d47a 100644
73336--- a/include/linux/clk-provider.h
73337+++ b/include/linux/clk-provider.h
73338@@ -141,6 +141,7 @@ struct clk_ops {
73339 unsigned long);
73340 void (*init)(struct clk_hw *hw);
73341 };
73342+typedef struct clk_ops __no_const clk_ops_no_const;
73343
73344 /**
73345 * struct clk_init_data - holds init data that's common to all clocks and is
73346diff --git a/include/linux/compat.h b/include/linux/compat.h
73347index 345da00..b6eff26 100644
73348--- a/include/linux/compat.h
73349+++ b/include/linux/compat.h
73350@@ -313,7 +313,7 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
73351 compat_size_t __user *len_ptr);
73352
73353 asmlinkage long compat_sys_ipc(u32, int, int, u32, compat_uptr_t, u32);
73354-asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg);
73355+asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg) __intentional_overflow(0);
73356 asmlinkage long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
73357 asmlinkage long compat_sys_msgsnd(int msqid, compat_uptr_t msgp,
73358 compat_ssize_t msgsz, int msgflg);
73359@@ -420,7 +420,7 @@ extern int compat_ptrace_request(struct task_struct *child,
73360 extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
73361 compat_ulong_t addr, compat_ulong_t data);
73362 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
73363- compat_long_t addr, compat_long_t data);
73364+ compat_ulong_t addr, compat_ulong_t data);
73365
73366 asmlinkage long compat_sys_lookup_dcookie(u32, u32, char __user *, size_t);
73367 /*
73368diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
73369index ded4299..da50e3b 100644
73370--- a/include/linux/compiler-gcc4.h
73371+++ b/include/linux/compiler-gcc4.h
73372@@ -39,9 +39,29 @@
73373 # define __compiletime_warning(message) __attribute__((warning(message)))
73374 # define __compiletime_error(message) __attribute__((error(message)))
73375 #endif /* __CHECKER__ */
73376+
73377+#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
73378+#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
73379+#define __bos0(ptr) __bos((ptr), 0)
73380+#define __bos1(ptr) __bos((ptr), 1)
73381 #endif /* GCC_VERSION >= 40300 */
73382
73383 #if GCC_VERSION >= 40500
73384+
73385+#ifdef CONSTIFY_PLUGIN
73386+#define __no_const __attribute__((no_const))
73387+#define __do_const __attribute__((do_const))
73388+#endif
73389+
73390+#ifdef SIZE_OVERFLOW_PLUGIN
73391+#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
73392+#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
73393+#endif
73394+
73395+#ifdef LATENT_ENTROPY_PLUGIN
73396+#define __latent_entropy __attribute__((latent_entropy))
73397+#endif
73398+
73399 /*
73400 * Mark a position in code as unreachable. This can be used to
73401 * suppress control flow warnings after asm blocks that transfer
73402diff --git a/include/linux/compiler.h b/include/linux/compiler.h
73403index 92669cd..1771a15 100644
73404--- a/include/linux/compiler.h
73405+++ b/include/linux/compiler.h
73406@@ -5,11 +5,14 @@
73407
73408 #ifdef __CHECKER__
73409 # define __user __attribute__((noderef, address_space(1)))
73410+# define __force_user __force __user
73411 # define __kernel __attribute__((address_space(0)))
73412+# define __force_kernel __force __kernel
73413 # define __safe __attribute__((safe))
73414 # define __force __attribute__((force))
73415 # define __nocast __attribute__((nocast))
73416 # define __iomem __attribute__((noderef, address_space(2)))
73417+# define __force_iomem __force __iomem
73418 # define __must_hold(x) __attribute__((context(x,1,1)))
73419 # define __acquires(x) __attribute__((context(x,0,1)))
73420 # define __releases(x) __attribute__((context(x,1,0)))
73421@@ -17,20 +20,37 @@
73422 # define __release(x) __context__(x,-1)
73423 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
73424 # define __percpu __attribute__((noderef, address_space(3)))
73425+# define __force_percpu __force __percpu
73426 #ifdef CONFIG_SPARSE_RCU_POINTER
73427 # define __rcu __attribute__((noderef, address_space(4)))
73428+# define __force_rcu __force __rcu
73429 #else
73430 # define __rcu
73431+# define __force_rcu
73432 #endif
73433 extern void __chk_user_ptr(const volatile void __user *);
73434 extern void __chk_io_ptr(const volatile void __iomem *);
73435 #else
73436-# define __user
73437-# define __kernel
73438+# ifdef CHECKER_PLUGIN
73439+//# define __user
73440+//# define __force_user
73441+//# define __kernel
73442+//# define __force_kernel
73443+# else
73444+# ifdef STRUCTLEAK_PLUGIN
73445+# define __user __attribute__((user))
73446+# else
73447+# define __user
73448+# endif
73449+# define __force_user
73450+# define __kernel
73451+# define __force_kernel
73452+# endif
73453 # define __safe
73454 # define __force
73455 # define __nocast
73456 # define __iomem
73457+# define __force_iomem
73458 # define __chk_user_ptr(x) (void)0
73459 # define __chk_io_ptr(x) (void)0
73460 # define __builtin_warning(x, y...) (1)
73461@@ -41,7 +61,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
73462 # define __release(x) (void)0
73463 # define __cond_lock(x,c) (c)
73464 # define __percpu
73465+# define __force_percpu
73466 # define __rcu
73467+# define __force_rcu
73468 #endif
73469
73470 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
73471@@ -275,6 +297,26 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
73472 # define __attribute_const__ /* unimplemented */
73473 #endif
73474
73475+#ifndef __no_const
73476+# define __no_const
73477+#endif
73478+
73479+#ifndef __do_const
73480+# define __do_const
73481+#endif
73482+
73483+#ifndef __size_overflow
73484+# define __size_overflow(...)
73485+#endif
73486+
73487+#ifndef __intentional_overflow
73488+# define __intentional_overflow(...)
73489+#endif
73490+
73491+#ifndef __latent_entropy
73492+# define __latent_entropy
73493+#endif
73494+
73495 /*
73496 * Tell gcc if a function is cold. The compiler will assume any path
73497 * directly leading to the call is unlikely.
73498@@ -284,6 +326,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
73499 #define __cold
73500 #endif
73501
73502+#ifndef __alloc_size
73503+#define __alloc_size(...)
73504+#endif
73505+
73506+#ifndef __bos
73507+#define __bos(ptr, arg)
73508+#endif
73509+
73510+#ifndef __bos0
73511+#define __bos0(ptr)
73512+#endif
73513+
73514+#ifndef __bos1
73515+#define __bos1(ptr)
73516+#endif
73517+
73518 /* Simple shorthand for a section definition */
73519 #ifndef __section
73520 # define __section(S) __attribute__ ((__section__(#S)))
73521@@ -349,7 +407,8 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
73522 * use is to mediate communication between process-level code and irq/NMI
73523 * handlers, all running on the same CPU.
73524 */
73525-#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
73526+#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
73527+#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
73528
73529 /* Ignore/forbid kprobes attach on very low level functions marked by this attribute: */
73530 #ifdef CONFIG_KPROBES
73531diff --git a/include/linux/completion.h b/include/linux/completion.h
73532index 3cd574d..240dcb0 100644
73533--- a/include/linux/completion.h
73534+++ b/include/linux/completion.h
73535@@ -78,16 +78,16 @@ static inline void init_completion(struct completion *x)
73536
73537 extern void wait_for_completion(struct completion *);
73538 extern void wait_for_completion_io(struct completion *);
73539-extern int wait_for_completion_interruptible(struct completion *x);
73540-extern int wait_for_completion_killable(struct completion *x);
73541+extern int wait_for_completion_interruptible(struct completion *x) __intentional_overflow(-1);
73542+extern int wait_for_completion_killable(struct completion *x) __intentional_overflow(-1);
73543 extern unsigned long wait_for_completion_timeout(struct completion *x,
73544- unsigned long timeout);
73545+ unsigned long timeout) __intentional_overflow(-1);
73546 extern unsigned long wait_for_completion_io_timeout(struct completion *x,
73547- unsigned long timeout);
73548+ unsigned long timeout) __intentional_overflow(-1);
73549 extern long wait_for_completion_interruptible_timeout(
73550- struct completion *x, unsigned long timeout);
73551+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
73552 extern long wait_for_completion_killable_timeout(
73553- struct completion *x, unsigned long timeout);
73554+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
73555 extern bool try_wait_for_completion(struct completion *x);
73556 extern bool completion_done(struct completion *x);
73557
73558diff --git a/include/linux/configfs.h b/include/linux/configfs.h
73559index 34025df..d94bbbc 100644
73560--- a/include/linux/configfs.h
73561+++ b/include/linux/configfs.h
73562@@ -125,7 +125,7 @@ struct configfs_attribute {
73563 const char *ca_name;
73564 struct module *ca_owner;
73565 umode_t ca_mode;
73566-};
73567+} __do_const;
73568
73569 /*
73570 * Users often need to create attribute structures for their configurable
73571diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
73572index fcabc42..cba5d93 100644
73573--- a/include/linux/cpufreq.h
73574+++ b/include/linux/cpufreq.h
73575@@ -167,6 +167,7 @@ struct global_attr {
73576 ssize_t (*store)(struct kobject *a, struct attribute *b,
73577 const char *c, size_t count);
73578 };
73579+typedef struct global_attr __no_const global_attr_no_const;
73580
73581 #define define_one_global_ro(_name) \
73582 static struct global_attr _name = \
73583@@ -208,7 +209,7 @@ struct cpufreq_driver {
73584 int (*suspend) (struct cpufreq_policy *policy);
73585 int (*resume) (struct cpufreq_policy *policy);
73586 struct freq_attr **attr;
73587-};
73588+} __do_const;
73589
73590 /* flags */
73591 #define CPUFREQ_STICKY 0x01 /* the driver isn't removed even if
73592diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
73593index 781addc..d1e1fe6 100644
73594--- a/include/linux/cpuidle.h
73595+++ b/include/linux/cpuidle.h
73596@@ -50,7 +50,8 @@ struct cpuidle_state {
73597 int index);
73598
73599 int (*enter_dead) (struct cpuidle_device *dev, int index);
73600-};
73601+} __do_const;
73602+typedef struct cpuidle_state __no_const cpuidle_state_no_const;
73603
73604 /* Idle State Flags */
73605 #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
73606@@ -192,7 +193,7 @@ struct cpuidle_governor {
73607 void (*reflect) (struct cpuidle_device *dev, int index);
73608
73609 struct module *owner;
73610-};
73611+} __do_const;
73612
73613 #ifdef CONFIG_CPU_IDLE
73614
73615diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
73616index d08e4d2..95fad61 100644
73617--- a/include/linux/cpumask.h
73618+++ b/include/linux/cpumask.h
73619@@ -118,17 +118,17 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
73620 }
73621
73622 /* Valid inputs for n are -1 and 0. */
73623-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
73624+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
73625 {
73626 return n+1;
73627 }
73628
73629-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
73630+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
73631 {
73632 return n+1;
73633 }
73634
73635-static inline unsigned int cpumask_next_and(int n,
73636+static inline unsigned int __intentional_overflow(-1) cpumask_next_and(int n,
73637 const struct cpumask *srcp,
73638 const struct cpumask *andp)
73639 {
73640@@ -167,7 +167,7 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
73641 *
73642 * Returns >= nr_cpu_ids if no further cpus set.
73643 */
73644-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
73645+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
73646 {
73647 /* -1 is a legal arg here. */
73648 if (n != -1)
73649@@ -182,7 +182,7 @@ static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
73650 *
73651 * Returns >= nr_cpu_ids if no further cpus unset.
73652 */
73653-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
73654+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
73655 {
73656 /* -1 is a legal arg here. */
73657 if (n != -1)
73658@@ -190,7 +190,7 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
73659 return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
73660 }
73661
73662-int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
73663+int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *) __intentional_overflow(-1);
73664 int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
73665
73666 /**
73667diff --git a/include/linux/cred.h b/include/linux/cred.h
73668index 04421e8..6bce4ef 100644
73669--- a/include/linux/cred.h
73670+++ b/include/linux/cred.h
73671@@ -194,6 +194,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
73672 static inline void validate_process_creds(void)
73673 {
73674 }
73675+static inline void validate_task_creds(struct task_struct *task)
73676+{
73677+}
73678 #endif
73679
73680 /**
73681diff --git a/include/linux/crypto.h b/include/linux/crypto.h
73682index b92eadf..b4ecdc1 100644
73683--- a/include/linux/crypto.h
73684+++ b/include/linux/crypto.h
73685@@ -373,7 +373,7 @@ struct cipher_tfm {
73686 const u8 *key, unsigned int keylen);
73687 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
73688 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
73689-};
73690+} __no_const;
73691
73692 struct hash_tfm {
73693 int (*init)(struct hash_desc *desc);
73694@@ -394,13 +394,13 @@ struct compress_tfm {
73695 int (*cot_decompress)(struct crypto_tfm *tfm,
73696 const u8 *src, unsigned int slen,
73697 u8 *dst, unsigned int *dlen);
73698-};
73699+} __no_const;
73700
73701 struct rng_tfm {
73702 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
73703 unsigned int dlen);
73704 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
73705-};
73706+} __no_const;
73707
73708 #define crt_ablkcipher crt_u.ablkcipher
73709 #define crt_aead crt_u.aead
73710diff --git a/include/linux/ctype.h b/include/linux/ctype.h
73711index 653589e..4ef254a 100644
73712--- a/include/linux/ctype.h
73713+++ b/include/linux/ctype.h
73714@@ -56,7 +56,7 @@ static inline unsigned char __toupper(unsigned char c)
73715 * Fast implementation of tolower() for internal usage. Do not use in your
73716 * code.
73717 */
73718-static inline char _tolower(const char c)
73719+static inline unsigned char _tolower(const unsigned char c)
73720 {
73721 return c | 0x20;
73722 }
73723diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
73724index 7925bf0..d5143d2 100644
73725--- a/include/linux/decompress/mm.h
73726+++ b/include/linux/decompress/mm.h
73727@@ -77,7 +77,7 @@ static void free(void *where)
73728 * warnings when not needed (indeed large_malloc / large_free are not
73729 * needed by inflate */
73730
73731-#define malloc(a) kmalloc(a, GFP_KERNEL)
73732+#define malloc(a) kmalloc((a), GFP_KERNEL)
73733 #define free(a) kfree(a)
73734
73735 #define large_malloc(a) vmalloc(a)
73736diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
73737index 5f1ab92..39c35ae 100644
73738--- a/include/linux/devfreq.h
73739+++ b/include/linux/devfreq.h
73740@@ -114,7 +114,7 @@ struct devfreq_governor {
73741 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
73742 int (*event_handler)(struct devfreq *devfreq,
73743 unsigned int event, void *data);
73744-};
73745+} __do_const;
73746
73747 /**
73748 * struct devfreq - Device devfreq structure
73749diff --git a/include/linux/device.h b/include/linux/device.h
73750index 2a9d6ed..d14551e3 100644
73751--- a/include/linux/device.h
73752+++ b/include/linux/device.h
73753@@ -313,7 +313,7 @@ struct subsys_interface {
73754 struct list_head node;
73755 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
73756 int (*remove_dev)(struct device *dev, struct subsys_interface *sif);
73757-};
73758+} __do_const;
73759
73760 int subsys_interface_register(struct subsys_interface *sif);
73761 void subsys_interface_unregister(struct subsys_interface *sif);
73762@@ -501,7 +501,7 @@ struct device_type {
73763 void (*release)(struct device *dev);
73764
73765 const struct dev_pm_ops *pm;
73766-};
73767+} __do_const;
73768
73769 /* interface for exporting device attributes */
73770 struct device_attribute {
73771@@ -511,11 +511,12 @@ struct device_attribute {
73772 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
73773 const char *buf, size_t count);
73774 };
73775+typedef struct device_attribute __no_const device_attribute_no_const;
73776
73777 struct dev_ext_attribute {
73778 struct device_attribute attr;
73779 void *var;
73780-};
73781+} __do_const;
73782
73783 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
73784 char *buf);
73785diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
73786index 3a8d0a2..c762be2 100644
73787--- a/include/linux/dma-mapping.h
73788+++ b/include/linux/dma-mapping.h
73789@@ -54,7 +54,7 @@ struct dma_map_ops {
73790 u64 (*get_required_mask)(struct device *dev);
73791 #endif
73792 int is_phys;
73793-};
73794+} __do_const;
73795
73796 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
73797
73798diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
73799index 0bc7275..4ccbf11 100644
73800--- a/include/linux/dmaengine.h
73801+++ b/include/linux/dmaengine.h
73802@@ -1078,9 +1078,9 @@ struct dma_pinned_list {
73803 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
73804 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
73805
73806-dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
73807+dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
73808 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
73809-dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
73810+dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
73811 struct dma_pinned_list *pinned_list, struct page *page,
73812 unsigned int offset, size_t len);
73813
73814diff --git a/include/linux/efi.h b/include/linux/efi.h
73815index 5f8f176..62a0556 100644
73816--- a/include/linux/efi.h
73817+++ b/include/linux/efi.h
73818@@ -745,6 +745,7 @@ struct efivar_operations {
73819 efi_set_variable_t *set_variable;
73820 efi_query_variable_store_t *query_variable_store;
73821 };
73822+typedef struct efivar_operations __no_const efivar_operations_no_const;
73823
73824 struct efivars {
73825 /*
73826diff --git a/include/linux/elf.h b/include/linux/elf.h
73827index 40a3c0e..4c45a38 100644
73828--- a/include/linux/elf.h
73829+++ b/include/linux/elf.h
73830@@ -24,6 +24,7 @@ extern Elf32_Dyn _DYNAMIC [];
73831 #define elf_note elf32_note
73832 #define elf_addr_t Elf32_Off
73833 #define Elf_Half Elf32_Half
73834+#define elf_dyn Elf32_Dyn
73835
73836 #else
73837
73838@@ -34,6 +35,7 @@ extern Elf64_Dyn _DYNAMIC [];
73839 #define elf_note elf64_note
73840 #define elf_addr_t Elf64_Off
73841 #define Elf_Half Elf64_Half
73842+#define elf_dyn Elf64_Dyn
73843
73844 #endif
73845
73846diff --git a/include/linux/err.h b/include/linux/err.h
73847index 15f92e0..e825a8e 100644
73848--- a/include/linux/err.h
73849+++ b/include/linux/err.h
73850@@ -19,12 +19,12 @@
73851
73852 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
73853
73854-static inline void * __must_check ERR_PTR(long error)
73855+static inline void * __must_check __intentional_overflow(-1) ERR_PTR(long error)
73856 {
73857 return (void *) error;
73858 }
73859
73860-static inline long __must_check PTR_ERR(__force const void *ptr)
73861+static inline long __must_check __intentional_overflow(-1) PTR_ERR(__force const void *ptr)
73862 {
73863 return (long) ptr;
73864 }
73865diff --git a/include/linux/extcon.h b/include/linux/extcon.h
73866index fcb51c8..bdafcf6 100644
73867--- a/include/linux/extcon.h
73868+++ b/include/linux/extcon.h
73869@@ -134,7 +134,7 @@ struct extcon_dev {
73870 /* /sys/class/extcon/.../mutually_exclusive/... */
73871 struct attribute_group attr_g_muex;
73872 struct attribute **attrs_muex;
73873- struct device_attribute *d_attrs_muex;
73874+ device_attribute_no_const *d_attrs_muex;
73875 };
73876
73877 /**
73878diff --git a/include/linux/fb.h b/include/linux/fb.h
73879index ffac70a..ca3e711 100644
73880--- a/include/linux/fb.h
73881+++ b/include/linux/fb.h
73882@@ -304,7 +304,7 @@ struct fb_ops {
73883 /* called at KDB enter and leave time to prepare the console */
73884 int (*fb_debug_enter)(struct fb_info *info);
73885 int (*fb_debug_leave)(struct fb_info *info);
73886-};
73887+} __do_const;
73888
73889 #ifdef CONFIG_FB_TILEBLITTING
73890 #define FB_TILE_CURSOR_NONE 0
73891diff --git a/include/linux/fdtable.h b/include/linux/fdtable.h
73892index 085197b..0fa6f0b 100644
73893--- a/include/linux/fdtable.h
73894+++ b/include/linux/fdtable.h
73895@@ -95,7 +95,7 @@ struct files_struct *get_files_struct(struct task_struct *);
73896 void put_files_struct(struct files_struct *fs);
73897 void reset_files_struct(struct files_struct *);
73898 int unshare_files(struct files_struct **);
73899-struct files_struct *dup_fd(struct files_struct *, int *);
73900+struct files_struct *dup_fd(struct files_struct *, int *) __latent_entropy;
73901 void do_close_on_exec(struct files_struct *);
73902 int iterate_fd(struct files_struct *, unsigned,
73903 int (*)(const void *, struct file *, unsigned),
73904diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
73905index 8293262..2b3b8bd 100644
73906--- a/include/linux/frontswap.h
73907+++ b/include/linux/frontswap.h
73908@@ -11,7 +11,7 @@ struct frontswap_ops {
73909 int (*load)(unsigned, pgoff_t, struct page *);
73910 void (*invalidate_page)(unsigned, pgoff_t);
73911 void (*invalidate_area)(unsigned);
73912-};
73913+} __no_const;
73914
73915 extern bool frontswap_enabled;
73916 extern struct frontswap_ops *
73917diff --git a/include/linux/fs.h b/include/linux/fs.h
73918index 3f40547..46f76eb 100644
73919--- a/include/linux/fs.h
73920+++ b/include/linux/fs.h
73921@@ -1552,7 +1552,8 @@ struct file_operations {
73922 long (*fallocate)(struct file *file, int mode, loff_t offset,
73923 loff_t len);
73924 int (*show_fdinfo)(struct seq_file *m, struct file *f);
73925-};
73926+} __do_const;
73927+typedef struct file_operations __no_const file_operations_no_const;
73928
73929 struct inode_operations {
73930 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
73931@@ -2745,4 +2746,14 @@ static inline bool dir_relax(struct inode *inode)
73932 return !IS_DEADDIR(inode);
73933 }
73934
73935+static inline bool is_sidechannel_device(const struct inode *inode)
73936+{
73937+#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
73938+ umode_t mode = inode->i_mode;
73939+ return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
73940+#else
73941+ return false;
73942+#endif
73943+}
73944+
73945 #endif /* _LINUX_FS_H */
73946diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
73947index 0efc3e6..e0e1e5f 100644
73948--- a/include/linux/fs_struct.h
73949+++ b/include/linux/fs_struct.h
73950@@ -6,7 +6,7 @@
73951 #include <linux/seqlock.h>
73952
73953 struct fs_struct {
73954- int users;
73955+ atomic_t users;
73956 spinlock_t lock;
73957 seqcount_t seq;
73958 int umask;
73959diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
73960index 7823e9e..56b6f2f 100644
73961--- a/include/linux/fscache-cache.h
73962+++ b/include/linux/fscache-cache.h
73963@@ -113,7 +113,7 @@ struct fscache_operation {
73964 fscache_operation_release_t release;
73965 };
73966
73967-extern atomic_t fscache_op_debug_id;
73968+extern atomic_unchecked_t fscache_op_debug_id;
73969 extern void fscache_op_work_func(struct work_struct *work);
73970
73971 extern void fscache_enqueue_operation(struct fscache_operation *);
73972@@ -135,7 +135,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
73973 INIT_WORK(&op->work, fscache_op_work_func);
73974 atomic_set(&op->usage, 1);
73975 op->state = FSCACHE_OP_ST_INITIALISED;
73976- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
73977+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
73978 op->processor = processor;
73979 op->release = release;
73980 INIT_LIST_HEAD(&op->pend_link);
73981diff --git a/include/linux/fscache.h b/include/linux/fscache.h
73982index 19b4645..3b73dfc 100644
73983--- a/include/linux/fscache.h
73984+++ b/include/linux/fscache.h
73985@@ -152,7 +152,7 @@ struct fscache_cookie_def {
73986 * - this is mandatory for any object that may have data
73987 */
73988 void (*now_uncached)(void *cookie_netfs_data);
73989-};
73990+} __do_const;
73991
73992 /*
73993 * fscache cached network filesystem type
73994diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
73995index 1c804b0..1432c2b 100644
73996--- a/include/linux/fsnotify.h
73997+++ b/include/linux/fsnotify.h
73998@@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
73999 struct inode *inode = file_inode(file);
74000 __u32 mask = FS_ACCESS;
74001
74002+ if (is_sidechannel_device(inode))
74003+ return;
74004+
74005 if (S_ISDIR(inode->i_mode))
74006 mask |= FS_ISDIR;
74007
74008@@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
74009 struct inode *inode = file_inode(file);
74010 __u32 mask = FS_MODIFY;
74011
74012+ if (is_sidechannel_device(inode))
74013+ return;
74014+
74015 if (S_ISDIR(inode->i_mode))
74016 mask |= FS_ISDIR;
74017
74018@@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
74019 */
74020 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
74021 {
74022- return kstrdup(name, GFP_KERNEL);
74023+ return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
74024 }
74025
74026 /*
74027diff --git a/include/linux/genhd.h b/include/linux/genhd.h
74028index 9f3c275..8bdff5d 100644
74029--- a/include/linux/genhd.h
74030+++ b/include/linux/genhd.h
74031@@ -194,7 +194,7 @@ struct gendisk {
74032 struct kobject *slave_dir;
74033
74034 struct timer_rand_state *random;
74035- atomic_t sync_io; /* RAID */
74036+ atomic_unchecked_t sync_io; /* RAID */
74037 struct disk_events *ev;
74038 #ifdef CONFIG_BLK_DEV_INTEGRITY
74039 struct blk_integrity *integrity;
74040@@ -435,7 +435,7 @@ extern void disk_flush_events(struct gendisk *disk, unsigned int mask);
74041 extern unsigned int disk_clear_events(struct gendisk *disk, unsigned int mask);
74042
74043 /* drivers/char/random.c */
74044-extern void add_disk_randomness(struct gendisk *disk);
74045+extern void add_disk_randomness(struct gendisk *disk) __latent_entropy;
74046 extern void rand_initialize_disk(struct gendisk *disk);
74047
74048 static inline sector_t get_start_sect(struct block_device *bdev)
74049diff --git a/include/linux/genl_magic_func.h b/include/linux/genl_magic_func.h
74050index 023bc34..b02b46a 100644
74051--- a/include/linux/genl_magic_func.h
74052+++ b/include/linux/genl_magic_func.h
74053@@ -246,7 +246,7 @@ const char *CONCAT_(GENL_MAGIC_FAMILY, _genl_cmd_to_str)(__u8 cmd)
74054 },
74055
74056 #define ZZZ_genl_ops CONCAT_(GENL_MAGIC_FAMILY, _genl_ops)
74057-static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
74058+static struct genl_ops ZZZ_genl_ops[] = {
74059 #include GENL_MAGIC_INCLUDE_FILE
74060 };
74061
74062diff --git a/include/linux/gfp.h b/include/linux/gfp.h
74063index 9b4dd49..61fd41d 100644
74064--- a/include/linux/gfp.h
74065+++ b/include/linux/gfp.h
74066@@ -35,6 +35,13 @@ struct vm_area_struct;
74067 #define ___GFP_NO_KSWAPD 0x400000u
74068 #define ___GFP_OTHER_NODE 0x800000u
74069 #define ___GFP_WRITE 0x1000000u
74070+
74071+#ifdef CONFIG_PAX_USERCOPY_SLABS
74072+#define ___GFP_USERCOPY 0x2000000u
74073+#else
74074+#define ___GFP_USERCOPY 0
74075+#endif
74076+
74077 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
74078
74079 /*
74080@@ -92,6 +99,7 @@ struct vm_area_struct;
74081 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
74082 #define __GFP_KMEMCG ((__force gfp_t)___GFP_KMEMCG) /* Allocation comes from a memcg-accounted resource */
74083 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
74084+#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
74085
74086 /*
74087 * This may seem redundant, but it's a way of annotating false positives vs.
74088@@ -99,7 +107,7 @@ struct vm_area_struct;
74089 */
74090 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
74091
74092-#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
74093+#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
74094 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
74095
74096 /* This equals 0, but use constants in case they ever change */
74097@@ -153,6 +161,8 @@ struct vm_area_struct;
74098 /* 4GB DMA on some platforms */
74099 #define GFP_DMA32 __GFP_DMA32
74100
74101+#define GFP_USERCOPY __GFP_USERCOPY
74102+
74103 /* Convert GFP flags to their corresponding migrate type */
74104 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
74105 {
74106diff --git a/include/linux/gracl.h b/include/linux/gracl.h
74107new file mode 100644
74108index 0000000..edb2cb6
74109--- /dev/null
74110+++ b/include/linux/gracl.h
74111@@ -0,0 +1,340 @@
74112+#ifndef GR_ACL_H
74113+#define GR_ACL_H
74114+
74115+#include <linux/grdefs.h>
74116+#include <linux/resource.h>
74117+#include <linux/capability.h>
74118+#include <linux/dcache.h>
74119+#include <asm/resource.h>
74120+
74121+/* Major status information */
74122+
74123+#define GR_VERSION "grsecurity 3.0"
74124+#define GRSECURITY_VERSION 0x3000
74125+
74126+enum {
74127+ GR_SHUTDOWN = 0,
74128+ GR_ENABLE = 1,
74129+ GR_SPROLE = 2,
74130+ GR_OLDRELOAD = 3,
74131+ GR_SEGVMOD = 4,
74132+ GR_STATUS = 5,
74133+ GR_UNSPROLE = 6,
74134+ GR_PASSSET = 7,
74135+ GR_SPROLEPAM = 8,
74136+ GR_RELOAD = 9,
74137+};
74138+
74139+/* Password setup definitions
74140+ * kernel/grhash.c */
74141+enum {
74142+ GR_PW_LEN = 128,
74143+ GR_SALT_LEN = 16,
74144+ GR_SHA_LEN = 32,
74145+};
74146+
74147+enum {
74148+ GR_SPROLE_LEN = 64,
74149+};
74150+
74151+enum {
74152+ GR_NO_GLOB = 0,
74153+ GR_REG_GLOB,
74154+ GR_CREATE_GLOB
74155+};
74156+
74157+#define GR_NLIMITS 32
74158+
74159+/* Begin Data Structures */
74160+
74161+struct sprole_pw {
74162+ unsigned char *rolename;
74163+ unsigned char salt[GR_SALT_LEN];
74164+ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
74165+};
74166+
74167+struct name_entry {
74168+ __u32 key;
74169+ ino_t inode;
74170+ dev_t device;
74171+ char *name;
74172+ __u16 len;
74173+ __u8 deleted;
74174+ struct name_entry *prev;
74175+ struct name_entry *next;
74176+};
74177+
74178+struct inodev_entry {
74179+ struct name_entry *nentry;
74180+ struct inodev_entry *prev;
74181+ struct inodev_entry *next;
74182+};
74183+
74184+struct acl_role_db {
74185+ struct acl_role_label **r_hash;
74186+ __u32 r_size;
74187+};
74188+
74189+struct inodev_db {
74190+ struct inodev_entry **i_hash;
74191+ __u32 i_size;
74192+};
74193+
74194+struct name_db {
74195+ struct name_entry **n_hash;
74196+ __u32 n_size;
74197+};
74198+
74199+struct crash_uid {
74200+ uid_t uid;
74201+ unsigned long expires;
74202+};
74203+
74204+struct gr_hash_struct {
74205+ void **table;
74206+ void **nametable;
74207+ void *first;
74208+ __u32 table_size;
74209+ __u32 used_size;
74210+ int type;
74211+};
74212+
74213+/* Userspace Grsecurity ACL data structures */
74214+
74215+struct acl_subject_label {
74216+ char *filename;
74217+ ino_t inode;
74218+ dev_t device;
74219+ __u32 mode;
74220+ kernel_cap_t cap_mask;
74221+ kernel_cap_t cap_lower;
74222+ kernel_cap_t cap_invert_audit;
74223+
74224+ struct rlimit res[GR_NLIMITS];
74225+ __u32 resmask;
74226+
74227+ __u8 user_trans_type;
74228+ __u8 group_trans_type;
74229+ uid_t *user_transitions;
74230+ gid_t *group_transitions;
74231+ __u16 user_trans_num;
74232+ __u16 group_trans_num;
74233+
74234+ __u32 sock_families[2];
74235+ __u32 ip_proto[8];
74236+ __u32 ip_type;
74237+ struct acl_ip_label **ips;
74238+ __u32 ip_num;
74239+ __u32 inaddr_any_override;
74240+
74241+ __u32 crashes;
74242+ unsigned long expires;
74243+
74244+ struct acl_subject_label *parent_subject;
74245+ struct gr_hash_struct *hash;
74246+ struct acl_subject_label *prev;
74247+ struct acl_subject_label *next;
74248+
74249+ struct acl_object_label **obj_hash;
74250+ __u32 obj_hash_size;
74251+ __u16 pax_flags;
74252+};
74253+
74254+struct role_allowed_ip {
74255+ __u32 addr;
74256+ __u32 netmask;
74257+
74258+ struct role_allowed_ip *prev;
74259+ struct role_allowed_ip *next;
74260+};
74261+
74262+struct role_transition {
74263+ char *rolename;
74264+
74265+ struct role_transition *prev;
74266+ struct role_transition *next;
74267+};
74268+
74269+struct acl_role_label {
74270+ char *rolename;
74271+ uid_t uidgid;
74272+ __u16 roletype;
74273+
74274+ __u16 auth_attempts;
74275+ unsigned long expires;
74276+
74277+ struct acl_subject_label *root_label;
74278+ struct gr_hash_struct *hash;
74279+
74280+ struct acl_role_label *prev;
74281+ struct acl_role_label *next;
74282+
74283+ struct role_transition *transitions;
74284+ struct role_allowed_ip *allowed_ips;
74285+ uid_t *domain_children;
74286+ __u16 domain_child_num;
74287+
74288+ umode_t umask;
74289+
74290+ struct acl_subject_label **subj_hash;
74291+ __u32 subj_hash_size;
74292+};
74293+
74294+struct user_acl_role_db {
74295+ struct acl_role_label **r_table;
74296+ __u32 num_pointers; /* Number of allocations to track */
74297+ __u32 num_roles; /* Number of roles */
74298+ __u32 num_domain_children; /* Number of domain children */
74299+ __u32 num_subjects; /* Number of subjects */
74300+ __u32 num_objects; /* Number of objects */
74301+};
74302+
74303+struct acl_object_label {
74304+ char *filename;
74305+ ino_t inode;
74306+ dev_t device;
74307+ __u32 mode;
74308+
74309+ struct acl_subject_label *nested;
74310+ struct acl_object_label *globbed;
74311+
74312+ /* next two structures not used */
74313+
74314+ struct acl_object_label *prev;
74315+ struct acl_object_label *next;
74316+};
74317+
74318+struct acl_ip_label {
74319+ char *iface;
74320+ __u32 addr;
74321+ __u32 netmask;
74322+ __u16 low, high;
74323+ __u8 mode;
74324+ __u32 type;
74325+ __u32 proto[8];
74326+
74327+ /* next two structures not used */
74328+
74329+ struct acl_ip_label *prev;
74330+ struct acl_ip_label *next;
74331+};
74332+
74333+struct gr_arg {
74334+ struct user_acl_role_db role_db;
74335+ unsigned char pw[GR_PW_LEN];
74336+ unsigned char salt[GR_SALT_LEN];
74337+ unsigned char sum[GR_SHA_LEN];
74338+ unsigned char sp_role[GR_SPROLE_LEN];
74339+ struct sprole_pw *sprole_pws;
74340+ dev_t segv_device;
74341+ ino_t segv_inode;
74342+ uid_t segv_uid;
74343+ __u16 num_sprole_pws;
74344+ __u16 mode;
74345+};
74346+
74347+struct gr_arg_wrapper {
74348+ struct gr_arg *arg;
74349+ __u32 version;
74350+ __u32 size;
74351+};
74352+
74353+struct subject_map {
74354+ struct acl_subject_label *user;
74355+ struct acl_subject_label *kernel;
74356+ struct subject_map *prev;
74357+ struct subject_map *next;
74358+};
74359+
74360+struct acl_subj_map_db {
74361+ struct subject_map **s_hash;
74362+ __u32 s_size;
74363+};
74364+
74365+struct gr_policy_state {
74366+ struct sprole_pw **acl_special_roles;
74367+ __u16 num_sprole_pws;
74368+ struct acl_role_label *kernel_role;
74369+ struct acl_role_label *role_list;
74370+ struct acl_role_label *default_role;
74371+ struct acl_role_db acl_role_set;
74372+ struct acl_subj_map_db subj_map_set;
74373+ struct name_db name_set;
74374+ struct inodev_db inodev_set;
74375+};
74376+
74377+struct gr_alloc_state {
74378+ unsigned long alloc_stack_next;
74379+ unsigned long alloc_stack_size;
74380+ void **alloc_stack;
74381+};
74382+
74383+struct gr_reload_state {
74384+ struct gr_policy_state oldpolicy;
74385+ struct gr_alloc_state oldalloc;
74386+ struct gr_policy_state newpolicy;
74387+ struct gr_alloc_state newalloc;
74388+ struct gr_policy_state *oldpolicy_ptr;
74389+ struct gr_alloc_state *oldalloc_ptr;
74390+ unsigned char oldmode;
74391+};
74392+
74393+/* End Data Structures Section */
74394+
74395+/* Hash functions generated by empirical testing by Brad Spengler
74396+ Makes good use of the low bits of the inode. Generally 0-1 times
74397+ in loop for successful match. 0-3 for unsuccessful match.
74398+ Shift/add algorithm with modulus of table size and an XOR*/
74399+
74400+static __inline__ unsigned int
74401+gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
74402+{
74403+ return ((((uid + type) << (16 + type)) ^ uid) % sz);
74404+}
74405+
74406+ static __inline__ unsigned int
74407+gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
74408+{
74409+ return ((const unsigned long)userp % sz);
74410+}
74411+
74412+static __inline__ unsigned int
74413+gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
74414+{
74415+ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
74416+}
74417+
74418+static __inline__ unsigned int
74419+gr_nhash(const char *name, const __u16 len, const unsigned int sz)
74420+{
74421+ return full_name_hash((const unsigned char *)name, len) % sz;
74422+}
74423+
74424+#define FOR_EACH_SUBJECT_START(role,subj,iter) \
74425+ subj = NULL; \
74426+ iter = 0; \
74427+ while (iter < role->subj_hash_size) { \
74428+ if (subj == NULL) \
74429+ subj = role->subj_hash[iter]; \
74430+ if (subj == NULL) { \
74431+ iter++; \
74432+ continue; \
74433+ }
74434+
74435+#define FOR_EACH_SUBJECT_END(subj,iter) \
74436+ subj = subj->next; \
74437+ if (subj == NULL) \
74438+ iter++; \
74439+ }
74440+
74441+
74442+#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
74443+ subj = role->hash->first; \
74444+ while (subj != NULL) {
74445+
74446+#define FOR_EACH_NESTED_SUBJECT_END(subj) \
74447+ subj = subj->next; \
74448+ }
74449+
74450+#endif
74451+
74452diff --git a/include/linux/gracl_compat.h b/include/linux/gracl_compat.h
74453new file mode 100644
74454index 0000000..33ebd1f
74455--- /dev/null
74456+++ b/include/linux/gracl_compat.h
74457@@ -0,0 +1,156 @@
74458+#ifndef GR_ACL_COMPAT_H
74459+#define GR_ACL_COMPAT_H
74460+
74461+#include <linux/resource.h>
74462+#include <asm/resource.h>
74463+
74464+struct sprole_pw_compat {
74465+ compat_uptr_t rolename;
74466+ unsigned char salt[GR_SALT_LEN];
74467+ unsigned char sum[GR_SHA_LEN];
74468+};
74469+
74470+struct gr_hash_struct_compat {
74471+ compat_uptr_t table;
74472+ compat_uptr_t nametable;
74473+ compat_uptr_t first;
74474+ __u32 table_size;
74475+ __u32 used_size;
74476+ int type;
74477+};
74478+
74479+struct acl_subject_label_compat {
74480+ compat_uptr_t filename;
74481+ compat_ino_t inode;
74482+ __u32 device;
74483+ __u32 mode;
74484+ kernel_cap_t cap_mask;
74485+ kernel_cap_t cap_lower;
74486+ kernel_cap_t cap_invert_audit;
74487+
74488+ struct compat_rlimit res[GR_NLIMITS];
74489+ __u32 resmask;
74490+
74491+ __u8 user_trans_type;
74492+ __u8 group_trans_type;
74493+ compat_uptr_t user_transitions;
74494+ compat_uptr_t group_transitions;
74495+ __u16 user_trans_num;
74496+ __u16 group_trans_num;
74497+
74498+ __u32 sock_families[2];
74499+ __u32 ip_proto[8];
74500+ __u32 ip_type;
74501+ compat_uptr_t ips;
74502+ __u32 ip_num;
74503+ __u32 inaddr_any_override;
74504+
74505+ __u32 crashes;
74506+ compat_ulong_t expires;
74507+
74508+ compat_uptr_t parent_subject;
74509+ compat_uptr_t hash;
74510+ compat_uptr_t prev;
74511+ compat_uptr_t next;
74512+
74513+ compat_uptr_t obj_hash;
74514+ __u32 obj_hash_size;
74515+ __u16 pax_flags;
74516+};
74517+
74518+struct role_allowed_ip_compat {
74519+ __u32 addr;
74520+ __u32 netmask;
74521+
74522+ compat_uptr_t prev;
74523+ compat_uptr_t next;
74524+};
74525+
74526+struct role_transition_compat {
74527+ compat_uptr_t rolename;
74528+
74529+ compat_uptr_t prev;
74530+ compat_uptr_t next;
74531+};
74532+
74533+struct acl_role_label_compat {
74534+ compat_uptr_t rolename;
74535+ uid_t uidgid;
74536+ __u16 roletype;
74537+
74538+ __u16 auth_attempts;
74539+ compat_ulong_t expires;
74540+
74541+ compat_uptr_t root_label;
74542+ compat_uptr_t hash;
74543+
74544+ compat_uptr_t prev;
74545+ compat_uptr_t next;
74546+
74547+ compat_uptr_t transitions;
74548+ compat_uptr_t allowed_ips;
74549+ compat_uptr_t domain_children;
74550+ __u16 domain_child_num;
74551+
74552+ umode_t umask;
74553+
74554+ compat_uptr_t subj_hash;
74555+ __u32 subj_hash_size;
74556+};
74557+
74558+struct user_acl_role_db_compat {
74559+ compat_uptr_t r_table;
74560+ __u32 num_pointers;
74561+ __u32 num_roles;
74562+ __u32 num_domain_children;
74563+ __u32 num_subjects;
74564+ __u32 num_objects;
74565+};
74566+
74567+struct acl_object_label_compat {
74568+ compat_uptr_t filename;
74569+ compat_ino_t inode;
74570+ __u32 device;
74571+ __u32 mode;
74572+
74573+ compat_uptr_t nested;
74574+ compat_uptr_t globbed;
74575+
74576+ compat_uptr_t prev;
74577+ compat_uptr_t next;
74578+};
74579+
74580+struct acl_ip_label_compat {
74581+ compat_uptr_t iface;
74582+ __u32 addr;
74583+ __u32 netmask;
74584+ __u16 low, high;
74585+ __u8 mode;
74586+ __u32 type;
74587+ __u32 proto[8];
74588+
74589+ compat_uptr_t prev;
74590+ compat_uptr_t next;
74591+};
74592+
74593+struct gr_arg_compat {
74594+ struct user_acl_role_db_compat role_db;
74595+ unsigned char pw[GR_PW_LEN];
74596+ unsigned char salt[GR_SALT_LEN];
74597+ unsigned char sum[GR_SHA_LEN];
74598+ unsigned char sp_role[GR_SPROLE_LEN];
74599+ compat_uptr_t sprole_pws;
74600+ __u32 segv_device;
74601+ compat_ino_t segv_inode;
74602+ uid_t segv_uid;
74603+ __u16 num_sprole_pws;
74604+ __u16 mode;
74605+};
74606+
74607+struct gr_arg_wrapper_compat {
74608+ compat_uptr_t arg;
74609+ __u32 version;
74610+ __u32 size;
74611+};
74612+
74613+#endif
74614diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
74615new file mode 100644
74616index 0000000..323ecf2
74617--- /dev/null
74618+++ b/include/linux/gralloc.h
74619@@ -0,0 +1,9 @@
74620+#ifndef __GRALLOC_H
74621+#define __GRALLOC_H
74622+
74623+void acl_free_all(void);
74624+int acl_alloc_stack_init(unsigned long size);
74625+void *acl_alloc(unsigned long len);
74626+void *acl_alloc_num(unsigned long num, unsigned long len);
74627+
74628+#endif
74629diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
74630new file mode 100644
74631index 0000000..be66033
74632--- /dev/null
74633+++ b/include/linux/grdefs.h
74634@@ -0,0 +1,140 @@
74635+#ifndef GRDEFS_H
74636+#define GRDEFS_H
74637+
74638+/* Begin grsecurity status declarations */
74639+
74640+enum {
74641+ GR_READY = 0x01,
74642+ GR_STATUS_INIT = 0x00 // disabled state
74643+};
74644+
74645+/* Begin ACL declarations */
74646+
74647+/* Role flags */
74648+
74649+enum {
74650+ GR_ROLE_USER = 0x0001,
74651+ GR_ROLE_GROUP = 0x0002,
74652+ GR_ROLE_DEFAULT = 0x0004,
74653+ GR_ROLE_SPECIAL = 0x0008,
74654+ GR_ROLE_AUTH = 0x0010,
74655+ GR_ROLE_NOPW = 0x0020,
74656+ GR_ROLE_GOD = 0x0040,
74657+ GR_ROLE_LEARN = 0x0080,
74658+ GR_ROLE_TPE = 0x0100,
74659+ GR_ROLE_DOMAIN = 0x0200,
74660+ GR_ROLE_PAM = 0x0400,
74661+ GR_ROLE_PERSIST = 0x0800
74662+};
74663+
74664+/* ACL Subject and Object mode flags */
74665+enum {
74666+ GR_DELETED = 0x80000000
74667+};
74668+
74669+/* ACL Object-only mode flags */
74670+enum {
74671+ GR_READ = 0x00000001,
74672+ GR_APPEND = 0x00000002,
74673+ GR_WRITE = 0x00000004,
74674+ GR_EXEC = 0x00000008,
74675+ GR_FIND = 0x00000010,
74676+ GR_INHERIT = 0x00000020,
74677+ GR_SETID = 0x00000040,
74678+ GR_CREATE = 0x00000080,
74679+ GR_DELETE = 0x00000100,
74680+ GR_LINK = 0x00000200,
74681+ GR_AUDIT_READ = 0x00000400,
74682+ GR_AUDIT_APPEND = 0x00000800,
74683+ GR_AUDIT_WRITE = 0x00001000,
74684+ GR_AUDIT_EXEC = 0x00002000,
74685+ GR_AUDIT_FIND = 0x00004000,
74686+ GR_AUDIT_INHERIT= 0x00008000,
74687+ GR_AUDIT_SETID = 0x00010000,
74688+ GR_AUDIT_CREATE = 0x00020000,
74689+ GR_AUDIT_DELETE = 0x00040000,
74690+ GR_AUDIT_LINK = 0x00080000,
74691+ GR_PTRACERD = 0x00100000,
74692+ GR_NOPTRACE = 0x00200000,
74693+ GR_SUPPRESS = 0x00400000,
74694+ GR_NOLEARN = 0x00800000,
74695+ GR_INIT_TRANSFER= 0x01000000
74696+};
74697+
74698+#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
74699+ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
74700+ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
74701+
74702+/* ACL subject-only mode flags */
74703+enum {
74704+ GR_KILL = 0x00000001,
74705+ GR_VIEW = 0x00000002,
74706+ GR_PROTECTED = 0x00000004,
74707+ GR_LEARN = 0x00000008,
74708+ GR_OVERRIDE = 0x00000010,
74709+ /* just a placeholder, this mode is only used in userspace */
74710+ GR_DUMMY = 0x00000020,
74711+ GR_PROTSHM = 0x00000040,
74712+ GR_KILLPROC = 0x00000080,
74713+ GR_KILLIPPROC = 0x00000100,
74714+ /* just a placeholder, this mode is only used in userspace */
74715+ GR_NOTROJAN = 0x00000200,
74716+ GR_PROTPROCFD = 0x00000400,
74717+ GR_PROCACCT = 0x00000800,
74718+ GR_RELAXPTRACE = 0x00001000,
74719+ //GR_NESTED = 0x00002000,
74720+ GR_INHERITLEARN = 0x00004000,
74721+ GR_PROCFIND = 0x00008000,
74722+ GR_POVERRIDE = 0x00010000,
74723+ GR_KERNELAUTH = 0x00020000,
74724+ GR_ATSECURE = 0x00040000,
74725+ GR_SHMEXEC = 0x00080000
74726+};
74727+
74728+enum {
74729+ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
74730+ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
74731+ GR_PAX_ENABLE_MPROTECT = 0x0004,
74732+ GR_PAX_ENABLE_RANDMMAP = 0x0008,
74733+ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
74734+ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
74735+ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
74736+ GR_PAX_DISABLE_MPROTECT = 0x0400,
74737+ GR_PAX_DISABLE_RANDMMAP = 0x0800,
74738+ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
74739+};
74740+
74741+enum {
74742+ GR_ID_USER = 0x01,
74743+ GR_ID_GROUP = 0x02,
74744+};
74745+
74746+enum {
74747+ GR_ID_ALLOW = 0x01,
74748+ GR_ID_DENY = 0x02,
74749+};
74750+
74751+#define GR_CRASH_RES 31
74752+#define GR_UIDTABLE_MAX 500
74753+
74754+/* begin resource learning section */
74755+enum {
74756+ GR_RLIM_CPU_BUMP = 60,
74757+ GR_RLIM_FSIZE_BUMP = 50000,
74758+ GR_RLIM_DATA_BUMP = 10000,
74759+ GR_RLIM_STACK_BUMP = 1000,
74760+ GR_RLIM_CORE_BUMP = 10000,
74761+ GR_RLIM_RSS_BUMP = 500000,
74762+ GR_RLIM_NPROC_BUMP = 1,
74763+ GR_RLIM_NOFILE_BUMP = 5,
74764+ GR_RLIM_MEMLOCK_BUMP = 50000,
74765+ GR_RLIM_AS_BUMP = 500000,
74766+ GR_RLIM_LOCKS_BUMP = 2,
74767+ GR_RLIM_SIGPENDING_BUMP = 5,
74768+ GR_RLIM_MSGQUEUE_BUMP = 10000,
74769+ GR_RLIM_NICE_BUMP = 1,
74770+ GR_RLIM_RTPRIO_BUMP = 1,
74771+ GR_RLIM_RTTIME_BUMP = 1000000
74772+};
74773+
74774+#endif
74775diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
74776new file mode 100644
74777index 0000000..d25522e
74778--- /dev/null
74779+++ b/include/linux/grinternal.h
74780@@ -0,0 +1,229 @@
74781+#ifndef __GRINTERNAL_H
74782+#define __GRINTERNAL_H
74783+
74784+#ifdef CONFIG_GRKERNSEC
74785+
74786+#include <linux/fs.h>
74787+#include <linux/mnt_namespace.h>
74788+#include <linux/nsproxy.h>
74789+#include <linux/gracl.h>
74790+#include <linux/grdefs.h>
74791+#include <linux/grmsg.h>
74792+
74793+void gr_add_learn_entry(const char *fmt, ...)
74794+ __attribute__ ((format (printf, 1, 2)));
74795+__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
74796+ const struct vfsmount *mnt);
74797+__u32 gr_check_create(const struct dentry *new_dentry,
74798+ const struct dentry *parent,
74799+ const struct vfsmount *mnt, const __u32 mode);
74800+int gr_check_protected_task(const struct task_struct *task);
74801+__u32 to_gr_audit(const __u32 reqmode);
74802+int gr_set_acls(const int type);
74803+int gr_acl_is_enabled(void);
74804+char gr_roletype_to_char(void);
74805+
74806+void gr_handle_alertkill(struct task_struct *task);
74807+char *gr_to_filename(const struct dentry *dentry,
74808+ const struct vfsmount *mnt);
74809+char *gr_to_filename1(const struct dentry *dentry,
74810+ const struct vfsmount *mnt);
74811+char *gr_to_filename2(const struct dentry *dentry,
74812+ const struct vfsmount *mnt);
74813+char *gr_to_filename3(const struct dentry *dentry,
74814+ const struct vfsmount *mnt);
74815+
74816+extern int grsec_enable_ptrace_readexec;
74817+extern int grsec_enable_harden_ptrace;
74818+extern int grsec_enable_link;
74819+extern int grsec_enable_fifo;
74820+extern int grsec_enable_execve;
74821+extern int grsec_enable_shm;
74822+extern int grsec_enable_execlog;
74823+extern int grsec_enable_signal;
74824+extern int grsec_enable_audit_ptrace;
74825+extern int grsec_enable_forkfail;
74826+extern int grsec_enable_time;
74827+extern int grsec_enable_rofs;
74828+extern int grsec_deny_new_usb;
74829+extern int grsec_enable_chroot_shmat;
74830+extern int grsec_enable_chroot_mount;
74831+extern int grsec_enable_chroot_double;
74832+extern int grsec_enable_chroot_pivot;
74833+extern int grsec_enable_chroot_chdir;
74834+extern int grsec_enable_chroot_chmod;
74835+extern int grsec_enable_chroot_mknod;
74836+extern int grsec_enable_chroot_fchdir;
74837+extern int grsec_enable_chroot_nice;
74838+extern int grsec_enable_chroot_execlog;
74839+extern int grsec_enable_chroot_caps;
74840+extern int grsec_enable_chroot_sysctl;
74841+extern int grsec_enable_chroot_unix;
74842+extern int grsec_enable_symlinkown;
74843+extern kgid_t grsec_symlinkown_gid;
74844+extern int grsec_enable_tpe;
74845+extern kgid_t grsec_tpe_gid;
74846+extern int grsec_enable_tpe_all;
74847+extern int grsec_enable_tpe_invert;
74848+extern int grsec_enable_socket_all;
74849+extern kgid_t grsec_socket_all_gid;
74850+extern int grsec_enable_socket_client;
74851+extern kgid_t grsec_socket_client_gid;
74852+extern int grsec_enable_socket_server;
74853+extern kgid_t grsec_socket_server_gid;
74854+extern kgid_t grsec_audit_gid;
74855+extern int grsec_enable_group;
74856+extern int grsec_enable_log_rwxmaps;
74857+extern int grsec_enable_mount;
74858+extern int grsec_enable_chdir;
74859+extern int grsec_resource_logging;
74860+extern int grsec_enable_blackhole;
74861+extern int grsec_lastack_retries;
74862+extern int grsec_enable_brute;
74863+extern int grsec_enable_harden_ipc;
74864+extern int grsec_lock;
74865+
74866+extern spinlock_t grsec_alert_lock;
74867+extern unsigned long grsec_alert_wtime;
74868+extern unsigned long grsec_alert_fyet;
74869+
74870+extern spinlock_t grsec_audit_lock;
74871+
74872+extern rwlock_t grsec_exec_file_lock;
74873+
74874+#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
74875+ gr_to_filename2((tsk)->exec_file->f_path.dentry, \
74876+ (tsk)->exec_file->f_path.mnt) : "/")
74877+
74878+#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
74879+ gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
74880+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
74881+
74882+#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
74883+ gr_to_filename((tsk)->exec_file->f_path.dentry, \
74884+ (tsk)->exec_file->f_path.mnt) : "/")
74885+
74886+#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
74887+ gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
74888+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
74889+
74890+#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
74891+
74892+#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
74893+
74894+static inline bool gr_is_same_file(const struct file *file1, const struct file *file2)
74895+{
74896+ if (file1 && file2) {
74897+ const struct inode *inode1 = file1->f_path.dentry->d_inode;
74898+ const struct inode *inode2 = file2->f_path.dentry->d_inode;
74899+ if (inode1->i_ino == inode2->i_ino && inode1->i_sb->s_dev == inode2->i_sb->s_dev)
74900+ return true;
74901+ }
74902+
74903+ return false;
74904+}
74905+
74906+#define GR_CHROOT_CAPS {{ \
74907+ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
74908+ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
74909+ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
74910+ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
74911+ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
74912+ CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
74913+ CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
74914+
74915+#define security_learn(normal_msg,args...) \
74916+({ \
74917+ read_lock(&grsec_exec_file_lock); \
74918+ gr_add_learn_entry(normal_msg "\n", ## args); \
74919+ read_unlock(&grsec_exec_file_lock); \
74920+})
74921+
74922+enum {
74923+ GR_DO_AUDIT,
74924+ GR_DONT_AUDIT,
74925+ /* used for non-audit messages that we shouldn't kill the task on */
74926+ GR_DONT_AUDIT_GOOD
74927+};
74928+
74929+enum {
74930+ GR_TTYSNIFF,
74931+ GR_RBAC,
74932+ GR_RBAC_STR,
74933+ GR_STR_RBAC,
74934+ GR_RBAC_MODE2,
74935+ GR_RBAC_MODE3,
74936+ GR_FILENAME,
74937+ GR_SYSCTL_HIDDEN,
74938+ GR_NOARGS,
74939+ GR_ONE_INT,
74940+ GR_ONE_INT_TWO_STR,
74941+ GR_ONE_STR,
74942+ GR_STR_INT,
74943+ GR_TWO_STR_INT,
74944+ GR_TWO_INT,
74945+ GR_TWO_U64,
74946+ GR_THREE_INT,
74947+ GR_FIVE_INT_TWO_STR,
74948+ GR_TWO_STR,
74949+ GR_THREE_STR,
74950+ GR_FOUR_STR,
74951+ GR_STR_FILENAME,
74952+ GR_FILENAME_STR,
74953+ GR_FILENAME_TWO_INT,
74954+ GR_FILENAME_TWO_INT_STR,
74955+ GR_TEXTREL,
74956+ GR_PTRACE,
74957+ GR_RESOURCE,
74958+ GR_CAP,
74959+ GR_SIG,
74960+ GR_SIG2,
74961+ GR_CRASH1,
74962+ GR_CRASH2,
74963+ GR_PSACCT,
74964+ GR_RWXMAP,
74965+ GR_RWXMAPVMA
74966+};
74967+
74968+#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
74969+#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
74970+#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
74971+#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
74972+#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
74973+#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
74974+#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)
74975+#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
74976+#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
74977+#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
74978+#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
74979+#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
74980+#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
74981+#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
74982+#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
74983+#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
74984+#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)
74985+#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
74986+#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
74987+#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
74988+#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
74989+#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
74990+#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
74991+#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
74992+#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)
74993+#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
74994+#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
74995+#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
74996+#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
74997+#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
74998+#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
74999+#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
75000+#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
75001+#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)
75002+#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
75003+#define gr_log_rwxmap_vma(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAPVMA, str)
75004+
75005+void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
75006+
75007+#endif
75008+
75009+#endif
75010diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
75011new file mode 100644
75012index 0000000..378a81a
75013--- /dev/null
75014+++ b/include/linux/grmsg.h
75015@@ -0,0 +1,114 @@
75016+#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"
75017+#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"
75018+#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
75019+#define GR_STOPMOD_MSG "denied modification of module state by "
75020+#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
75021+#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
75022+#define GR_IOPERM_MSG "denied use of ioperm() by "
75023+#define GR_IOPL_MSG "denied use of iopl() by "
75024+#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
75025+#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
75026+#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
75027+#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
75028+#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
75029+#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"
75030+#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"
75031+#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
75032+#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
75033+#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
75034+#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
75035+#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
75036+#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
75037+#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
75038+#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
75039+#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
75040+#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
75041+#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
75042+#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
75043+#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
75044+#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
75045+#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
75046+#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
75047+#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
75048+#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
75049+#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
75050+#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
75051+#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
75052+#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
75053+#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
75054+#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
75055+#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
75056+#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
75057+#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
75058+#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
75059+#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
75060+#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
75061+#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
75062+#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
75063+#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
75064+#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
75065+#define GR_INITF_ACL_MSG "init_variables() failed %s by "
75066+#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"
75067+#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
75068+#define GR_SHUTS_ACL_MSG "shutdown auth success for "
75069+#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
75070+#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
75071+#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
75072+#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
75073+#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
75074+#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
75075+#define GR_ENABLEF_ACL_MSG "unable to load %s for "
75076+#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
75077+#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
75078+#define GR_RELOADF_ACL_MSG "failed reload of %s for "
75079+#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
75080+#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
75081+#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
75082+#define GR_SPROLEF_ACL_MSG "special role %s failure for "
75083+#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
75084+#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
75085+#define GR_INVMODE_ACL_MSG "invalid mode %d by "
75086+#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
75087+#define GR_FAILFORK_MSG "failed fork with errno %s by "
75088+#define GR_NICE_CHROOT_MSG "denied priority change by "
75089+#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
75090+#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
75091+#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
75092+#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
75093+#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
75094+#define GR_TIME_MSG "time set by "
75095+#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
75096+#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
75097+#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
75098+#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
75099+#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
75100+#define GR_BIND_MSG "denied bind() by "
75101+#define GR_CONNECT_MSG "denied connect() by "
75102+#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
75103+#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
75104+#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"
75105+#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
75106+#define GR_CAP_ACL_MSG "use of %s denied for "
75107+#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
75108+#define GR_CAP_ACL_MSG2 "use of %s permitted for "
75109+#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
75110+#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
75111+#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
75112+#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
75113+#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
75114+#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
75115+#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
75116+#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
75117+#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
75118+#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
75119+#define GR_TEXTREL_AUDIT_MSG "denied text relocation in %.950s, VMA:0x%08lx 0x%08lx by "
75120+#define GR_PTGNUSTACK_MSG "denied marking stack executable as requested by PT_GNU_STACK marking in %.950s by "
75121+#define GR_VM86_MSG "denied use of vm86 by "
75122+#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
75123+#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
75124+#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
75125+#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
75126+#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
75127+#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 "
75128+#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 "
75129+#define GR_IPC_DENIED_MSG "denied %s of globally-%sable IPC with creator uid %u by "
75130diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
75131new file mode 100644
75132index 0000000..b2edfb1
75133--- /dev/null
75134+++ b/include/linux/grsecurity.h
75135@@ -0,0 +1,243 @@
75136+#ifndef GR_SECURITY_H
75137+#define GR_SECURITY_H
75138+#include <linux/fs.h>
75139+#include <linux/fs_struct.h>
75140+#include <linux/binfmts.h>
75141+#include <linux/gracl.h>
75142+
75143+/* notify of brain-dead configs */
75144+#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
75145+#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
75146+#endif
75147+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
75148+#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
75149+#endif
75150+#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
75151+#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
75152+#endif
75153+#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
75154+#error "CONFIG_PAX enabled, but no PaX options are enabled."
75155+#endif
75156+
75157+int gr_handle_new_usb(void);
75158+
75159+void gr_handle_brute_attach(unsigned long mm_flags);
75160+void gr_handle_brute_check(void);
75161+void gr_handle_kernel_exploit(void);
75162+
75163+char gr_roletype_to_char(void);
75164+
75165+int gr_acl_enable_at_secure(void);
75166+
75167+int gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs);
75168+int gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs);
75169+
75170+void gr_del_task_from_ip_table(struct task_struct *p);
75171+
75172+int gr_pid_is_chrooted(struct task_struct *p);
75173+int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
75174+int gr_handle_chroot_nice(void);
75175+int gr_handle_chroot_sysctl(const int op);
75176+int gr_handle_chroot_setpriority(struct task_struct *p,
75177+ const int niceval);
75178+int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
75179+int gr_handle_chroot_chroot(const struct dentry *dentry,
75180+ const struct vfsmount *mnt);
75181+void gr_handle_chroot_chdir(const struct path *path);
75182+int gr_handle_chroot_chmod(const struct dentry *dentry,
75183+ const struct vfsmount *mnt, const int mode);
75184+int gr_handle_chroot_mknod(const struct dentry *dentry,
75185+ const struct vfsmount *mnt, const int mode);
75186+int gr_handle_chroot_mount(const struct dentry *dentry,
75187+ const struct vfsmount *mnt,
75188+ const char *dev_name);
75189+int gr_handle_chroot_pivot(void);
75190+int gr_handle_chroot_unix(const pid_t pid);
75191+
75192+int gr_handle_rawio(const struct inode *inode);
75193+
75194+void gr_handle_ioperm(void);
75195+void gr_handle_iopl(void);
75196+
75197+umode_t gr_acl_umask(void);
75198+
75199+int gr_tpe_allow(const struct file *file);
75200+
75201+void gr_set_chroot_entries(struct task_struct *task, const struct path *path);
75202+void gr_clear_chroot_entries(struct task_struct *task);
75203+
75204+void gr_log_forkfail(const int retval);
75205+void gr_log_timechange(void);
75206+void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
75207+void gr_log_chdir(const struct dentry *dentry,
75208+ const struct vfsmount *mnt);
75209+void gr_log_chroot_exec(const struct dentry *dentry,
75210+ const struct vfsmount *mnt);
75211+void gr_log_remount(const char *devname, const int retval);
75212+void gr_log_unmount(const char *devname, const int retval);
75213+void gr_log_mount(const char *from, const char *to, const int retval);
75214+void gr_log_textrel(struct vm_area_struct *vma);
75215+void gr_log_ptgnustack(struct file *file);
75216+void gr_log_rwxmmap(struct file *file);
75217+void gr_log_rwxmprotect(struct vm_area_struct *vma);
75218+
75219+int gr_handle_follow_link(const struct inode *parent,
75220+ const struct inode *inode,
75221+ const struct dentry *dentry,
75222+ const struct vfsmount *mnt);
75223+int gr_handle_fifo(const struct dentry *dentry,
75224+ const struct vfsmount *mnt,
75225+ const struct dentry *dir, const int flag,
75226+ const int acc_mode);
75227+int gr_handle_hardlink(const struct dentry *dentry,
75228+ const struct vfsmount *mnt,
75229+ struct inode *inode,
75230+ const int mode, const struct filename *to);
75231+
75232+int gr_is_capable(const int cap);
75233+int gr_is_capable_nolog(const int cap);
75234+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
75235+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
75236+
75237+void gr_copy_label(struct task_struct *tsk);
75238+void gr_handle_crash(struct task_struct *task, const int sig);
75239+int gr_handle_signal(const struct task_struct *p, const int sig);
75240+int gr_check_crash_uid(const kuid_t uid);
75241+int gr_check_protected_task(const struct task_struct *task);
75242+int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
75243+int gr_acl_handle_mmap(const struct file *file,
75244+ const unsigned long prot);
75245+int gr_acl_handle_mprotect(const struct file *file,
75246+ const unsigned long prot);
75247+int gr_check_hidden_task(const struct task_struct *tsk);
75248+__u32 gr_acl_handle_truncate(const struct dentry *dentry,
75249+ const struct vfsmount *mnt);
75250+__u32 gr_acl_handle_utime(const struct dentry *dentry,
75251+ const struct vfsmount *mnt);
75252+__u32 gr_acl_handle_access(const struct dentry *dentry,
75253+ const struct vfsmount *mnt, const int fmode);
75254+__u32 gr_acl_handle_chmod(const struct dentry *dentry,
75255+ const struct vfsmount *mnt, umode_t *mode);
75256+__u32 gr_acl_handle_chown(const struct dentry *dentry,
75257+ const struct vfsmount *mnt);
75258+__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
75259+ const struct vfsmount *mnt);
75260+int gr_handle_ptrace(struct task_struct *task, const long request);
75261+int gr_handle_proc_ptrace(struct task_struct *task);
75262+__u32 gr_acl_handle_execve(const struct dentry *dentry,
75263+ const struct vfsmount *mnt);
75264+int gr_check_crash_exec(const struct file *filp);
75265+int gr_acl_is_enabled(void);
75266+void gr_set_role_label(struct task_struct *task, const kuid_t uid,
75267+ const kgid_t gid);
75268+int gr_set_proc_label(const struct dentry *dentry,
75269+ const struct vfsmount *mnt,
75270+ const int unsafe_flags);
75271+__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
75272+ const struct vfsmount *mnt);
75273+__u32 gr_acl_handle_open(const struct dentry *dentry,
75274+ const struct vfsmount *mnt, int acc_mode);
75275+__u32 gr_acl_handle_creat(const struct dentry *dentry,
75276+ const struct dentry *p_dentry,
75277+ const struct vfsmount *p_mnt,
75278+ int open_flags, int acc_mode, const int imode);
75279+void gr_handle_create(const struct dentry *dentry,
75280+ const struct vfsmount *mnt);
75281+void gr_handle_proc_create(const struct dentry *dentry,
75282+ const struct inode *inode);
75283+__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
75284+ const struct dentry *parent_dentry,
75285+ const struct vfsmount *parent_mnt,
75286+ const int mode);
75287+__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
75288+ const struct dentry *parent_dentry,
75289+ const struct vfsmount *parent_mnt);
75290+__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
75291+ const struct vfsmount *mnt);
75292+void gr_handle_delete(const ino_t ino, const dev_t dev);
75293+__u32 gr_acl_handle_unlink(const struct dentry *dentry,
75294+ const struct vfsmount *mnt);
75295+__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
75296+ const struct dentry *parent_dentry,
75297+ const struct vfsmount *parent_mnt,
75298+ const struct filename *from);
75299+__u32 gr_acl_handle_link(const struct dentry *new_dentry,
75300+ const struct dentry *parent_dentry,
75301+ const struct vfsmount *parent_mnt,
75302+ const struct dentry *old_dentry,
75303+ const struct vfsmount *old_mnt, const struct filename *to);
75304+int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
75305+int gr_acl_handle_rename(struct dentry *new_dentry,
75306+ struct dentry *parent_dentry,
75307+ const struct vfsmount *parent_mnt,
75308+ struct dentry *old_dentry,
75309+ struct inode *old_parent_inode,
75310+ struct vfsmount *old_mnt, const struct filename *newname);
75311+void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
75312+ struct dentry *old_dentry,
75313+ struct dentry *new_dentry,
75314+ struct vfsmount *mnt, const __u8 replace);
75315+__u32 gr_check_link(const struct dentry *new_dentry,
75316+ const struct dentry *parent_dentry,
75317+ const struct vfsmount *parent_mnt,
75318+ const struct dentry *old_dentry,
75319+ const struct vfsmount *old_mnt);
75320+int gr_acl_handle_filldir(const struct file *file, const char *name,
75321+ const unsigned int namelen, const ino_t ino);
75322+
75323+__u32 gr_acl_handle_unix(const struct dentry *dentry,
75324+ const struct vfsmount *mnt);
75325+void gr_acl_handle_exit(void);
75326+void gr_acl_handle_psacct(struct task_struct *task, const long code);
75327+int gr_acl_handle_procpidmem(const struct task_struct *task);
75328+int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
75329+int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
75330+void gr_audit_ptrace(struct task_struct *task);
75331+dev_t gr_get_dev_from_dentry(struct dentry *dentry);
75332+void gr_put_exec_file(struct task_struct *task);
75333+
75334+int gr_ptrace_readexec(struct file *file, int unsafe_flags);
75335+
75336+#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
75337+extern void gr_learn_resource(const struct task_struct *task, const int res,
75338+ const unsigned long wanted, const int gt);
75339+#else
75340+static inline void gr_learn_resource(const struct task_struct *task, const int res,
75341+ const unsigned long wanted, const int gt)
75342+{
75343+}
75344+#endif
75345+
75346+#ifdef CONFIG_GRKERNSEC_RESLOG
75347+extern void gr_log_resource(const struct task_struct *task, const int res,
75348+ const unsigned long wanted, const int gt);
75349+#else
75350+static inline void gr_log_resource(const struct task_struct *task, const int res,
75351+ const unsigned long wanted, const int gt)
75352+{
75353+}
75354+#endif
75355+
75356+#ifdef CONFIG_GRKERNSEC
75357+void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
75358+void gr_handle_vm86(void);
75359+void gr_handle_mem_readwrite(u64 from, u64 to);
75360+
75361+void gr_log_badprocpid(const char *entry);
75362+
75363+extern int grsec_enable_dmesg;
75364+extern int grsec_disable_privio;
75365+
75366+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
75367+extern kgid_t grsec_proc_gid;
75368+#endif
75369+
75370+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
75371+extern int grsec_enable_chroot_findtask;
75372+#endif
75373+#ifdef CONFIG_GRKERNSEC_SETXID
75374+extern int grsec_enable_setxid;
75375+#endif
75376+#endif
75377+
75378+#endif
75379diff --git a/include/linux/grsock.h b/include/linux/grsock.h
75380new file mode 100644
75381index 0000000..e7ffaaf
75382--- /dev/null
75383+++ b/include/linux/grsock.h
75384@@ -0,0 +1,19 @@
75385+#ifndef __GRSOCK_H
75386+#define __GRSOCK_H
75387+
75388+extern void gr_attach_curr_ip(const struct sock *sk);
75389+extern int gr_handle_sock_all(const int family, const int type,
75390+ const int protocol);
75391+extern int gr_handle_sock_server(const struct sockaddr *sck);
75392+extern int gr_handle_sock_server_other(const struct sock *sck);
75393+extern int gr_handle_sock_client(const struct sockaddr *sck);
75394+extern int gr_search_connect(struct socket * sock,
75395+ struct sockaddr_in * addr);
75396+extern int gr_search_bind(struct socket * sock,
75397+ struct sockaddr_in * addr);
75398+extern int gr_search_listen(struct socket * sock);
75399+extern int gr_search_accept(struct socket * sock);
75400+extern int gr_search_socket(const int domain, const int type,
75401+ const int protocol);
75402+
75403+#endif
75404diff --git a/include/linux/highmem.h b/include/linux/highmem.h
75405index 7fb31da..08b5114 100644
75406--- a/include/linux/highmem.h
75407+++ b/include/linux/highmem.h
75408@@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
75409 kunmap_atomic(kaddr);
75410 }
75411
75412+static inline void sanitize_highpage(struct page *page)
75413+{
75414+ void *kaddr;
75415+ unsigned long flags;
75416+
75417+ local_irq_save(flags);
75418+ kaddr = kmap_atomic(page);
75419+ clear_page(kaddr);
75420+ kunmap_atomic(kaddr);
75421+ local_irq_restore(flags);
75422+}
75423+
75424 static inline void zero_user_segments(struct page *page,
75425 unsigned start1, unsigned end1,
75426 unsigned start2, unsigned end2)
75427diff --git a/include/linux/hwmon-sysfs.h b/include/linux/hwmon-sysfs.h
75428index 1c7b89a..7dda400 100644
75429--- a/include/linux/hwmon-sysfs.h
75430+++ b/include/linux/hwmon-sysfs.h
75431@@ -25,7 +25,8 @@
75432 struct sensor_device_attribute{
75433 struct device_attribute dev_attr;
75434 int index;
75435-};
75436+} __do_const;
75437+typedef struct sensor_device_attribute __no_const sensor_device_attribute_no_const;
75438 #define to_sensor_dev_attr(_dev_attr) \
75439 container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
75440
75441@@ -41,7 +42,8 @@ struct sensor_device_attribute_2 {
75442 struct device_attribute dev_attr;
75443 u8 index;
75444 u8 nr;
75445-};
75446+} __do_const;
75447+typedef struct sensor_device_attribute_2 __no_const sensor_device_attribute_2_no_const;
75448 #define to_sensor_dev_attr_2(_dev_attr) \
75449 container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
75450
75451diff --git a/include/linux/i2c.h b/include/linux/i2c.h
75452index 2ab11dc..663a3f2 100644
75453--- a/include/linux/i2c.h
75454+++ b/include/linux/i2c.h
75455@@ -366,6 +366,7 @@ struct i2c_algorithm {
75456 /* To determine what the adapter supports */
75457 u32 (*functionality) (struct i2c_adapter *);
75458 };
75459+typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
75460
75461 /**
75462 * struct i2c_bus_recovery_info - I2C bus recovery information
75463diff --git a/include/linux/i2o.h b/include/linux/i2o.h
75464index d23c3c2..eb63c81 100644
75465--- a/include/linux/i2o.h
75466+++ b/include/linux/i2o.h
75467@@ -565,7 +565,7 @@ struct i2o_controller {
75468 struct i2o_device *exec; /* Executive */
75469 #if BITS_PER_LONG == 64
75470 spinlock_t context_list_lock; /* lock for context_list */
75471- atomic_t context_list_counter; /* needed for unique contexts */
75472+ atomic_unchecked_t context_list_counter; /* needed for unique contexts */
75473 struct list_head context_list; /* list of context id's
75474 and pointers */
75475 #endif
75476diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
75477index aff7ad8..3942bbd 100644
75478--- a/include/linux/if_pppox.h
75479+++ b/include/linux/if_pppox.h
75480@@ -76,7 +76,7 @@ struct pppox_proto {
75481 int (*ioctl)(struct socket *sock, unsigned int cmd,
75482 unsigned long arg);
75483 struct module *owner;
75484-};
75485+} __do_const;
75486
75487 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
75488 extern void unregister_pppox_proto(int proto_num);
75489diff --git a/include/linux/init.h b/include/linux/init.h
75490index f1c27a71..7d6010e 100644
75491--- a/include/linux/init.h
75492+++ b/include/linux/init.h
75493@@ -39,9 +39,17 @@
75494 * Also note, that this data cannot be "const".
75495 */
75496
75497+#define add_init_latent_entropy __latent_entropy
75498+
75499+#ifdef CONFIG_MEMORY_HOTPLUG
75500+#define add_meminit_latent_entropy
75501+#else
75502+#define add_meminit_latent_entropy __latent_entropy
75503+#endif
75504+
75505 /* These are for everybody (although not all archs will actually
75506 discard it in modules) */
75507-#define __init __section(.init.text) __cold notrace
75508+#define __init __section(.init.text) __cold notrace add_init_latent_entropy
75509 #define __initdata __section(.init.data)
75510 #define __initconst __constsection(.init.rodata)
75511 #define __exitdata __section(.exit.data)
75512@@ -102,7 +110,7 @@
75513 #define __cpuexitconst
75514
75515 /* Used for MEMORY_HOTPLUG */
75516-#define __meminit __section(.meminit.text) __cold notrace
75517+#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
75518 #define __meminitdata __section(.meminit.data)
75519 #define __meminitconst __constsection(.meminit.rodata)
75520 #define __memexit __section(.memexit.text) __exitused __cold notrace
75521diff --git a/include/linux/init_task.h b/include/linux/init_task.h
75522index 5cd0f09..c9f67cc 100644
75523--- a/include/linux/init_task.h
75524+++ b/include/linux/init_task.h
75525@@ -154,6 +154,12 @@ extern struct task_group root_task_group;
75526
75527 #define INIT_TASK_COMM "swapper"
75528
75529+#ifdef CONFIG_X86
75530+#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
75531+#else
75532+#define INIT_TASK_THREAD_INFO
75533+#endif
75534+
75535 /*
75536 * INIT_TASK is used to set up the first task table, touch at
75537 * your own risk!. Base=0, limit=0x1fffff (=2MB)
75538@@ -193,6 +199,7 @@ extern struct task_group root_task_group;
75539 RCU_POINTER_INITIALIZER(cred, &init_cred), \
75540 .comm = INIT_TASK_COMM, \
75541 .thread = INIT_THREAD, \
75542+ INIT_TASK_THREAD_INFO \
75543 .fs = &init_fs, \
75544 .files = &init_files, \
75545 .signal = &init_signals, \
75546diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
75547index 5e865b5..71bd258 100644
75548--- a/include/linux/interrupt.h
75549+++ b/include/linux/interrupt.h
75550@@ -361,7 +361,7 @@ enum
75551 /* map softirq index to softirq name. update 'softirq_to_name' in
75552 * kernel/softirq.c when adding a new softirq.
75553 */
75554-extern char *softirq_to_name[NR_SOFTIRQS];
75555+extern const char * const softirq_to_name[NR_SOFTIRQS];
75556
75557 /* softirq mask and active fields moved to irq_cpustat_t in
75558 * asm/hardirq.h to get better cache usage. KAO
75559@@ -369,12 +369,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
75560
75561 struct softirq_action
75562 {
75563- void (*action)(struct softirq_action *);
75564-};
75565+ void (*action)(void);
75566+} __no_const;
75567
75568 asmlinkage void do_softirq(void);
75569 asmlinkage void __do_softirq(void);
75570-extern void open_softirq(int nr, void (*action)(struct softirq_action *));
75571+extern void open_softirq(int nr, void (*action)(void));
75572 extern void softirq_init(void);
75573 extern void __raise_softirq_irqoff(unsigned int nr);
75574
75575diff --git a/include/linux/iommu.h b/include/linux/iommu.h
75576index 7ea319e..f9e971d 100644
75577--- a/include/linux/iommu.h
75578+++ b/include/linux/iommu.h
75579@@ -129,7 +129,7 @@ struct iommu_ops {
75580 u32 (*domain_get_windows)(struct iommu_domain *domain);
75581
75582 unsigned long pgsize_bitmap;
75583-};
75584+} __do_const;
75585
75586 #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
75587 #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */
75588diff --git a/include/linux/ioport.h b/include/linux/ioport.h
75589index 89b7c24..382af74 100644
75590--- a/include/linux/ioport.h
75591+++ b/include/linux/ioport.h
75592@@ -161,7 +161,7 @@ struct resource *lookup_resource(struct resource *root, resource_size_t start);
75593 int adjust_resource(struct resource *res, resource_size_t start,
75594 resource_size_t size);
75595 resource_size_t resource_alignment(struct resource *res);
75596-static inline resource_size_t resource_size(const struct resource *res)
75597+static inline resource_size_t __intentional_overflow(-1) resource_size(const struct resource *res)
75598 {
75599 return res->end - res->start + 1;
75600 }
75601diff --git a/include/linux/irq.h b/include/linux/irq.h
75602index 56bb0dc..8ae94d62 100644
75603--- a/include/linux/irq.h
75604+++ b/include/linux/irq.h
75605@@ -333,7 +333,8 @@ struct irq_chip {
75606 void (*irq_print_chip)(struct irq_data *data, struct seq_file *p);
75607
75608 unsigned long flags;
75609-};
75610+} __do_const;
75611+typedef struct irq_chip __no_const irq_chip_no_const;
75612
75613 /*
75614 * irq_chip specific flags
75615diff --git a/include/linux/irqchip/arm-gic.h b/include/linux/irqchip/arm-gic.h
75616index 0e5d9ec..46acb3a 100644
75617--- a/include/linux/irqchip/arm-gic.h
75618+++ b/include/linux/irqchip/arm-gic.h
75619@@ -59,9 +59,11 @@
75620
75621 #ifndef __ASSEMBLY__
75622
75623+#include <linux/irq.h>
75624+
75625 struct device_node;
75626
75627-extern struct irq_chip gic_arch_extn;
75628+extern irq_chip_no_const gic_arch_extn;
75629
75630 void gic_init_bases(unsigned int, int, void __iomem *, void __iomem *,
75631 u32 offset, struct device_node *);
75632diff --git a/include/linux/jiffies.h b/include/linux/jiffies.h
75633index d235e88..8ccbe74 100644
75634--- a/include/linux/jiffies.h
75635+++ b/include/linux/jiffies.h
75636@@ -292,14 +292,14 @@ extern unsigned long preset_lpj;
75637 /*
75638 * Convert various time units to each other:
75639 */
75640-extern unsigned int jiffies_to_msecs(const unsigned long j);
75641-extern unsigned int jiffies_to_usecs(const unsigned long j);
75642-extern unsigned long msecs_to_jiffies(const unsigned int m);
75643-extern unsigned long usecs_to_jiffies(const unsigned int u);
75644-extern unsigned long timespec_to_jiffies(const struct timespec *value);
75645+extern unsigned int jiffies_to_msecs(const unsigned long j) __intentional_overflow(-1);
75646+extern unsigned int jiffies_to_usecs(const unsigned long j) __intentional_overflow(-1);
75647+extern unsigned long msecs_to_jiffies(const unsigned int m) __intentional_overflow(-1);
75648+extern unsigned long usecs_to_jiffies(const unsigned int u) __intentional_overflow(-1);
75649+extern unsigned long timespec_to_jiffies(const struct timespec *value) __intentional_overflow(-1);
75650 extern void jiffies_to_timespec(const unsigned long jiffies,
75651 struct timespec *value);
75652-extern unsigned long timeval_to_jiffies(const struct timeval *value);
75653+extern unsigned long timeval_to_jiffies(const struct timeval *value) __intentional_overflow(-1);
75654 extern void jiffies_to_timeval(const unsigned long jiffies,
75655 struct timeval *value);
75656
75657diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
75658index 6883e19..e854fcb 100644
75659--- a/include/linux/kallsyms.h
75660+++ b/include/linux/kallsyms.h
75661@@ -15,7 +15,8 @@
75662
75663 struct module;
75664
75665-#ifdef CONFIG_KALLSYMS
75666+#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
75667+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
75668 /* Lookup the address for a symbol. Returns 0 if not found. */
75669 unsigned long kallsyms_lookup_name(const char *name);
75670
75671@@ -106,6 +107,21 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
75672 /* Stupid that this does nothing, but I didn't create this mess. */
75673 #define __print_symbol(fmt, addr)
75674 #endif /*CONFIG_KALLSYMS*/
75675+#else /* when included by kallsyms.c, vsnprintf.c, kprobes.c, or
75676+ arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
75677+extern unsigned long kallsyms_lookup_name(const char *name);
75678+extern void __print_symbol(const char *fmt, unsigned long address);
75679+extern int sprint_backtrace(char *buffer, unsigned long address);
75680+extern int sprint_symbol(char *buffer, unsigned long address);
75681+extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
75682+const char *kallsyms_lookup(unsigned long addr,
75683+ unsigned long *symbolsize,
75684+ unsigned long *offset,
75685+ char **modname, char *namebuf);
75686+extern int kallsyms_lookup_size_offset(unsigned long addr,
75687+ unsigned long *symbolsize,
75688+ unsigned long *offset);
75689+#endif
75690
75691 /* This macro allows us to keep printk typechecking */
75692 static __printf(1, 2)
75693diff --git a/include/linux/key-type.h b/include/linux/key-type.h
75694index 518a53a..5e28358 100644
75695--- a/include/linux/key-type.h
75696+++ b/include/linux/key-type.h
75697@@ -125,7 +125,7 @@ struct key_type {
75698 /* internal fields */
75699 struct list_head link; /* link in types list */
75700 struct lock_class_key lock_class; /* key->sem lock class */
75701-};
75702+} __do_const;
75703
75704 extern struct key_type key_type_keyring;
75705
75706diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
75707index c6e091b..a940adf 100644
75708--- a/include/linux/kgdb.h
75709+++ b/include/linux/kgdb.h
75710@@ -52,7 +52,7 @@ extern int kgdb_connected;
75711 extern int kgdb_io_module_registered;
75712
75713 extern atomic_t kgdb_setting_breakpoint;
75714-extern atomic_t kgdb_cpu_doing_single_step;
75715+extern atomic_unchecked_t kgdb_cpu_doing_single_step;
75716
75717 extern struct task_struct *kgdb_usethread;
75718 extern struct task_struct *kgdb_contthread;
75719@@ -254,7 +254,7 @@ struct kgdb_arch {
75720 void (*correct_hw_break)(void);
75721
75722 void (*enable_nmi)(bool on);
75723-};
75724+} __do_const;
75725
75726 /**
75727 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
75728@@ -279,7 +279,7 @@ struct kgdb_io {
75729 void (*pre_exception) (void);
75730 void (*post_exception) (void);
75731 int is_console;
75732-};
75733+} __do_const;
75734
75735 extern struct kgdb_arch arch_kgdb_ops;
75736
75737diff --git a/include/linux/kmod.h b/include/linux/kmod.h
75738index 0555cc6..40116ce 100644
75739--- a/include/linux/kmod.h
75740+++ b/include/linux/kmod.h
75741@@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
75742 * usually useless though. */
75743 extern __printf(2, 3)
75744 int __request_module(bool wait, const char *name, ...);
75745+extern __printf(3, 4)
75746+int ___request_module(bool wait, char *param_name, const char *name, ...);
75747 #define request_module(mod...) __request_module(true, mod)
75748 #define request_module_nowait(mod...) __request_module(false, mod)
75749 #define try_then_request_module(x, mod...) \
75750@@ -57,6 +59,9 @@ struct subprocess_info {
75751 struct work_struct work;
75752 struct completion *complete;
75753 char *path;
75754+#ifdef CONFIG_GRKERNSEC
75755+ char *origpath;
75756+#endif
75757 char **argv;
75758 char **envp;
75759 int wait;
75760diff --git a/include/linux/kobject.h b/include/linux/kobject.h
75761index de6dcbcc..4735f88 100644
75762--- a/include/linux/kobject.h
75763+++ b/include/linux/kobject.h
75764@@ -115,7 +115,7 @@ struct kobj_type {
75765 struct attribute **default_attrs;
75766 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
75767 const void *(*namespace)(struct kobject *kobj);
75768-};
75769+} __do_const;
75770
75771 struct kobj_uevent_env {
75772 char *envp[UEVENT_NUM_ENVP];
75773@@ -138,6 +138,7 @@ struct kobj_attribute {
75774 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
75775 const char *buf, size_t count);
75776 };
75777+typedef struct kobj_attribute __no_const kobj_attribute_no_const;
75778
75779 extern const struct sysfs_ops kobj_sysfs_ops;
75780
75781diff --git a/include/linux/kobject_ns.h b/include/linux/kobject_ns.h
75782index df32d25..fb52e27 100644
75783--- a/include/linux/kobject_ns.h
75784+++ b/include/linux/kobject_ns.h
75785@@ -44,7 +44,7 @@ struct kobj_ns_type_operations {
75786 const void *(*netlink_ns)(struct sock *sk);
75787 const void *(*initial_ns)(void);
75788 void (*drop_ns)(void *);
75789-};
75790+} __do_const;
75791
75792 int kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
75793 int kobj_ns_type_registered(enum kobj_ns_type type);
75794diff --git a/include/linux/kref.h b/include/linux/kref.h
75795index 484604d..0f6c5b6 100644
75796--- a/include/linux/kref.h
75797+++ b/include/linux/kref.h
75798@@ -68,7 +68,7 @@ static inline void kref_get(struct kref *kref)
75799 static inline int kref_sub(struct kref *kref, unsigned int count,
75800 void (*release)(struct kref *kref))
75801 {
75802- WARN_ON(release == NULL);
75803+ BUG_ON(release == NULL);
75804
75805 if (atomic_sub_and_test((int) count, &kref->refcount)) {
75806 release(kref);
75807diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
75808index 0fbbc7a..db081e3 100644
75809--- a/include/linux/kvm_host.h
75810+++ b/include/linux/kvm_host.h
75811@@ -458,7 +458,7 @@ static inline void kvm_irqfd_exit(void)
75812 {
75813 }
75814 #endif
75815-int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
75816+int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
75817 struct module *module);
75818 void kvm_exit(void);
75819
75820@@ -632,7 +632,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
75821 struct kvm_guest_debug *dbg);
75822 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
75823
75824-int kvm_arch_init(void *opaque);
75825+int kvm_arch_init(const void *opaque);
75826 void kvm_arch_exit(void);
75827
75828 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
75829diff --git a/include/linux/libata.h b/include/linux/libata.h
75830index 0e23c26..6ad8c33 100644
75831--- a/include/linux/libata.h
75832+++ b/include/linux/libata.h
75833@@ -972,7 +972,7 @@ struct ata_port_operations {
75834 * fields must be pointers.
75835 */
75836 const struct ata_port_operations *inherits;
75837-};
75838+} __do_const;
75839
75840 struct ata_port_info {
75841 unsigned long flags;
75842diff --git a/include/linux/linkage.h b/include/linux/linkage.h
75843index d3e8ad2..a949f68 100644
75844--- a/include/linux/linkage.h
75845+++ b/include/linux/linkage.h
75846@@ -31,6 +31,7 @@
75847 #endif
75848
75849 #define __page_aligned_data __section(.data..page_aligned) __aligned(PAGE_SIZE)
75850+#define __page_aligned_rodata __read_only __aligned(PAGE_SIZE)
75851 #define __page_aligned_bss __section(.bss..page_aligned) __aligned(PAGE_SIZE)
75852
75853 /*
75854diff --git a/include/linux/list.h b/include/linux/list.h
75855index f4d8a2f..38e6e46 100644
75856--- a/include/linux/list.h
75857+++ b/include/linux/list.h
75858@@ -112,6 +112,19 @@ extern void __list_del_entry(struct list_head *entry);
75859 extern void list_del(struct list_head *entry);
75860 #endif
75861
75862+extern void __pax_list_add(struct list_head *new,
75863+ struct list_head *prev,
75864+ struct list_head *next);
75865+static inline void pax_list_add(struct list_head *new, struct list_head *head)
75866+{
75867+ __pax_list_add(new, head, head->next);
75868+}
75869+static inline void pax_list_add_tail(struct list_head *new, struct list_head *head)
75870+{
75871+ __pax_list_add(new, head->prev, head);
75872+}
75873+extern void pax_list_del(struct list_head *entry);
75874+
75875 /**
75876 * list_replace - replace old entry by new one
75877 * @old : the element to be replaced
75878@@ -145,6 +158,8 @@ static inline void list_del_init(struct list_head *entry)
75879 INIT_LIST_HEAD(entry);
75880 }
75881
75882+extern void pax_list_del_init(struct list_head *entry);
75883+
75884 /**
75885 * list_move - delete from one list and add as another's head
75886 * @list: the entry to move
75887diff --git a/include/linux/math64.h b/include/linux/math64.h
75888index 69ed5f5..243ed51 100644
75889--- a/include/linux/math64.h
75890+++ b/include/linux/math64.h
75891@@ -15,7 +15,7 @@
75892 * This is commonly provided by 32bit archs to provide an optimized 64bit
75893 * divide.
75894 */
75895-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
75896+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
75897 {
75898 *remainder = dividend % divisor;
75899 return dividend / divisor;
75900@@ -42,7 +42,7 @@ static inline u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder)
75901 /**
75902 * div64_u64 - unsigned 64bit divide with 64bit divisor
75903 */
75904-static inline u64 div64_u64(u64 dividend, u64 divisor)
75905+static inline u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
75906 {
75907 return dividend / divisor;
75908 }
75909@@ -61,7 +61,7 @@ static inline s64 div64_s64(s64 dividend, s64 divisor)
75910 #define div64_ul(x, y) div_u64((x), (y))
75911
75912 #ifndef div_u64_rem
75913-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
75914+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
75915 {
75916 *remainder = do_div(dividend, divisor);
75917 return dividend;
75918@@ -77,7 +77,7 @@ extern u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder);
75919 #endif
75920
75921 #ifndef div64_u64
75922-extern u64 div64_u64(u64 dividend, u64 divisor);
75923+extern u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor);
75924 #endif
75925
75926 #ifndef div64_s64
75927@@ -94,7 +94,7 @@ extern s64 div64_s64(s64 dividend, s64 divisor);
75928 * divide.
75929 */
75930 #ifndef div_u64
75931-static inline u64 div_u64(u64 dividend, u32 divisor)
75932+static inline u64 __intentional_overflow(-1) div_u64(u64 dividend, u32 divisor)
75933 {
75934 u32 remainder;
75935 return div_u64_rem(dividend, divisor, &remainder);
75936diff --git a/include/linux/mempolicy.h b/include/linux/mempolicy.h
75937index da6716b..2e31db3 100644
75938--- a/include/linux/mempolicy.h
75939+++ b/include/linux/mempolicy.h
75940@@ -91,6 +91,10 @@ static inline struct mempolicy *mpol_dup(struct mempolicy *pol)
75941 }
75942
75943 #define vma_policy(vma) ((vma)->vm_policy)
75944+static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
75945+{
75946+ vma->vm_policy = pol;
75947+}
75948
75949 static inline void mpol_get(struct mempolicy *pol)
75950 {
75951@@ -240,6 +244,9 @@ mpol_shared_policy_lookup(struct shared_policy *sp, unsigned long idx)
75952 }
75953
75954 #define vma_policy(vma) NULL
75955+static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
75956+{
75957+}
75958
75959 static inline int
75960 vma_dup_policy(struct vm_area_struct *src, struct vm_area_struct *dst)
75961diff --git a/include/linux/mm.h b/include/linux/mm.h
75962index 8b6e55e..c4edf39 100644
75963--- a/include/linux/mm.h
75964+++ b/include/linux/mm.h
75965@@ -113,6 +113,11 @@ extern unsigned int kobjsize(const void *objp);
75966 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
75967 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
75968 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
75969+
75970+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
75971+#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
75972+#endif
75973+
75974 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
75975
75976 #ifdef CONFIG_MEM_SOFT_DIRTY
75977@@ -215,8 +220,8 @@ struct vm_operations_struct {
75978 /* called by access_process_vm when get_user_pages() fails, typically
75979 * for use by special VMAs that can switch between memory and hardware
75980 */
75981- int (*access)(struct vm_area_struct *vma, unsigned long addr,
75982- void *buf, int len, int write);
75983+ ssize_t (*access)(struct vm_area_struct *vma, unsigned long addr,
75984+ void *buf, size_t len, int write);
75985 #ifdef CONFIG_NUMA
75986 /*
75987 * set_policy() op must add a reference to any non-NULL @new mempolicy
75988@@ -246,6 +251,7 @@ struct vm_operations_struct {
75989 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
75990 unsigned long size, pgoff_t pgoff);
75991 };
75992+typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
75993
75994 struct mmu_gather;
75995 struct inode;
75996@@ -977,8 +983,8 @@ int follow_pfn(struct vm_area_struct *vma, unsigned long address,
75997 unsigned long *pfn);
75998 int follow_phys(struct vm_area_struct *vma, unsigned long address,
75999 unsigned int flags, unsigned long *prot, resource_size_t *phys);
76000-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
76001- void *buf, int len, int write);
76002+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
76003+ void *buf, size_t len, int write);
76004
76005 static inline void unmap_shared_mapping_range(struct address_space *mapping,
76006 loff_t const holebegin, loff_t const holelen)
76007@@ -1017,9 +1023,9 @@ static inline int fixup_user_fault(struct task_struct *tsk,
76008 }
76009 #endif
76010
76011-extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
76012-extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
76013- void *buf, int len, int write);
76014+extern ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write);
76015+extern ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
76016+ void *buf, size_t len, int write);
76017
76018 long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
76019 unsigned long start, unsigned long nr_pages,
76020@@ -1051,34 +1057,6 @@ int set_page_dirty(struct page *page);
76021 int set_page_dirty_lock(struct page *page);
76022 int clear_page_dirty_for_io(struct page *page);
76023
76024-/* Is the vma a continuation of the stack vma above it? */
76025-static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
76026-{
76027- return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
76028-}
76029-
76030-static inline int stack_guard_page_start(struct vm_area_struct *vma,
76031- unsigned long addr)
76032-{
76033- return (vma->vm_flags & VM_GROWSDOWN) &&
76034- (vma->vm_start == addr) &&
76035- !vma_growsdown(vma->vm_prev, addr);
76036-}
76037-
76038-/* Is the vma a continuation of the stack vma below it? */
76039-static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
76040-{
76041- return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
76042-}
76043-
76044-static inline int stack_guard_page_end(struct vm_area_struct *vma,
76045- unsigned long addr)
76046-{
76047- return (vma->vm_flags & VM_GROWSUP) &&
76048- (vma->vm_end == addr) &&
76049- !vma_growsup(vma->vm_next, addr);
76050-}
76051-
76052 extern pid_t
76053 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
76054
76055@@ -1178,6 +1156,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
76056 }
76057 #endif
76058
76059+#ifdef CONFIG_MMU
76060+pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
76061+#else
76062+static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
76063+{
76064+ return __pgprot(0);
76065+}
76066+#endif
76067+
76068 int vma_wants_writenotify(struct vm_area_struct *vma);
76069
76070 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
76071@@ -1196,8 +1183,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
76072 {
76073 return 0;
76074 }
76075+
76076+static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
76077+ unsigned long address)
76078+{
76079+ return 0;
76080+}
76081 #else
76082 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
76083+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
76084 #endif
76085
76086 #ifdef __PAGETABLE_PMD_FOLDED
76087@@ -1206,8 +1200,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
76088 {
76089 return 0;
76090 }
76091+
76092+static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
76093+ unsigned long address)
76094+{
76095+ return 0;
76096+}
76097 #else
76098 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
76099+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
76100 #endif
76101
76102 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
76103@@ -1225,11 +1226,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
76104 NULL: pud_offset(pgd, address);
76105 }
76106
76107+static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
76108+{
76109+ return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
76110+ NULL: pud_offset(pgd, address);
76111+}
76112+
76113 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
76114 {
76115 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
76116 NULL: pmd_offset(pud, address);
76117 }
76118+
76119+static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
76120+{
76121+ return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
76122+ NULL: pmd_offset(pud, address);
76123+}
76124 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
76125
76126 #if USE_SPLIT_PTLOCKS
76127@@ -1517,7 +1530,7 @@ extern int install_special_mapping(struct mm_struct *mm,
76128 unsigned long addr, unsigned long len,
76129 unsigned long flags, struct page **pages);
76130
76131-extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
76132+extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long) __intentional_overflow(-1);
76133
76134 extern unsigned long mmap_region(struct file *file, unsigned long addr,
76135 unsigned long len, vm_flags_t vm_flags, unsigned long pgoff);
76136@@ -1525,6 +1538,7 @@ extern unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
76137 unsigned long len, unsigned long prot, unsigned long flags,
76138 unsigned long pgoff, unsigned long *populate);
76139 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
76140+extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
76141
76142 #ifdef CONFIG_MMU
76143 extern int __mm_populate(unsigned long addr, unsigned long len,
76144@@ -1553,10 +1567,11 @@ struct vm_unmapped_area_info {
76145 unsigned long high_limit;
76146 unsigned long align_mask;
76147 unsigned long align_offset;
76148+ unsigned long threadstack_offset;
76149 };
76150
76151-extern unsigned long unmapped_area(struct vm_unmapped_area_info *info);
76152-extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
76153+extern unsigned long unmapped_area(const struct vm_unmapped_area_info *info);
76154+extern unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info);
76155
76156 /*
76157 * Search for an unmapped address range.
76158@@ -1568,7 +1583,7 @@ extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
76159 * - satisfies (begin_addr & align_mask) == (align_offset & align_mask)
76160 */
76161 static inline unsigned long
76162-vm_unmapped_area(struct vm_unmapped_area_info *info)
76163+vm_unmapped_area(const struct vm_unmapped_area_info *info)
76164 {
76165 if (!(info->flags & VM_UNMAPPED_AREA_TOPDOWN))
76166 return unmapped_area(info);
76167@@ -1631,6 +1646,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
76168 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
76169 struct vm_area_struct **pprev);
76170
76171+extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
76172+extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
76173+extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
76174+
76175 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
76176 NULL if none. Assume start_addr < end_addr. */
76177 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
76178@@ -1659,15 +1678,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
76179 return vma;
76180 }
76181
76182-#ifdef CONFIG_MMU
76183-pgprot_t vm_get_page_prot(unsigned long vm_flags);
76184-#else
76185-static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
76186-{
76187- return __pgprot(0);
76188-}
76189-#endif
76190-
76191 #ifdef CONFIG_ARCH_USES_NUMA_PROT_NONE
76192 unsigned long change_prot_numa(struct vm_area_struct *vma,
76193 unsigned long start, unsigned long end);
76194@@ -1719,6 +1729,11 @@ void vm_stat_account(struct mm_struct *, unsigned long, struct file *, long);
76195 static inline void vm_stat_account(struct mm_struct *mm,
76196 unsigned long flags, struct file *file, long pages)
76197 {
76198+
76199+#ifdef CONFIG_PAX_RANDMMAP
76200+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
76201+#endif
76202+
76203 mm->total_vm += pages;
76204 }
76205 #endif /* CONFIG_PROC_FS */
76206@@ -1800,7 +1815,7 @@ extern int unpoison_memory(unsigned long pfn);
76207 extern int sysctl_memory_failure_early_kill;
76208 extern int sysctl_memory_failure_recovery;
76209 extern void shake_page(struct page *p, int access);
76210-extern atomic_long_t num_poisoned_pages;
76211+extern atomic_long_unchecked_t num_poisoned_pages;
76212 extern int soft_offline_page(struct page *page, int flags);
76213
76214 extern void dump_page(struct page *page);
76215@@ -1837,5 +1852,11 @@ void __init setup_nr_node_ids(void);
76216 static inline void setup_nr_node_ids(void) {}
76217 #endif
76218
76219+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
76220+extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
76221+#else
76222+static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
76223+#endif
76224+
76225 #endif /* __KERNEL__ */
76226 #endif /* _LINUX_MM_H */
76227diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
76228index d9851ee..619492d 100644
76229--- a/include/linux/mm_types.h
76230+++ b/include/linux/mm_types.h
76231@@ -289,6 +289,8 @@ struct vm_area_struct {
76232 #ifdef CONFIG_NUMA
76233 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
76234 #endif
76235+
76236+ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
76237 };
76238
76239 struct core_thread {
76240@@ -436,6 +438,24 @@ struct mm_struct {
76241 int first_nid;
76242 #endif
76243 struct uprobes_state uprobes_state;
76244+
76245+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
76246+ unsigned long pax_flags;
76247+#endif
76248+
76249+#ifdef CONFIG_PAX_DLRESOLVE
76250+ unsigned long call_dl_resolve;
76251+#endif
76252+
76253+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
76254+ unsigned long call_syscall;
76255+#endif
76256+
76257+#ifdef CONFIG_PAX_ASLR
76258+ unsigned long delta_mmap; /* randomized offset */
76259+ unsigned long delta_stack; /* randomized offset */
76260+#endif
76261+
76262 };
76263
76264 /* first nid will either be a valid NID or one of these values */
76265diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
76266index c5d5278..f0b68c8 100644
76267--- a/include/linux/mmiotrace.h
76268+++ b/include/linux/mmiotrace.h
76269@@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
76270 /* Called from ioremap.c */
76271 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
76272 void __iomem *addr);
76273-extern void mmiotrace_iounmap(volatile void __iomem *addr);
76274+extern void mmiotrace_iounmap(const volatile void __iomem *addr);
76275
76276 /* For anyone to insert markers. Remember trailing newline. */
76277 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
76278@@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
76279 {
76280 }
76281
76282-static inline void mmiotrace_iounmap(volatile void __iomem *addr)
76283+static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
76284 {
76285 }
76286
76287diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
76288index bd791e4..8617c34f 100644
76289--- a/include/linux/mmzone.h
76290+++ b/include/linux/mmzone.h
76291@@ -396,7 +396,7 @@ struct zone {
76292 unsigned long flags; /* zone flags, see below */
76293
76294 /* Zone statistics */
76295- atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
76296+ atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
76297
76298 /*
76299 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
76300diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
76301index 45e9214..a7227d6 100644
76302--- a/include/linux/mod_devicetable.h
76303+++ b/include/linux/mod_devicetable.h
76304@@ -13,7 +13,7 @@
76305 typedef unsigned long kernel_ulong_t;
76306 #endif
76307
76308-#define PCI_ANY_ID (~0)
76309+#define PCI_ANY_ID ((__u16)~0)
76310
76311 struct pci_device_id {
76312 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
76313@@ -139,7 +139,7 @@ struct usb_device_id {
76314 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
76315 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
76316
76317-#define HID_ANY_ID (~0)
76318+#define HID_ANY_ID (~0U)
76319 #define HID_BUS_ANY 0xffff
76320 #define HID_GROUP_ANY 0x0000
76321
76322@@ -467,7 +467,7 @@ struct dmi_system_id {
76323 const char *ident;
76324 struct dmi_strmatch matches[4];
76325 void *driver_data;
76326-};
76327+} __do_const;
76328 /*
76329 * struct dmi_device_id appears during expansion of
76330 * "MODULE_DEVICE_TABLE(dmi, x)". Compiler doesn't look inside it
76331diff --git a/include/linux/module.h b/include/linux/module.h
76332index 05f2447..2aee07c 100644
76333--- a/include/linux/module.h
76334+++ b/include/linux/module.h
76335@@ -17,9 +17,11 @@
76336 #include <linux/moduleparam.h>
76337 #include <linux/tracepoint.h>
76338 #include <linux/export.h>
76339+#include <linux/fs.h>
76340
76341 #include <linux/percpu.h>
76342 #include <asm/module.h>
76343+#include <asm/pgtable.h>
76344
76345 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
76346 #define MODULE_SIG_STRING "~Module signature appended~\n"
76347@@ -55,12 +57,13 @@ struct module_attribute {
76348 int (*test)(struct module *);
76349 void (*free)(struct module *);
76350 };
76351+typedef struct module_attribute __no_const module_attribute_no_const;
76352
76353 struct module_version_attribute {
76354 struct module_attribute mattr;
76355 const char *module_name;
76356 const char *version;
76357-} __attribute__ ((__aligned__(sizeof(void *))));
76358+} __do_const __attribute__ ((__aligned__(sizeof(void *))));
76359
76360 extern ssize_t __modver_version_show(struct module_attribute *,
76361 struct module_kobject *, char *);
76362@@ -238,7 +241,7 @@ struct module
76363
76364 /* Sysfs stuff. */
76365 struct module_kobject mkobj;
76366- struct module_attribute *modinfo_attrs;
76367+ module_attribute_no_const *modinfo_attrs;
76368 const char *version;
76369 const char *srcversion;
76370 struct kobject *holders_dir;
76371@@ -287,19 +290,16 @@ struct module
76372 int (*init)(void);
76373
76374 /* If this is non-NULL, vfree after init() returns */
76375- void *module_init;
76376+ void *module_init_rx, *module_init_rw;
76377
76378 /* Here is the actual code + data, vfree'd on unload. */
76379- void *module_core;
76380+ void *module_core_rx, *module_core_rw;
76381
76382 /* Here are the sizes of the init and core sections */
76383- unsigned int init_size, core_size;
76384+ unsigned int init_size_rw, core_size_rw;
76385
76386 /* The size of the executable code in each section. */
76387- unsigned int init_text_size, core_text_size;
76388-
76389- /* Size of RO sections of the module (text+rodata) */
76390- unsigned int init_ro_size, core_ro_size;
76391+ unsigned int init_size_rx, core_size_rx;
76392
76393 /* Arch-specific module values */
76394 struct mod_arch_specific arch;
76395@@ -355,6 +355,10 @@ struct module
76396 #ifdef CONFIG_EVENT_TRACING
76397 struct ftrace_event_call **trace_events;
76398 unsigned int num_trace_events;
76399+ struct file_operations trace_id;
76400+ struct file_operations trace_enable;
76401+ struct file_operations trace_format;
76402+ struct file_operations trace_filter;
76403 #endif
76404 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
76405 unsigned int num_ftrace_callsites;
76406@@ -402,16 +406,46 @@ bool is_module_address(unsigned long addr);
76407 bool is_module_percpu_address(unsigned long addr);
76408 bool is_module_text_address(unsigned long addr);
76409
76410+static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
76411+{
76412+
76413+#ifdef CONFIG_PAX_KERNEXEC
76414+ if (ktla_ktva(addr) >= (unsigned long)start &&
76415+ ktla_ktva(addr) < (unsigned long)start + size)
76416+ return 1;
76417+#endif
76418+
76419+ return ((void *)addr >= start && (void *)addr < start + size);
76420+}
76421+
76422+static inline int within_module_core_rx(unsigned long addr, const struct module *mod)
76423+{
76424+ return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
76425+}
76426+
76427+static inline int within_module_core_rw(unsigned long addr, const struct module *mod)
76428+{
76429+ return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
76430+}
76431+
76432+static inline int within_module_init_rx(unsigned long addr, const struct module *mod)
76433+{
76434+ return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
76435+}
76436+
76437+static inline int within_module_init_rw(unsigned long addr, const struct module *mod)
76438+{
76439+ return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
76440+}
76441+
76442 static inline int within_module_core(unsigned long addr, const struct module *mod)
76443 {
76444- return (unsigned long)mod->module_core <= addr &&
76445- addr < (unsigned long)mod->module_core + mod->core_size;
76446+ return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
76447 }
76448
76449 static inline int within_module_init(unsigned long addr, const struct module *mod)
76450 {
76451- return (unsigned long)mod->module_init <= addr &&
76452- addr < (unsigned long)mod->module_init + mod->init_size;
76453+ return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
76454 }
76455
76456 /* Search for module by name: must hold module_mutex. */
76457diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
76458index 560ca53..ef621ef 100644
76459--- a/include/linux/moduleloader.h
76460+++ b/include/linux/moduleloader.h
76461@@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
76462 sections. Returns NULL on failure. */
76463 void *module_alloc(unsigned long size);
76464
76465+#ifdef CONFIG_PAX_KERNEXEC
76466+void *module_alloc_exec(unsigned long size);
76467+#else
76468+#define module_alloc_exec(x) module_alloc(x)
76469+#endif
76470+
76471 /* Free memory returned from module_alloc. */
76472 void module_free(struct module *mod, void *module_region);
76473
76474+#ifdef CONFIG_PAX_KERNEXEC
76475+void module_free_exec(struct module *mod, void *module_region);
76476+#else
76477+#define module_free_exec(x, y) module_free((x), (y))
76478+#endif
76479+
76480 /*
76481 * Apply the given relocation to the (simplified) ELF. Return -error
76482 * or 0.
76483@@ -45,7 +57,9 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
76484 unsigned int relsec,
76485 struct module *me)
76486 {
76487+#ifdef CONFIG_MODULES
76488 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
76489+#endif
76490 return -ENOEXEC;
76491 }
76492 #endif
76493@@ -67,7 +81,9 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
76494 unsigned int relsec,
76495 struct module *me)
76496 {
76497+#ifdef CONFIG_MODULES
76498 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
76499+#endif
76500 return -ENOEXEC;
76501 }
76502 #endif
76503diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
76504index c3eb102..073c4a6 100644
76505--- a/include/linux/moduleparam.h
76506+++ b/include/linux/moduleparam.h
76507@@ -295,7 +295,7 @@ static inline void __kernel_param_unlock(void)
76508 * @len is usually just sizeof(string).
76509 */
76510 #define module_param_string(name, string, len, perm) \
76511- static const struct kparam_string __param_string_##name \
76512+ static const struct kparam_string __param_string_##name __used \
76513 = { len, string }; \
76514 __module_param_call(MODULE_PARAM_PREFIX, name, \
76515 &param_ops_string, \
76516@@ -434,7 +434,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
76517 */
76518 #define module_param_array_named(name, array, type, nump, perm) \
76519 param_check_##type(name, &(array)[0]); \
76520- static const struct kparam_array __param_arr_##name \
76521+ static const struct kparam_array __param_arr_##name __used \
76522 = { .max = ARRAY_SIZE(array), .num = nump, \
76523 .ops = &param_ops_##type, \
76524 .elemsize = sizeof(array[0]), .elem = array }; \
76525diff --git a/include/linux/namei.h b/include/linux/namei.h
76526index 8e47bc7..c70fd73 100644
76527--- a/include/linux/namei.h
76528+++ b/include/linux/namei.h
76529@@ -19,7 +19,7 @@ struct nameidata {
76530 unsigned seq;
76531 int last_type;
76532 unsigned depth;
76533- char *saved_names[MAX_NESTED_LINKS + 1];
76534+ const char *saved_names[MAX_NESTED_LINKS + 1];
76535 };
76536
76537 /*
76538@@ -83,12 +83,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
76539
76540 extern void nd_jump_link(struct nameidata *nd, struct path *path);
76541
76542-static inline void nd_set_link(struct nameidata *nd, char *path)
76543+static inline void nd_set_link(struct nameidata *nd, const char *path)
76544 {
76545 nd->saved_names[nd->depth] = path;
76546 }
76547
76548-static inline char *nd_get_link(struct nameidata *nd)
76549+static inline const char *nd_get_link(const struct nameidata *nd)
76550 {
76551 return nd->saved_names[nd->depth];
76552 }
76553diff --git a/include/linux/net.h b/include/linux/net.h
76554index 4f27575..fc8a65f 100644
76555--- a/include/linux/net.h
76556+++ b/include/linux/net.h
76557@@ -183,7 +183,7 @@ struct net_proto_family {
76558 int (*create)(struct net *net, struct socket *sock,
76559 int protocol, int kern);
76560 struct module *owner;
76561-};
76562+} __do_const;
76563
76564 struct iovec;
76565 struct kvec;
76566diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
76567index 25f5d2d1..5cf2120 100644
76568--- a/include/linux/netdevice.h
76569+++ b/include/linux/netdevice.h
76570@@ -1098,6 +1098,7 @@ struct net_device_ops {
76571 sa_family_t sa_family,
76572 __be16 port);
76573 };
76574+typedef struct net_device_ops __no_const net_device_ops_no_const;
76575
76576 /*
76577 * The DEVICE structure.
76578@@ -1169,7 +1170,7 @@ struct net_device {
76579 int iflink;
76580
76581 struct net_device_stats stats;
76582- atomic_long_t rx_dropped; /* dropped packets by core network
76583+ atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
76584 * Do not use this in drivers.
76585 */
76586
76587diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
76588index 708fe72ab9..77084a3 100644
76589--- a/include/linux/netfilter.h
76590+++ b/include/linux/netfilter.h
76591@@ -82,7 +82,7 @@ struct nf_sockopt_ops {
76592 #endif
76593 /* Use the module struct to lock set/get code in place */
76594 struct module *owner;
76595-};
76596+} __do_const;
76597
76598 /* Function to register/unregister hook points. */
76599 int nf_register_hook(struct nf_hook_ops *reg);
76600diff --git a/include/linux/netfilter/ipset/ip_set.h b/include/linux/netfilter/ipset/ip_set.h
76601index 9ac9fbd..f92edb4 100644
76602--- a/include/linux/netfilter/ipset/ip_set.h
76603+++ b/include/linux/netfilter/ipset/ip_set.h
76604@@ -124,7 +124,7 @@ struct ip_set_type_variant {
76605 /* Return true if "b" set is the same as "a"
76606 * according to the create set parameters */
76607 bool (*same_set)(const struct ip_set *a, const struct ip_set *b);
76608-};
76609+} __do_const;
76610
76611 /* The core set type structure */
76612 struct ip_set_type {
76613diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
76614index cadb740..d7c37c0 100644
76615--- a/include/linux/netfilter/nfnetlink.h
76616+++ b/include/linux/netfilter/nfnetlink.h
76617@@ -16,7 +16,7 @@ struct nfnl_callback {
76618 const struct nlattr * const cda[]);
76619 const struct nla_policy *policy; /* netlink attribute policy */
76620 const u_int16_t attr_count; /* number of nlattr's */
76621-};
76622+} __do_const;
76623
76624 struct nfnetlink_subsystem {
76625 const char *name;
76626diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
76627new file mode 100644
76628index 0000000..33f4af8
76629--- /dev/null
76630+++ b/include/linux/netfilter/xt_gradm.h
76631@@ -0,0 +1,9 @@
76632+#ifndef _LINUX_NETFILTER_XT_GRADM_H
76633+#define _LINUX_NETFILTER_XT_GRADM_H 1
76634+
76635+struct xt_gradm_mtinfo {
76636+ __u16 flags;
76637+ __u16 invflags;
76638+};
76639+
76640+#endif
76641diff --git a/include/linux/nls.h b/include/linux/nls.h
76642index 5dc635f..35f5e11 100644
76643--- a/include/linux/nls.h
76644+++ b/include/linux/nls.h
76645@@ -31,7 +31,7 @@ struct nls_table {
76646 const unsigned char *charset2upper;
76647 struct module *owner;
76648 struct nls_table *next;
76649-};
76650+} __do_const;
76651
76652 /* this value hold the maximum octet of charset */
76653 #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
76654diff --git a/include/linux/notifier.h b/include/linux/notifier.h
76655index d14a4c3..a078786 100644
76656--- a/include/linux/notifier.h
76657+++ b/include/linux/notifier.h
76658@@ -54,7 +54,8 @@ struct notifier_block {
76659 notifier_fn_t notifier_call;
76660 struct notifier_block __rcu *next;
76661 int priority;
76662-};
76663+} __do_const;
76664+typedef struct notifier_block __no_const notifier_block_no_const;
76665
76666 struct atomic_notifier_head {
76667 spinlock_t lock;
76668diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
76669index b2a0f15..4d7da32 100644
76670--- a/include/linux/oprofile.h
76671+++ b/include/linux/oprofile.h
76672@@ -138,9 +138,9 @@ int oprofilefs_create_ulong(struct dentry * root,
76673 int oprofilefs_create_ro_ulong(struct dentry * root,
76674 char const * name, ulong * val);
76675
76676-/** Create a file for read-only access to an atomic_t. */
76677+/** Create a file for read-only access to an atomic_unchecked_t. */
76678 int oprofilefs_create_ro_atomic(struct dentry * root,
76679- char const * name, atomic_t * val);
76680+ char const * name, atomic_unchecked_t * val);
76681
76682 /** create a directory */
76683 struct dentry *oprofilefs_mkdir(struct dentry *parent, char const *name);
76684diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
76685index 430dd96..544e26e 100644
76686--- a/include/linux/pci_hotplug.h
76687+++ b/include/linux/pci_hotplug.h
76688@@ -71,7 +71,8 @@ struct hotplug_slot_ops {
76689 int (*get_latch_status) (struct hotplug_slot *slot, u8 *value);
76690 int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value);
76691 int (*reset_slot) (struct hotplug_slot *slot, int probe);
76692-};
76693+} __do_const;
76694+typedef struct hotplug_slot_ops __no_const hotplug_slot_ops_no_const;
76695
76696 /**
76697 * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
76698diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
76699index c8ba627..24bdfa8 100644
76700--- a/include/linux/perf_event.h
76701+++ b/include/linux/perf_event.h
76702@@ -327,8 +327,8 @@ struct perf_event {
76703
76704 enum perf_event_active_state state;
76705 unsigned int attach_state;
76706- local64_t count;
76707- atomic64_t child_count;
76708+ local64_t count; /* PaX: fix it one day */
76709+ atomic64_unchecked_t child_count;
76710
76711 /*
76712 * These are the total time in nanoseconds that the event
76713@@ -379,8 +379,8 @@ struct perf_event {
76714 * These accumulate total time (in nanoseconds) that children
76715 * events have been enabled and running, respectively.
76716 */
76717- atomic64_t child_total_time_enabled;
76718- atomic64_t child_total_time_running;
76719+ atomic64_unchecked_t child_total_time_enabled;
76720+ atomic64_unchecked_t child_total_time_running;
76721
76722 /*
76723 * Protect attach/detach and child_list:
76724@@ -702,7 +702,7 @@ static inline void perf_callchain_store(struct perf_callchain_entry *entry, u64
76725 entry->ip[entry->nr++] = ip;
76726 }
76727
76728-extern int sysctl_perf_event_paranoid;
76729+extern int sysctl_perf_event_legitimately_concerned;
76730 extern int sysctl_perf_event_mlock;
76731 extern int sysctl_perf_event_sample_rate;
76732 extern int sysctl_perf_cpu_time_max_percent;
76733@@ -717,19 +717,24 @@ extern int perf_cpu_time_max_percent_handler(struct ctl_table *table, int write,
76734 loff_t *ppos);
76735
76736
76737+static inline bool perf_paranoid_any(void)
76738+{
76739+ return sysctl_perf_event_legitimately_concerned > 2;
76740+}
76741+
76742 static inline bool perf_paranoid_tracepoint_raw(void)
76743 {
76744- return sysctl_perf_event_paranoid > -1;
76745+ return sysctl_perf_event_legitimately_concerned > -1;
76746 }
76747
76748 static inline bool perf_paranoid_cpu(void)
76749 {
76750- return sysctl_perf_event_paranoid > 0;
76751+ return sysctl_perf_event_legitimately_concerned > 0;
76752 }
76753
76754 static inline bool perf_paranoid_kernel(void)
76755 {
76756- return sysctl_perf_event_paranoid > 1;
76757+ return sysctl_perf_event_legitimately_concerned > 1;
76758 }
76759
76760 extern void perf_event_init(void);
76761@@ -845,7 +850,7 @@ struct perf_pmu_events_attr {
76762 struct device_attribute attr;
76763 u64 id;
76764 const char *event_str;
76765-};
76766+} __do_const;
76767
76768 #define PMU_EVENT_ATTR(_name, _var, _id, _show) \
76769 static struct perf_pmu_events_attr _var = { \
76770diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
76771index b8809fe..ae4ccd0 100644
76772--- a/include/linux/pipe_fs_i.h
76773+++ b/include/linux/pipe_fs_i.h
76774@@ -47,10 +47,10 @@ struct pipe_inode_info {
76775 struct mutex mutex;
76776 wait_queue_head_t wait;
76777 unsigned int nrbufs, curbuf, buffers;
76778- unsigned int readers;
76779- unsigned int writers;
76780- unsigned int files;
76781- unsigned int waiting_writers;
76782+ atomic_t readers;
76783+ atomic_t writers;
76784+ atomic_t files;
76785+ atomic_t waiting_writers;
76786 unsigned int r_counter;
76787 unsigned int w_counter;
76788 struct page *tmp_page;
76789diff --git a/include/linux/platform_data/usb-ehci-s5p.h b/include/linux/platform_data/usb-ehci-s5p.h
76790index 5f28cae..3d23723 100644
76791--- a/include/linux/platform_data/usb-ehci-s5p.h
76792+++ b/include/linux/platform_data/usb-ehci-s5p.h
76793@@ -14,7 +14,7 @@
76794 struct s5p_ehci_platdata {
76795 int (*phy_init)(struct platform_device *pdev, int type);
76796 int (*phy_exit)(struct platform_device *pdev, int type);
76797-};
76798+} __no_const;
76799
76800 extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd);
76801
76802diff --git a/include/linux/platform_data/usb-ohci-exynos.h b/include/linux/platform_data/usb-ohci-exynos.h
76803index c256c59..8ea94c7 100644
76804--- a/include/linux/platform_data/usb-ohci-exynos.h
76805+++ b/include/linux/platform_data/usb-ohci-exynos.h
76806@@ -14,7 +14,7 @@
76807 struct exynos4_ohci_platdata {
76808 int (*phy_init)(struct platform_device *pdev, int type);
76809 int (*phy_exit)(struct platform_device *pdev, int type);
76810-};
76811+} __no_const;
76812
76813 extern void exynos4_ohci_set_platdata(struct exynos4_ohci_platdata *pd);
76814
76815diff --git a/include/linux/pm.h b/include/linux/pm.h
76816index a224c7f..92d8a97 100644
76817--- a/include/linux/pm.h
76818+++ b/include/linux/pm.h
76819@@ -576,6 +576,7 @@ extern int dev_pm_put_subsys_data(struct device *dev);
76820 struct dev_pm_domain {
76821 struct dev_pm_ops ops;
76822 };
76823+typedef struct dev_pm_domain __no_const dev_pm_domain_no_const;
76824
76825 /*
76826 * The PM_EVENT_ messages are also used by drivers implementing the legacy
76827diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
76828index 7c1d252..c5c773e 100644
76829--- a/include/linux/pm_domain.h
76830+++ b/include/linux/pm_domain.h
76831@@ -48,7 +48,7 @@ struct gpd_dev_ops {
76832
76833 struct gpd_cpu_data {
76834 unsigned int saved_exit_latency;
76835- struct cpuidle_state *idle_state;
76836+ cpuidle_state_no_const *idle_state;
76837 };
76838
76839 struct generic_pm_domain {
76840diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
76841index 6fa7cea..7bf6415 100644
76842--- a/include/linux/pm_runtime.h
76843+++ b/include/linux/pm_runtime.h
76844@@ -103,7 +103,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
76845
76846 static inline void pm_runtime_mark_last_busy(struct device *dev)
76847 {
76848- ACCESS_ONCE(dev->power.last_busy) = jiffies;
76849+ ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
76850 }
76851
76852 #else /* !CONFIG_PM_RUNTIME */
76853diff --git a/include/linux/pnp.h b/include/linux/pnp.h
76854index 195aafc..49a7bc2 100644
76855--- a/include/linux/pnp.h
76856+++ b/include/linux/pnp.h
76857@@ -297,7 +297,7 @@ static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
76858 struct pnp_fixup {
76859 char id[7];
76860 void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
76861-};
76862+} __do_const;
76863
76864 /* config parameters */
76865 #define PNP_CONFIG_NORMAL 0x0001
76866diff --git a/include/linux/poison.h b/include/linux/poison.h
76867index 2110a81..13a11bb 100644
76868--- a/include/linux/poison.h
76869+++ b/include/linux/poison.h
76870@@ -19,8 +19,8 @@
76871 * under normal circumstances, used to verify that nobody uses
76872 * non-initialized list entries.
76873 */
76874-#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
76875-#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
76876+#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
76877+#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
76878
76879 /********** include/linux/timer.h **********/
76880 /*
76881diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
76882index d8b187c3..9a9257a 100644
76883--- a/include/linux/power/smartreflex.h
76884+++ b/include/linux/power/smartreflex.h
76885@@ -238,7 +238,7 @@ struct omap_sr_class_data {
76886 int (*notify)(struct omap_sr *sr, u32 status);
76887 u8 notify_flags;
76888 u8 class_type;
76889-};
76890+} __do_const;
76891
76892 /**
76893 * struct omap_sr_nvalue_table - Smartreflex n-target value info
76894diff --git a/include/linux/ppp-comp.h b/include/linux/ppp-comp.h
76895index 4ea1d37..80f4b33 100644
76896--- a/include/linux/ppp-comp.h
76897+++ b/include/linux/ppp-comp.h
76898@@ -84,7 +84,7 @@ struct compressor {
76899 struct module *owner;
76900 /* Extra skb space needed by the compressor algorithm */
76901 unsigned int comp_extra;
76902-};
76903+} __do_const;
76904
76905 /*
76906 * The return value from decompress routine is the length of the
76907diff --git a/include/linux/preempt.h b/include/linux/preempt.h
76908index f5d4723..a6ea2fa 100644
76909--- a/include/linux/preempt.h
76910+++ b/include/linux/preempt.h
76911@@ -18,8 +18,13 @@
76912 # define sub_preempt_count(val) do { preempt_count() -= (val); } while (0)
76913 #endif
76914
76915+#define raw_add_preempt_count(val) do { preempt_count() += (val); } while (0)
76916+#define raw_sub_preempt_count(val) do { preempt_count() -= (val); } while (0)
76917+
76918 #define inc_preempt_count() add_preempt_count(1)
76919+#define raw_inc_preempt_count() raw_add_preempt_count(1)
76920 #define dec_preempt_count() sub_preempt_count(1)
76921+#define raw_dec_preempt_count() raw_sub_preempt_count(1)
76922
76923 #define preempt_count() (current_thread_info()->preempt_count)
76924
76925@@ -64,6 +69,12 @@ do { \
76926 barrier(); \
76927 } while (0)
76928
76929+#define raw_preempt_disable() \
76930+do { \
76931+ raw_inc_preempt_count(); \
76932+ barrier(); \
76933+} while (0)
76934+
76935 #define sched_preempt_enable_no_resched() \
76936 do { \
76937 barrier(); \
76938@@ -72,6 +83,12 @@ do { \
76939
76940 #define preempt_enable_no_resched() sched_preempt_enable_no_resched()
76941
76942+#define raw_preempt_enable_no_resched() \
76943+do { \
76944+ barrier(); \
76945+ raw_dec_preempt_count(); \
76946+} while (0)
76947+
76948 #define preempt_enable() \
76949 do { \
76950 preempt_enable_no_resched(); \
76951@@ -116,8 +133,10 @@ do { \
76952 * region.
76953 */
76954 #define preempt_disable() barrier()
76955+#define raw_preempt_disable() barrier()
76956 #define sched_preempt_enable_no_resched() barrier()
76957 #define preempt_enable_no_resched() barrier()
76958+#define raw_preempt_enable_no_resched() barrier()
76959 #define preempt_enable() barrier()
76960
76961 #define preempt_disable_notrace() barrier()
76962diff --git a/include/linux/printk.h b/include/linux/printk.h
76963index e6131a78..8e9fb61 100644
76964--- a/include/linux/printk.h
76965+++ b/include/linux/printk.h
76966@@ -106,6 +106,8 @@ static inline __printf(1, 2) __cold
76967 void early_printk(const char *s, ...) { }
76968 #endif
76969
76970+extern int kptr_restrict;
76971+
76972 #ifdef CONFIG_PRINTK
76973 asmlinkage __printf(5, 0)
76974 int vprintk_emit(int facility, int level,
76975@@ -140,7 +142,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
76976
76977 extern int printk_delay_msec;
76978 extern int dmesg_restrict;
76979-extern int kptr_restrict;
76980
76981 extern void wake_up_klogd(void);
76982
76983diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
76984index 608e60a..c26f864 100644
76985--- a/include/linux/proc_fs.h
76986+++ b/include/linux/proc_fs.h
76987@@ -34,6 +34,19 @@ static inline struct proc_dir_entry *proc_create(
76988 return proc_create_data(name, mode, parent, proc_fops, NULL);
76989 }
76990
76991+static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
76992+ struct proc_dir_entry *parent, const struct file_operations *proc_fops)
76993+{
76994+#ifdef CONFIG_GRKERNSEC_PROC_USER
76995+ return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
76996+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
76997+ return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
76998+#else
76999+ return proc_create_data(name, mode, parent, proc_fops, NULL);
77000+#endif
77001+}
77002+
77003+
77004 extern void proc_set_size(struct proc_dir_entry *, loff_t);
77005 extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
77006 extern void *PDE_DATA(const struct inode *);
77007diff --git a/include/linux/proc_ns.h b/include/linux/proc_ns.h
77008index 34a1e10..03a6d03 100644
77009--- a/include/linux/proc_ns.h
77010+++ b/include/linux/proc_ns.h
77011@@ -14,7 +14,7 @@ struct proc_ns_operations {
77012 void (*put)(void *ns);
77013 int (*install)(struct nsproxy *nsproxy, void *ns);
77014 unsigned int (*inum)(void *ns);
77015-};
77016+} __do_const;
77017
77018 struct proc_ns {
77019 void *ns;
77020diff --git a/include/linux/quota.h b/include/linux/quota.h
77021index cc7494a..1e27036 100644
77022--- a/include/linux/quota.h
77023+++ b/include/linux/quota.h
77024@@ -70,7 +70,7 @@ struct kqid { /* Type in which we store the quota identifier */
77025
77026 extern bool qid_eq(struct kqid left, struct kqid right);
77027 extern bool qid_lt(struct kqid left, struct kqid right);
77028-extern qid_t from_kqid(struct user_namespace *to, struct kqid qid);
77029+extern qid_t from_kqid(struct user_namespace *to, struct kqid qid) __intentional_overflow(-1);
77030 extern qid_t from_kqid_munged(struct user_namespace *to, struct kqid qid);
77031 extern bool qid_valid(struct kqid qid);
77032
77033diff --git a/include/linux/random.h b/include/linux/random.h
77034index 6312dd9..2561947 100644
77035--- a/include/linux/random.h
77036+++ b/include/linux/random.h
77037@@ -10,9 +10,19 @@
77038
77039
77040 extern void add_device_randomness(const void *, unsigned int);
77041+
77042+static inline void add_latent_entropy(void)
77043+{
77044+
77045+#ifdef LATENT_ENTROPY_PLUGIN
77046+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
77047+#endif
77048+
77049+}
77050+
77051 extern void add_input_randomness(unsigned int type, unsigned int code,
77052- unsigned int value);
77053-extern void add_interrupt_randomness(int irq, int irq_flags);
77054+ unsigned int value) __latent_entropy;
77055+extern void add_interrupt_randomness(int irq, int irq_flags) __latent_entropy;
77056
77057 extern void get_random_bytes(void *buf, int nbytes);
77058 extern void get_random_bytes_arch(void *buf, int nbytes);
77059@@ -33,6 +43,11 @@ void prandom_seed(u32 seed);
77060 u32 prandom_u32_state(struct rnd_state *);
77061 void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
77062
77063+static inline unsigned long pax_get_random_long(void)
77064+{
77065+ return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
77066+}
77067+
77068 /*
77069 * Handle minimum values for seeds
77070 */
77071diff --git a/include/linux/rculist.h b/include/linux/rculist.h
77072index 4106721..132d42c 100644
77073--- a/include/linux/rculist.h
77074+++ b/include/linux/rculist.h
77075@@ -44,6 +44,9 @@ extern void __list_add_rcu(struct list_head *new,
77076 struct list_head *prev, struct list_head *next);
77077 #endif
77078
77079+extern void __pax_list_add_rcu(struct list_head *new,
77080+ struct list_head *prev, struct list_head *next);
77081+
77082 /**
77083 * list_add_rcu - add a new entry to rcu-protected list
77084 * @new: new entry to be added
77085@@ -65,6 +68,11 @@ static inline void list_add_rcu(struct list_head *new, struct list_head *head)
77086 __list_add_rcu(new, head, head->next);
77087 }
77088
77089+static inline void pax_list_add_rcu(struct list_head *new, struct list_head *head)
77090+{
77091+ __pax_list_add_rcu(new, head, head->next);
77092+}
77093+
77094 /**
77095 * list_add_tail_rcu - add a new entry to rcu-protected list
77096 * @new: new entry to be added
77097@@ -87,6 +95,12 @@ static inline void list_add_tail_rcu(struct list_head *new,
77098 __list_add_rcu(new, head->prev, head);
77099 }
77100
77101+static inline void pax_list_add_tail_rcu(struct list_head *new,
77102+ struct list_head *head)
77103+{
77104+ __pax_list_add_rcu(new, head->prev, head);
77105+}
77106+
77107 /**
77108 * list_del_rcu - deletes entry from list without re-initialization
77109 * @entry: the element to delete from the list.
77110@@ -117,6 +131,8 @@ static inline void list_del_rcu(struct list_head *entry)
77111 entry->prev = LIST_POISON2;
77112 }
77113
77114+extern void pax_list_del_rcu(struct list_head *entry);
77115+
77116 /**
77117 * hlist_del_init_rcu - deletes entry from hash list with re-initialization
77118 * @n: the element to delete from the hash list.
77119diff --git a/include/linux/reboot.h b/include/linux/reboot.h
77120index 8e00f9f..9449b55 100644
77121--- a/include/linux/reboot.h
77122+++ b/include/linux/reboot.h
77123@@ -43,9 +43,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
77124 * Architecture-specific implementations of sys_reboot commands.
77125 */
77126
77127-extern void machine_restart(char *cmd);
77128-extern void machine_halt(void);
77129-extern void machine_power_off(void);
77130+extern void machine_restart(char *cmd) __noreturn;
77131+extern void machine_halt(void) __noreturn;
77132+extern void machine_power_off(void) __noreturn;
77133
77134 extern void machine_shutdown(void);
77135 struct pt_regs;
77136@@ -56,9 +56,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
77137 */
77138
77139 extern void kernel_restart_prepare(char *cmd);
77140-extern void kernel_restart(char *cmd);
77141-extern void kernel_halt(void);
77142-extern void kernel_power_off(void);
77143+extern void kernel_restart(char *cmd) __noreturn;
77144+extern void kernel_halt(void) __noreturn;
77145+extern void kernel_power_off(void) __noreturn;
77146
77147 extern int C_A_D; /* for sysctl */
77148 void ctrl_alt_del(void);
77149@@ -72,7 +72,7 @@ extern int orderly_poweroff(bool force);
77150 * Emergency restart, callable from an interrupt handler.
77151 */
77152
77153-extern void emergency_restart(void);
77154+extern void emergency_restart(void) __noreturn;
77155 #include <asm/emergency-restart.h>
77156
77157 #endif /* _LINUX_REBOOT_H */
77158diff --git a/include/linux/regset.h b/include/linux/regset.h
77159index 8e0c9fe..ac4d221 100644
77160--- a/include/linux/regset.h
77161+++ b/include/linux/regset.h
77162@@ -161,7 +161,8 @@ struct user_regset {
77163 unsigned int align;
77164 unsigned int bias;
77165 unsigned int core_note_type;
77166-};
77167+} __do_const;
77168+typedef struct user_regset __no_const user_regset_no_const;
77169
77170 /**
77171 * struct user_regset_view - available regsets
77172diff --git a/include/linux/relay.h b/include/linux/relay.h
77173index d7c8359..818daf5 100644
77174--- a/include/linux/relay.h
77175+++ b/include/linux/relay.h
77176@@ -157,7 +157,7 @@ struct rchan_callbacks
77177 * The callback should return 0 if successful, negative if not.
77178 */
77179 int (*remove_buf_file)(struct dentry *dentry);
77180-};
77181+} __no_const;
77182
77183 /*
77184 * CONFIG_RELAY kernel API, kernel/relay.c
77185diff --git a/include/linux/rio.h b/include/linux/rio.h
77186index b71d573..2f940bd 100644
77187--- a/include/linux/rio.h
77188+++ b/include/linux/rio.h
77189@@ -355,7 +355,7 @@ struct rio_ops {
77190 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
77191 u64 rstart, u32 size, u32 flags);
77192 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
77193-};
77194+} __no_const;
77195
77196 #define RIO_RESOURCE_MEM 0x00000100
77197 #define RIO_RESOURCE_DOORBELL 0x00000200
77198diff --git a/include/linux/rmap.h b/include/linux/rmap.h
77199index 6dacb93..6174423 100644
77200--- a/include/linux/rmap.h
77201+++ b/include/linux/rmap.h
77202@@ -145,8 +145,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
77203 void anon_vma_init(void); /* create anon_vma_cachep */
77204 int anon_vma_prepare(struct vm_area_struct *);
77205 void unlink_anon_vmas(struct vm_area_struct *);
77206-int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
77207-int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
77208+int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
77209+int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
77210
77211 static inline void anon_vma_merge(struct vm_area_struct *vma,
77212 struct vm_area_struct *next)
77213diff --git a/include/linux/sched.h b/include/linux/sched.h
77214index e27baee..aaef421 100644
77215--- a/include/linux/sched.h
77216+++ b/include/linux/sched.h
77217@@ -62,6 +62,7 @@ struct bio_list;
77218 struct fs_struct;
77219 struct perf_event_context;
77220 struct blk_plug;
77221+struct linux_binprm;
77222
77223 /*
77224 * List of flags we want to share for kernel threads,
77225@@ -295,7 +296,7 @@ extern char __sched_text_start[], __sched_text_end[];
77226 extern int in_sched_functions(unsigned long addr);
77227
77228 #define MAX_SCHEDULE_TIMEOUT LONG_MAX
77229-extern signed long schedule_timeout(signed long timeout);
77230+extern signed long schedule_timeout(signed long timeout) __intentional_overflow(-1);
77231 extern signed long schedule_timeout_interruptible(signed long timeout);
77232 extern signed long schedule_timeout_killable(signed long timeout);
77233 extern signed long schedule_timeout_uninterruptible(signed long timeout);
77234@@ -306,6 +307,19 @@ struct nsproxy;
77235 struct user_namespace;
77236
77237 #ifdef CONFIG_MMU
77238+
77239+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
77240+extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
77241+#else
77242+static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
77243+{
77244+ return 0;
77245+}
77246+#endif
77247+
77248+extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
77249+extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
77250+
77251 extern void arch_pick_mmap_layout(struct mm_struct *mm);
77252 extern unsigned long
77253 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
77254@@ -581,6 +595,17 @@ struct signal_struct {
77255 #ifdef CONFIG_TASKSTATS
77256 struct taskstats *stats;
77257 #endif
77258+
77259+#ifdef CONFIG_GRKERNSEC
77260+ u32 curr_ip;
77261+ u32 saved_ip;
77262+ u32 gr_saddr;
77263+ u32 gr_daddr;
77264+ u16 gr_sport;
77265+ u16 gr_dport;
77266+ u8 used_accept:1;
77267+#endif
77268+
77269 #ifdef CONFIG_AUDIT
77270 unsigned audit_tty;
77271 unsigned audit_tty_log_passwd;
77272@@ -661,6 +686,14 @@ struct user_struct {
77273 struct key *session_keyring; /* UID's default session keyring */
77274 #endif
77275
77276+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
77277+ unsigned char kernel_banned;
77278+#endif
77279+#ifdef CONFIG_GRKERNSEC_BRUTE
77280+ unsigned char suid_banned;
77281+ unsigned long suid_ban_expires;
77282+#endif
77283+
77284 /* Hash table maintenance information */
77285 struct hlist_node uidhash_node;
77286 kuid_t uid;
77287@@ -1146,8 +1179,8 @@ struct task_struct {
77288 struct list_head thread_group;
77289
77290 struct completion *vfork_done; /* for vfork() */
77291- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
77292- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
77293+ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
77294+ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
77295
77296 cputime_t utime, stime, utimescaled, stimescaled;
77297 cputime_t gtime;
77298@@ -1172,11 +1205,6 @@ struct task_struct {
77299 struct task_cputime cputime_expires;
77300 struct list_head cpu_timers[3];
77301
77302-/* process credentials */
77303- const struct cred __rcu *real_cred; /* objective and real subjective task
77304- * credentials (COW) */
77305- const struct cred __rcu *cred; /* effective (overridable) subjective task
77306- * credentials (COW) */
77307 char comm[TASK_COMM_LEN]; /* executable name excluding path
77308 - access with [gs]et_task_comm (which lock
77309 it with task_lock())
77310@@ -1193,6 +1221,10 @@ struct task_struct {
77311 #endif
77312 /* CPU-specific state of this task */
77313 struct thread_struct thread;
77314+/* thread_info moved to task_struct */
77315+#ifdef CONFIG_X86
77316+ struct thread_info tinfo;
77317+#endif
77318 /* filesystem information */
77319 struct fs_struct *fs;
77320 /* open file information */
77321@@ -1266,6 +1298,10 @@ struct task_struct {
77322 gfp_t lockdep_reclaim_gfp;
77323 #endif
77324
77325+/* process credentials */
77326+ const struct cred __rcu *real_cred; /* objective and real subjective task
77327+ * credentials (COW) */
77328+
77329 /* journalling filesystem info */
77330 void *journal_info;
77331
77332@@ -1304,6 +1340,10 @@ struct task_struct {
77333 /* cg_list protected by css_set_lock and tsk->alloc_lock */
77334 struct list_head cg_list;
77335 #endif
77336+
77337+ const struct cred __rcu *cred; /* effective (overridable) subjective task
77338+ * credentials (COW) */
77339+
77340 #ifdef CONFIG_FUTEX
77341 struct robust_list_head __user *robust_list;
77342 #ifdef CONFIG_COMPAT
77343@@ -1407,8 +1447,78 @@ struct task_struct {
77344 unsigned int sequential_io;
77345 unsigned int sequential_io_avg;
77346 #endif
77347+
77348+#ifdef CONFIG_GRKERNSEC
77349+ /* grsecurity */
77350+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
77351+ u64 exec_id;
77352+#endif
77353+#ifdef CONFIG_GRKERNSEC_SETXID
77354+ const struct cred *delayed_cred;
77355+#endif
77356+ struct dentry *gr_chroot_dentry;
77357+ struct acl_subject_label *acl;
77358+ struct acl_subject_label *tmpacl;
77359+ struct acl_role_label *role;
77360+ struct file *exec_file;
77361+ unsigned long brute_expires;
77362+ u16 acl_role_id;
77363+ u8 inherited;
77364+ /* is this the task that authenticated to the special role */
77365+ u8 acl_sp_role;
77366+ u8 is_writable;
77367+ u8 brute;
77368+ u8 gr_is_chrooted;
77369+#endif
77370+
77371 };
77372
77373+#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
77374+#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
77375+#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
77376+#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
77377+/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
77378+#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
77379+
77380+#ifdef CONFIG_PAX_SOFTMODE
77381+extern int pax_softmode;
77382+#endif
77383+
77384+extern int pax_check_flags(unsigned long *);
77385+
77386+/* if tsk != current then task_lock must be held on it */
77387+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
77388+static inline unsigned long pax_get_flags(struct task_struct *tsk)
77389+{
77390+ if (likely(tsk->mm))
77391+ return tsk->mm->pax_flags;
77392+ else
77393+ return 0UL;
77394+}
77395+
77396+/* if tsk != current then task_lock must be held on it */
77397+static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
77398+{
77399+ if (likely(tsk->mm)) {
77400+ tsk->mm->pax_flags = flags;
77401+ return 0;
77402+ }
77403+ return -EINVAL;
77404+}
77405+#endif
77406+
77407+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
77408+extern void pax_set_initial_flags(struct linux_binprm *bprm);
77409+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
77410+extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
77411+#endif
77412+
77413+struct path;
77414+extern char *pax_get_path(const struct path *path, char *buf, int buflen);
77415+extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
77416+extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
77417+extern void pax_report_refcount_overflow(struct pt_regs *regs);
77418+
77419 /* Future-safe accessor for struct task_struct's cpus_allowed. */
77420 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
77421
77422@@ -1467,7 +1577,7 @@ struct pid_namespace;
77423 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
77424 struct pid_namespace *ns);
77425
77426-static inline pid_t task_pid_nr(struct task_struct *tsk)
77427+static inline pid_t task_pid_nr(const struct task_struct *tsk)
77428 {
77429 return tsk->pid;
77430 }
77431@@ -1917,7 +2027,9 @@ void yield(void);
77432 extern struct exec_domain default_exec_domain;
77433
77434 union thread_union {
77435+#ifndef CONFIG_X86
77436 struct thread_info thread_info;
77437+#endif
77438 unsigned long stack[THREAD_SIZE/sizeof(long)];
77439 };
77440
77441@@ -1950,6 +2062,7 @@ extern struct pid_namespace init_pid_ns;
77442 */
77443
77444 extern struct task_struct *find_task_by_vpid(pid_t nr);
77445+extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
77446 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
77447 struct pid_namespace *ns);
77448
77449@@ -2114,7 +2227,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
77450 extern void exit_itimers(struct signal_struct *);
77451 extern void flush_itimer_signals(void);
77452
77453-extern void do_group_exit(int);
77454+extern __noreturn void do_group_exit(int);
77455
77456 extern int allow_signal(int);
77457 extern int disallow_signal(int);
77458@@ -2305,9 +2418,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
77459
77460 #endif
77461
77462-static inline int object_is_on_stack(void *obj)
77463+static inline int object_starts_on_stack(void *obj)
77464 {
77465- void *stack = task_stack_page(current);
77466+ const void *stack = task_stack_page(current);
77467
77468 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
77469 }
77470diff --git a/include/linux/sched/sysctl.h b/include/linux/sched/sysctl.h
77471index bf8086b..962b035 100644
77472--- a/include/linux/sched/sysctl.h
77473+++ b/include/linux/sched/sysctl.h
77474@@ -30,6 +30,7 @@ enum { sysctl_hung_task_timeout_secs = 0 };
77475 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
77476
77477 extern int sysctl_max_map_count;
77478+extern unsigned long sysctl_heap_stack_gap;
77479
77480 extern unsigned int sysctl_sched_latency;
77481 extern unsigned int sysctl_sched_min_granularity;
77482diff --git a/include/linux/security.h b/include/linux/security.h
77483index 9d37e2b..43368e4 100644
77484--- a/include/linux/security.h
77485+++ b/include/linux/security.h
77486@@ -27,6 +27,7 @@
77487 #include <linux/slab.h>
77488 #include <linux/err.h>
77489 #include <linux/string.h>
77490+#include <linux/grsecurity.h>
77491
77492 struct linux_binprm;
77493 struct cred;
77494@@ -116,8 +117,6 @@ struct seq_file;
77495
77496 extern int cap_netlink_send(struct sock *sk, struct sk_buff *skb);
77497
77498-void reset_security_ops(void);
77499-
77500 #ifdef CONFIG_MMU
77501 extern unsigned long mmap_min_addr;
77502 extern unsigned long dac_mmap_min_addr;
77503diff --git a/include/linux/semaphore.h b/include/linux/semaphore.h
77504index dc368b8..e895209 100644
77505--- a/include/linux/semaphore.h
77506+++ b/include/linux/semaphore.h
77507@@ -37,7 +37,7 @@ static inline void sema_init(struct semaphore *sem, int val)
77508 }
77509
77510 extern void down(struct semaphore *sem);
77511-extern int __must_check down_interruptible(struct semaphore *sem);
77512+extern int __must_check down_interruptible(struct semaphore *sem) __intentional_overflow(-1);
77513 extern int __must_check down_killable(struct semaphore *sem);
77514 extern int __must_check down_trylock(struct semaphore *sem);
77515 extern int __must_check down_timeout(struct semaphore *sem, long jiffies);
77516diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
77517index 4e32edc..f8f2d18 100644
77518--- a/include/linux/seq_file.h
77519+++ b/include/linux/seq_file.h
77520@@ -26,6 +26,9 @@ struct seq_file {
77521 struct mutex lock;
77522 const struct seq_operations *op;
77523 int poll_event;
77524+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
77525+ u64 exec_id;
77526+#endif
77527 #ifdef CONFIG_USER_NS
77528 struct user_namespace *user_ns;
77529 #endif
77530@@ -38,6 +41,7 @@ struct seq_operations {
77531 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
77532 int (*show) (struct seq_file *m, void *v);
77533 };
77534+typedef struct seq_operations __no_const seq_operations_no_const;
77535
77536 #define SEQ_SKIP 1
77537
77538diff --git a/include/linux/shm.h b/include/linux/shm.h
77539index 429c199..4d42e38 100644
77540--- a/include/linux/shm.h
77541+++ b/include/linux/shm.h
77542@@ -21,6 +21,10 @@ struct shmid_kernel /* private to the kernel */
77543
77544 /* The task created the shm object. NULL if the task is dead. */
77545 struct task_struct *shm_creator;
77546+#ifdef CONFIG_GRKERNSEC
77547+ time_t shm_createtime;
77548+ pid_t shm_lapid;
77549+#endif
77550 };
77551
77552 /* shm_mode upper byte flags */
77553diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
77554index c2d8933..b2b4ed6 100644
77555--- a/include/linux/skbuff.h
77556+++ b/include/linux/skbuff.h
77557@@ -648,7 +648,7 @@ extern bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
77558 extern struct sk_buff *__alloc_skb(unsigned int size,
77559 gfp_t priority, int flags, int node);
77560 extern struct sk_buff *build_skb(void *data, unsigned int frag_size);
77561-static inline struct sk_buff *alloc_skb(unsigned int size,
77562+static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
77563 gfp_t priority)
77564 {
77565 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
77566@@ -764,7 +764,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
77567 */
77568 static inline int skb_queue_empty(const struct sk_buff_head *list)
77569 {
77570- return list->next == (struct sk_buff *)list;
77571+ return list->next == (const struct sk_buff *)list;
77572 }
77573
77574 /**
77575@@ -777,7 +777,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
77576 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
77577 const struct sk_buff *skb)
77578 {
77579- return skb->next == (struct sk_buff *)list;
77580+ return skb->next == (const struct sk_buff *)list;
77581 }
77582
77583 /**
77584@@ -790,7 +790,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
77585 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
77586 const struct sk_buff *skb)
77587 {
77588- return skb->prev == (struct sk_buff *)list;
77589+ return skb->prev == (const struct sk_buff *)list;
77590 }
77591
77592 /**
77593@@ -1750,7 +1750,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
77594 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
77595 */
77596 #ifndef NET_SKB_PAD
77597-#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
77598+#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
77599 #endif
77600
77601 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
77602@@ -2348,7 +2348,7 @@ extern struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags,
77603 int noblock, int *err);
77604 extern unsigned int datagram_poll(struct file *file, struct socket *sock,
77605 struct poll_table_struct *wait);
77606-extern int skb_copy_datagram_iovec(const struct sk_buff *from,
77607+extern int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from,
77608 int offset, struct iovec *to,
77609 int size);
77610 extern int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb,
77611@@ -2643,6 +2643,9 @@ static inline void nf_reset(struct sk_buff *skb)
77612 nf_bridge_put(skb->nf_bridge);
77613 skb->nf_bridge = NULL;
77614 #endif
77615+#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
77616+ skb->nf_trace = 0;
77617+#endif
77618 }
77619
77620 static inline void nf_reset_trace(struct sk_buff *skb)
77621diff --git a/include/linux/slab.h b/include/linux/slab.h
77622index 74f1058..914b7da 100644
77623--- a/include/linux/slab.h
77624+++ b/include/linux/slab.h
77625@@ -14,15 +14,29 @@
77626 #include <linux/gfp.h>
77627 #include <linux/types.h>
77628 #include <linux/workqueue.h>
77629-
77630+#include <linux/err.h>
77631
77632 /*
77633 * Flags to pass to kmem_cache_create().
77634 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
77635 */
77636 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
77637+
77638+#ifdef CONFIG_PAX_USERCOPY_SLABS
77639+#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
77640+#else
77641+#define SLAB_USERCOPY 0x00000000UL
77642+#endif
77643+
77644 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
77645 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
77646+
77647+#ifdef CONFIG_PAX_MEMORY_SANITIZE
77648+#define SLAB_NO_SANITIZE 0x00001000UL /* PaX: Do not sanitize objs on free */
77649+#else
77650+#define SLAB_NO_SANITIZE 0x00000000UL
77651+#endif
77652+
77653 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
77654 #define SLAB_CACHE_DMA 0x00004000UL /* Use GFP_DMA memory */
77655 #define SLAB_STORE_USER 0x00010000UL /* DEBUG: Store the last owner for bug hunting */
77656@@ -91,10 +105,13 @@
77657 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
77658 * Both make kfree a no-op.
77659 */
77660-#define ZERO_SIZE_PTR ((void *)16)
77661+#define ZERO_SIZE_PTR \
77662+({ \
77663+ BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
77664+ (void *)(-MAX_ERRNO-1L); \
77665+})
77666
77667-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
77668- (unsigned long)ZERO_SIZE_PTR)
77669+#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
77670
77671 #include <linux/kmemleak.h>
77672
77673@@ -135,6 +152,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
77674 void kfree(const void *);
77675 void kzfree(const void *);
77676 size_t ksize(const void *);
77677+const char *check_heap_object(const void *ptr, unsigned long n);
77678+bool is_usercopy_object(const void *ptr);
77679
77680 /*
77681 * Some archs want to perform DMA into kmalloc caches and need a guaranteed
77682@@ -167,7 +186,7 @@ struct kmem_cache {
77683 unsigned int align; /* Alignment as calculated */
77684 unsigned long flags; /* Active flags on the slab */
77685 const char *name; /* Slab name for sysfs */
77686- int refcount; /* Use counter */
77687+ atomic_t refcount; /* Use counter */
77688 void (*ctor)(void *); /* Called on object slot creation */
77689 struct list_head list; /* List of all slab caches on the system */
77690 };
77691@@ -241,6 +260,10 @@ extern struct kmem_cache *kmalloc_caches[KMALLOC_SHIFT_HIGH + 1];
77692 extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
77693 #endif
77694
77695+#ifdef CONFIG_PAX_USERCOPY_SLABS
77696+extern struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
77697+#endif
77698+
77699 /*
77700 * Figure out which kmalloc slab an allocation of a certain size
77701 * belongs to.
77702@@ -249,7 +272,7 @@ extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
77703 * 2 = 120 .. 192 bytes
77704 * n = 2^(n-1) .. 2^n -1
77705 */
77706-static __always_inline int kmalloc_index(size_t size)
77707+static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
77708 {
77709 if (!size)
77710 return 0;
77711@@ -292,11 +315,11 @@ static __always_inline int kmalloc_index(size_t size)
77712 }
77713 #endif /* !CONFIG_SLOB */
77714
77715-void *__kmalloc(size_t size, gfp_t flags);
77716+void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1);
77717 void *kmem_cache_alloc(struct kmem_cache *, gfp_t flags);
77718
77719 #ifdef CONFIG_NUMA
77720-void *__kmalloc_node(size_t size, gfp_t flags, int node);
77721+void *__kmalloc_node(size_t size, gfp_t flags, int node) __alloc_size(1);
77722 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
77723 #else
77724 static __always_inline void *__kmalloc_node(size_t size, gfp_t flags, int node)
77725diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
77726index e9346b4..1494959 100644
77727--- a/include/linux/slab_def.h
77728+++ b/include/linux/slab_def.h
77729@@ -36,7 +36,7 @@ struct kmem_cache {
77730 /* 4) cache creation/removal */
77731 const char *name;
77732 struct list_head list;
77733- int refcount;
77734+ atomic_t refcount;
77735 int object_size;
77736 int align;
77737
77738@@ -52,10 +52,14 @@ struct kmem_cache {
77739 unsigned long node_allocs;
77740 unsigned long node_frees;
77741 unsigned long node_overflow;
77742- atomic_t allochit;
77743- atomic_t allocmiss;
77744- atomic_t freehit;
77745- atomic_t freemiss;
77746+ atomic_unchecked_t allochit;
77747+ atomic_unchecked_t allocmiss;
77748+ atomic_unchecked_t freehit;
77749+ atomic_unchecked_t freemiss;
77750+#ifdef CONFIG_PAX_MEMORY_SANITIZE
77751+ atomic_unchecked_t sanitized;
77752+ atomic_unchecked_t not_sanitized;
77753+#endif
77754
77755 /*
77756 * If debugging is enabled, then the allocator can add additional
77757diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
77758index cc0b67e..a0329b1 100644
77759--- a/include/linux/slub_def.h
77760+++ b/include/linux/slub_def.h
77761@@ -74,7 +74,7 @@ struct kmem_cache {
77762 struct kmem_cache_order_objects max;
77763 struct kmem_cache_order_objects min;
77764 gfp_t allocflags; /* gfp flags to use on each alloc */
77765- int refcount; /* Refcount for slab cache destroy */
77766+ atomic_t refcount; /* Refcount for slab cache destroy */
77767 void (*ctor)(void *);
77768 int inuse; /* Offset to metadata */
77769 int align; /* Alignment */
77770diff --git a/include/linux/smp.h b/include/linux/smp.h
77771index 731f523..3340268 100644
77772--- a/include/linux/smp.h
77773+++ b/include/linux/smp.h
77774@@ -186,7 +186,9 @@ static inline void __smp_call_function_single(int cpuid,
77775 #endif
77776
77777 #define get_cpu() ({ preempt_disable(); smp_processor_id(); })
77778+#define raw_get_cpu() ({ raw_preempt_disable(); raw_smp_processor_id(); })
77779 #define put_cpu() preempt_enable()
77780+#define raw_put_cpu_no_resched() raw_preempt_enable_no_resched()
77781
77782 /*
77783 * Callback to arch code if there's nosmp or maxcpus=0 on the
77784diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h
77785index 54f91d3..be2c379 100644
77786--- a/include/linux/sock_diag.h
77787+++ b/include/linux/sock_diag.h
77788@@ -11,7 +11,7 @@ struct sock;
77789 struct sock_diag_handler {
77790 __u8 family;
77791 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
77792-};
77793+} __do_const;
77794
77795 int sock_diag_register(const struct sock_diag_handler *h);
77796 void sock_diag_unregister(const struct sock_diag_handler *h);
77797diff --git a/include/linux/sonet.h b/include/linux/sonet.h
77798index 680f9a3..f13aeb0 100644
77799--- a/include/linux/sonet.h
77800+++ b/include/linux/sonet.h
77801@@ -7,7 +7,7 @@
77802 #include <uapi/linux/sonet.h>
77803
77804 struct k_sonet_stats {
77805-#define __HANDLE_ITEM(i) atomic_t i
77806+#define __HANDLE_ITEM(i) atomic_unchecked_t i
77807 __SONET_ITEMS
77808 #undef __HANDLE_ITEM
77809 };
77810diff --git a/include/linux/sunrpc/addr.h b/include/linux/sunrpc/addr.h
77811index 07d8e53..dc934c9 100644
77812--- a/include/linux/sunrpc/addr.h
77813+++ b/include/linux/sunrpc/addr.h
77814@@ -23,9 +23,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
77815 {
77816 switch (sap->sa_family) {
77817 case AF_INET:
77818- return ntohs(((struct sockaddr_in *)sap)->sin_port);
77819+ return ntohs(((const struct sockaddr_in *)sap)->sin_port);
77820 case AF_INET6:
77821- return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
77822+ return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
77823 }
77824 return 0;
77825 }
77826@@ -58,7 +58,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
77827 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
77828 const struct sockaddr *src)
77829 {
77830- const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
77831+ const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
77832 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
77833
77834 dsin->sin_family = ssin->sin_family;
77835@@ -164,7 +164,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
77836 if (sa->sa_family != AF_INET6)
77837 return 0;
77838
77839- return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
77840+ return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
77841 }
77842
77843 #endif /* _LINUX_SUNRPC_ADDR_H */
77844diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
77845index 6740801..c535f27 100644
77846--- a/include/linux/sunrpc/clnt.h
77847+++ b/include/linux/sunrpc/clnt.h
77848@@ -96,7 +96,7 @@ struct rpc_procinfo {
77849 unsigned int p_timer; /* Which RTT timer to use */
77850 u32 p_statidx; /* Which procedure to account */
77851 const char * p_name; /* name of procedure */
77852-};
77853+} __do_const;
77854
77855 #ifdef __KERNEL__
77856
77857diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
77858index 6eecfc2..7ada79d 100644
77859--- a/include/linux/sunrpc/svc.h
77860+++ b/include/linux/sunrpc/svc.h
77861@@ -410,7 +410,7 @@ struct svc_procedure {
77862 unsigned int pc_count; /* call count */
77863 unsigned int pc_cachetype; /* cache info (NFS) */
77864 unsigned int pc_xdrressize; /* maximum size of XDR reply */
77865-};
77866+} __do_const;
77867
77868 /*
77869 * Function prototypes.
77870diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
77871index 0b8e3e6..33e0a01 100644
77872--- a/include/linux/sunrpc/svc_rdma.h
77873+++ b/include/linux/sunrpc/svc_rdma.h
77874@@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
77875 extern unsigned int svcrdma_max_requests;
77876 extern unsigned int svcrdma_max_req_size;
77877
77878-extern atomic_t rdma_stat_recv;
77879-extern atomic_t rdma_stat_read;
77880-extern atomic_t rdma_stat_write;
77881-extern atomic_t rdma_stat_sq_starve;
77882-extern atomic_t rdma_stat_rq_starve;
77883-extern atomic_t rdma_stat_rq_poll;
77884-extern atomic_t rdma_stat_rq_prod;
77885-extern atomic_t rdma_stat_sq_poll;
77886-extern atomic_t rdma_stat_sq_prod;
77887+extern atomic_unchecked_t rdma_stat_recv;
77888+extern atomic_unchecked_t rdma_stat_read;
77889+extern atomic_unchecked_t rdma_stat_write;
77890+extern atomic_unchecked_t rdma_stat_sq_starve;
77891+extern atomic_unchecked_t rdma_stat_rq_starve;
77892+extern atomic_unchecked_t rdma_stat_rq_poll;
77893+extern atomic_unchecked_t rdma_stat_rq_prod;
77894+extern atomic_unchecked_t rdma_stat_sq_poll;
77895+extern atomic_unchecked_t rdma_stat_sq_prod;
77896
77897 #define RPCRDMA_VERSION 1
77898
77899diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
77900index 8d71d65..f79586e 100644
77901--- a/include/linux/sunrpc/svcauth.h
77902+++ b/include/linux/sunrpc/svcauth.h
77903@@ -120,7 +120,7 @@ struct auth_ops {
77904 int (*release)(struct svc_rqst *rq);
77905 void (*domain_release)(struct auth_domain *);
77906 int (*set_client)(struct svc_rqst *rq);
77907-};
77908+} __do_const;
77909
77910 #define SVC_GARBAGE 1
77911 #define SVC_SYSERR 2
77912diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
77913index a5ffd32..0935dea 100644
77914--- a/include/linux/swiotlb.h
77915+++ b/include/linux/swiotlb.h
77916@@ -60,7 +60,8 @@ extern void
77917
77918 extern void
77919 swiotlb_free_coherent(struct device *hwdev, size_t size,
77920- void *vaddr, dma_addr_t dma_handle);
77921+ void *vaddr, dma_addr_t dma_handle,
77922+ struct dma_attrs *attrs);
77923
77924 extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
77925 unsigned long offset, size_t size,
77926diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
77927index 7fac04e..de57300 100644
77928--- a/include/linux/syscalls.h
77929+++ b/include/linux/syscalls.h
77930@@ -97,8 +97,14 @@ struct sigaltstack;
77931 #define __MAP(n,...) __MAP##n(__VA_ARGS__)
77932
77933 #define __SC_DECL(t, a) t a
77934+#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))
77935 #define __TYPE_IS_LL(t) (__same_type((t)0, 0LL) || __same_type((t)0, 0ULL))
77936-#define __SC_LONG(t, a) __typeof(__builtin_choose_expr(__TYPE_IS_LL(t), 0LL, 0L)) a
77937+#define __SC_LONG(t, a) __typeof( \
77938+ __builtin_choose_expr( \
77939+ sizeof(t) > sizeof(int), \
77940+ (t) 0, \
77941+ __builtin_choose_expr(__TYPE_IS_U(t), 0UL, 0L) \
77942+ )) a
77943 #define __SC_CAST(t, a) (t) a
77944 #define __SC_ARGS(t, a) a
77945 #define __SC_TEST(t, a) (void)BUILD_BUG_ON_ZERO(!__TYPE_IS_LL(t) && sizeof(t) > sizeof(long))
77946@@ -363,11 +369,11 @@ asmlinkage long sys_sync(void);
77947 asmlinkage long sys_fsync(unsigned int fd);
77948 asmlinkage long sys_fdatasync(unsigned int fd);
77949 asmlinkage long sys_bdflush(int func, long data);
77950-asmlinkage long sys_mount(char __user *dev_name, char __user *dir_name,
77951- char __user *type, unsigned long flags,
77952+asmlinkage long sys_mount(const char __user *dev_name, const char __user *dir_name,
77953+ const char __user *type, unsigned long flags,
77954 void __user *data);
77955-asmlinkage long sys_umount(char __user *name, int flags);
77956-asmlinkage long sys_oldumount(char __user *name);
77957+asmlinkage long sys_umount(const char __user *name, int flags);
77958+asmlinkage long sys_oldumount(const char __user *name);
77959 asmlinkage long sys_truncate(const char __user *path, long length);
77960 asmlinkage long sys_ftruncate(unsigned int fd, unsigned long length);
77961 asmlinkage long sys_stat(const char __user *filename,
77962@@ -579,7 +585,7 @@ asmlinkage long sys_getsockname(int, struct sockaddr __user *, int __user *);
77963 asmlinkage long sys_getpeername(int, struct sockaddr __user *, int __user *);
77964 asmlinkage long sys_send(int, void __user *, size_t, unsigned);
77965 asmlinkage long sys_sendto(int, void __user *, size_t, unsigned,
77966- struct sockaddr __user *, int);
77967+ struct sockaddr __user *, int) __intentional_overflow(0);
77968 asmlinkage long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags);
77969 asmlinkage long sys_sendmmsg(int fd, struct mmsghdr __user *msg,
77970 unsigned int vlen, unsigned flags);
77971diff --git a/include/linux/syscore_ops.h b/include/linux/syscore_ops.h
77972index 27b3b0b..e093dd9 100644
77973--- a/include/linux/syscore_ops.h
77974+++ b/include/linux/syscore_ops.h
77975@@ -16,7 +16,7 @@ struct syscore_ops {
77976 int (*suspend)(void);
77977 void (*resume)(void);
77978 void (*shutdown)(void);
77979-};
77980+} __do_const;
77981
77982 extern void register_syscore_ops(struct syscore_ops *ops);
77983 extern void unregister_syscore_ops(struct syscore_ops *ops);
77984diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
77985index 14a8ff2..af52bad 100644
77986--- a/include/linux/sysctl.h
77987+++ b/include/linux/sysctl.h
77988@@ -34,13 +34,13 @@ struct ctl_table_root;
77989 struct ctl_table_header;
77990 struct ctl_dir;
77991
77992-typedef struct ctl_table ctl_table;
77993-
77994 typedef int proc_handler (struct ctl_table *ctl, int write,
77995 void __user *buffer, size_t *lenp, loff_t *ppos);
77996
77997 extern int proc_dostring(struct ctl_table *, int,
77998 void __user *, size_t *, loff_t *);
77999+extern int proc_dostring_modpriv(struct ctl_table *, int,
78000+ void __user *, size_t *, loff_t *);
78001 extern int proc_dointvec(struct ctl_table *, int,
78002 void __user *, size_t *, loff_t *);
78003 extern int proc_dointvec_minmax(struct ctl_table *, int,
78004@@ -115,7 +115,9 @@ struct ctl_table
78005 struct ctl_table_poll *poll;
78006 void *extra1;
78007 void *extra2;
78008-};
78009+} __do_const;
78010+typedef struct ctl_table __no_const ctl_table_no_const;
78011+typedef struct ctl_table ctl_table;
78012
78013 struct ctl_node {
78014 struct rb_node node;
78015diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
78016index 11baec7..706f99f 100644
78017--- a/include/linux/sysfs.h
78018+++ b/include/linux/sysfs.h
78019@@ -33,7 +33,8 @@ struct attribute {
78020 struct lock_class_key *key;
78021 struct lock_class_key skey;
78022 #endif
78023-};
78024+} __do_const;
78025+typedef struct attribute __no_const attribute_no_const;
78026
78027 /**
78028 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
78029@@ -62,7 +63,8 @@ struct attribute_group {
78030 struct attribute *, int);
78031 struct attribute **attrs;
78032 struct bin_attribute **bin_attrs;
78033-};
78034+} __do_const;
78035+typedef struct attribute_group __no_const attribute_group_no_const;
78036
78037 /**
78038 * Use these macros to make defining attributes easier. See include/linux/device.h
78039@@ -126,7 +128,8 @@ struct bin_attribute {
78040 char *, loff_t, size_t);
78041 int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
78042 struct vm_area_struct *vma);
78043-};
78044+} __do_const;
78045+typedef struct bin_attribute __no_const bin_attribute_no_const;
78046
78047 /**
78048 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
78049diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
78050index 7faf933..9b85a0c 100644
78051--- a/include/linux/sysrq.h
78052+++ b/include/linux/sysrq.h
78053@@ -16,6 +16,7 @@
78054
78055 #include <linux/errno.h>
78056 #include <linux/types.h>
78057+#include <linux/compiler.h>
78058
78059 /* Enable/disable SYSRQ support by default (0==no, 1==yes). */
78060 #define SYSRQ_DEFAULT_ENABLE 1
78061@@ -36,7 +37,7 @@ struct sysrq_key_op {
78062 char *help_msg;
78063 char *action_msg;
78064 int enable_mask;
78065-};
78066+} __do_const;
78067
78068 #ifdef CONFIG_MAGIC_SYSRQ
78069
78070diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
78071index e7e0473..7989295 100644
78072--- a/include/linux/thread_info.h
78073+++ b/include/linux/thread_info.h
78074@@ -148,6 +148,15 @@ static inline bool test_and_clear_restore_sigmask(void)
78075 #error "no set_restore_sigmask() provided and default one won't work"
78076 #endif
78077
78078+extern void __check_object_size(const void *ptr, unsigned long n, bool to_user);
78079+static inline void check_object_size(const void *ptr, unsigned long n, bool to_user)
78080+{
78081+#ifndef CONFIG_PAX_USERCOPY_DEBUG
78082+ if (!__builtin_constant_p(n))
78083+#endif
78084+ __check_object_size(ptr, n, to_user);
78085+}
78086+
78087 #endif /* __KERNEL__ */
78088
78089 #endif /* _LINUX_THREAD_INFO_H */
78090diff --git a/include/linux/tty.h b/include/linux/tty.h
78091index 64f8646..1515fc7 100644
78092--- a/include/linux/tty.h
78093+++ b/include/linux/tty.h
78094@@ -197,7 +197,7 @@ struct tty_port {
78095 const struct tty_port_operations *ops; /* Port operations */
78096 spinlock_t lock; /* Lock protecting tty field */
78097 int blocked_open; /* Waiting to open */
78098- int count; /* Usage count */
78099+ atomic_t count; /* Usage count */
78100 wait_queue_head_t open_wait; /* Open waiters */
78101 wait_queue_head_t close_wait; /* Close waiters */
78102 wait_queue_head_t delta_msr_wait; /* Modem status change */
78103@@ -546,7 +546,7 @@ extern int tty_port_open(struct tty_port *port,
78104 struct tty_struct *tty, struct file *filp);
78105 static inline int tty_port_users(struct tty_port *port)
78106 {
78107- return port->count + port->blocked_open;
78108+ return atomic_read(&port->count) + port->blocked_open;
78109 }
78110
78111 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
78112diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
78113index 756a609..b302dd6 100644
78114--- a/include/linux/tty_driver.h
78115+++ b/include/linux/tty_driver.h
78116@@ -285,7 +285,7 @@ struct tty_operations {
78117 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
78118 #endif
78119 const struct file_operations *proc_fops;
78120-};
78121+} __do_const;
78122
78123 struct tty_driver {
78124 int magic; /* magic number for this structure */
78125diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
78126index f15c898..207b7d1 100644
78127--- a/include/linux/tty_ldisc.h
78128+++ b/include/linux/tty_ldisc.h
78129@@ -211,7 +211,7 @@ struct tty_ldisc_ops {
78130
78131 struct module *owner;
78132
78133- int refcount;
78134+ atomic_t refcount;
78135 };
78136
78137 struct tty_ldisc {
78138diff --git a/include/linux/types.h b/include/linux/types.h
78139index 4d118ba..c3ee9bf 100644
78140--- a/include/linux/types.h
78141+++ b/include/linux/types.h
78142@@ -176,10 +176,26 @@ typedef struct {
78143 int counter;
78144 } atomic_t;
78145
78146+#ifdef CONFIG_PAX_REFCOUNT
78147+typedef struct {
78148+ int counter;
78149+} atomic_unchecked_t;
78150+#else
78151+typedef atomic_t atomic_unchecked_t;
78152+#endif
78153+
78154 #ifdef CONFIG_64BIT
78155 typedef struct {
78156 long counter;
78157 } atomic64_t;
78158+
78159+#ifdef CONFIG_PAX_REFCOUNT
78160+typedef struct {
78161+ long counter;
78162+} atomic64_unchecked_t;
78163+#else
78164+typedef atomic64_t atomic64_unchecked_t;
78165+#endif
78166 #endif
78167
78168 struct list_head {
78169diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
78170index 5ca0951..ab496a5 100644
78171--- a/include/linux/uaccess.h
78172+++ b/include/linux/uaccess.h
78173@@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
78174 long ret; \
78175 mm_segment_t old_fs = get_fs(); \
78176 \
78177- set_fs(KERNEL_DS); \
78178 pagefault_disable(); \
78179- ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
78180- pagefault_enable(); \
78181+ set_fs(KERNEL_DS); \
78182+ ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
78183 set_fs(old_fs); \
78184+ pagefault_enable(); \
78185 ret; \
78186 })
78187
78188diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h
78189index 8e522cbc..aa8572d 100644
78190--- a/include/linux/uidgid.h
78191+++ b/include/linux/uidgid.h
78192@@ -197,4 +197,9 @@ static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid)
78193
78194 #endif /* CONFIG_USER_NS */
78195
78196+#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
78197+#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
78198+#define gr_is_global_root(x) uid_eq((x), GLOBAL_ROOT_UID)
78199+#define gr_is_global_nonroot(x) (!uid_eq((x), GLOBAL_ROOT_UID))
78200+
78201 #endif /* _LINUX_UIDGID_H */
78202diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
78203index 99c1b4d..562e6f3 100644
78204--- a/include/linux/unaligned/access_ok.h
78205+++ b/include/linux/unaligned/access_ok.h
78206@@ -4,34 +4,34 @@
78207 #include <linux/kernel.h>
78208 #include <asm/byteorder.h>
78209
78210-static inline u16 get_unaligned_le16(const void *p)
78211+static inline u16 __intentional_overflow(-1) get_unaligned_le16(const void *p)
78212 {
78213- return le16_to_cpup((__le16 *)p);
78214+ return le16_to_cpup((const __le16 *)p);
78215 }
78216
78217-static inline u32 get_unaligned_le32(const void *p)
78218+static inline u32 __intentional_overflow(-1) get_unaligned_le32(const void *p)
78219 {
78220- return le32_to_cpup((__le32 *)p);
78221+ return le32_to_cpup((const __le32 *)p);
78222 }
78223
78224-static inline u64 get_unaligned_le64(const void *p)
78225+static inline u64 __intentional_overflow(-1) get_unaligned_le64(const void *p)
78226 {
78227- return le64_to_cpup((__le64 *)p);
78228+ return le64_to_cpup((const __le64 *)p);
78229 }
78230
78231-static inline u16 get_unaligned_be16(const void *p)
78232+static inline u16 __intentional_overflow(-1) get_unaligned_be16(const void *p)
78233 {
78234- return be16_to_cpup((__be16 *)p);
78235+ return be16_to_cpup((const __be16 *)p);
78236 }
78237
78238-static inline u32 get_unaligned_be32(const void *p)
78239+static inline u32 __intentional_overflow(-1) get_unaligned_be32(const void *p)
78240 {
78241- return be32_to_cpup((__be32 *)p);
78242+ return be32_to_cpup((const __be32 *)p);
78243 }
78244
78245-static inline u64 get_unaligned_be64(const void *p)
78246+static inline u64 __intentional_overflow(-1) get_unaligned_be64(const void *p)
78247 {
78248- return be64_to_cpup((__be64 *)p);
78249+ return be64_to_cpup((const __be64 *)p);
78250 }
78251
78252 static inline void put_unaligned_le16(u16 val, void *p)
78253diff --git a/include/linux/usb.h b/include/linux/usb.h
78254index 001629c..7c1cc9b 100644
78255--- a/include/linux/usb.h
78256+++ b/include/linux/usb.h
78257@@ -561,7 +561,7 @@ struct usb_device {
78258 int maxchild;
78259
78260 u32 quirks;
78261- atomic_t urbnum;
78262+ atomic_unchecked_t urbnum;
78263
78264 unsigned long active_duration;
78265
78266@@ -1635,7 +1635,7 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
78267
78268 extern int usb_control_msg(struct usb_device *dev, unsigned int pipe,
78269 __u8 request, __u8 requesttype, __u16 value, __u16 index,
78270- void *data, __u16 size, int timeout);
78271+ void *data, __u16 size, int timeout) __intentional_overflow(-1);
78272 extern int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
78273 void *data, int len, int *actual_length, int timeout);
78274 extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
78275diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
78276index e452ba6..78f8e80 100644
78277--- a/include/linux/usb/renesas_usbhs.h
78278+++ b/include/linux/usb/renesas_usbhs.h
78279@@ -39,7 +39,7 @@ enum {
78280 */
78281 struct renesas_usbhs_driver_callback {
78282 int (*notify_hotplug)(struct platform_device *pdev);
78283-};
78284+} __no_const;
78285
78286 /*
78287 * callback functions for platform
78288diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
78289index 6f8fbcf..8259001 100644
78290--- a/include/linux/vermagic.h
78291+++ b/include/linux/vermagic.h
78292@@ -25,9 +25,35 @@
78293 #define MODULE_ARCH_VERMAGIC ""
78294 #endif
78295
78296+#ifdef CONFIG_PAX_REFCOUNT
78297+#define MODULE_PAX_REFCOUNT "REFCOUNT "
78298+#else
78299+#define MODULE_PAX_REFCOUNT ""
78300+#endif
78301+
78302+#ifdef CONSTIFY_PLUGIN
78303+#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
78304+#else
78305+#define MODULE_CONSTIFY_PLUGIN ""
78306+#endif
78307+
78308+#ifdef STACKLEAK_PLUGIN
78309+#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
78310+#else
78311+#define MODULE_STACKLEAK_PLUGIN ""
78312+#endif
78313+
78314+#ifdef CONFIG_GRKERNSEC
78315+#define MODULE_GRSEC "GRSEC "
78316+#else
78317+#define MODULE_GRSEC ""
78318+#endif
78319+
78320 #define VERMAGIC_STRING \
78321 UTS_RELEASE " " \
78322 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
78323 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
78324- MODULE_ARCH_VERMAGIC
78325+ MODULE_ARCH_VERMAGIC \
78326+ MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
78327+ MODULE_GRSEC
78328
78329diff --git a/include/linux/vga_switcheroo.h b/include/linux/vga_switcheroo.h
78330index 502073a..a7de024 100644
78331--- a/include/linux/vga_switcheroo.h
78332+++ b/include/linux/vga_switcheroo.h
78333@@ -63,8 +63,8 @@ int vga_switcheroo_get_client_state(struct pci_dev *dev);
78334
78335 void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic);
78336
78337-int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain);
78338-int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain);
78339+int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain);
78340+int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain);
78341 #else
78342
78343 static inline void vga_switcheroo_unregister_client(struct pci_dev *dev) {}
78344@@ -81,8 +81,8 @@ static inline int vga_switcheroo_get_client_state(struct pci_dev *dev) { return
78345
78346 static inline void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic) {}
78347
78348-static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
78349-static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
78350+static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
78351+static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
78352
78353 #endif
78354 #endif /* _LINUX_VGA_SWITCHEROO_H_ */
78355diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
78356index 4b8a891..cc929b4 100644
78357--- a/include/linux/vmalloc.h
78358+++ b/include/linux/vmalloc.h
78359@@ -16,6 +16,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
78360 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
78361 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
78362 #define VM_UNINITIALIZED 0x00000020 /* vm_struct is not fully initialized */
78363+
78364+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
78365+#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
78366+#endif
78367+
78368 /* bits [20..32] reserved for arch specific ioremap internals */
78369
78370 /*
78371@@ -75,7 +80,7 @@ extern void *vmalloc_32_user(unsigned long size);
78372 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
78373 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
78374 unsigned long start, unsigned long end, gfp_t gfp_mask,
78375- pgprot_t prot, int node, const void *caller);
78376+ pgprot_t prot, int node, const void *caller) __size_overflow(1);
78377 extern void vfree(const void *addr);
78378
78379 extern void *vmap(struct page **pages, unsigned int count,
78380@@ -142,7 +147,7 @@ extern void free_vm_area(struct vm_struct *area);
78381
78382 /* for /dev/kmem */
78383 extern long vread(char *buf, char *addr, unsigned long count);
78384-extern long vwrite(char *buf, char *addr, unsigned long count);
78385+extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
78386
78387 /*
78388 * Internals. Dont't use..
78389diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
78390index e4b9480..b96d5ab 100644
78391--- a/include/linux/vmstat.h
78392+++ b/include/linux/vmstat.h
78393@@ -90,18 +90,18 @@ static inline void vm_events_fold_cpu(int cpu)
78394 /*
78395 * Zone based page accounting with per cpu differentials.
78396 */
78397-extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
78398+extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
78399
78400 static inline void zone_page_state_add(long x, struct zone *zone,
78401 enum zone_stat_item item)
78402 {
78403- atomic_long_add(x, &zone->vm_stat[item]);
78404- atomic_long_add(x, &vm_stat[item]);
78405+ atomic_long_add_unchecked(x, &zone->vm_stat[item]);
78406+ atomic_long_add_unchecked(x, &vm_stat[item]);
78407 }
78408
78409 static inline unsigned long global_page_state(enum zone_stat_item item)
78410 {
78411- long x = atomic_long_read(&vm_stat[item]);
78412+ long x = atomic_long_read_unchecked(&vm_stat[item]);
78413 #ifdef CONFIG_SMP
78414 if (x < 0)
78415 x = 0;
78416@@ -112,7 +112,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
78417 static inline unsigned long zone_page_state(struct zone *zone,
78418 enum zone_stat_item item)
78419 {
78420- long x = atomic_long_read(&zone->vm_stat[item]);
78421+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
78422 #ifdef CONFIG_SMP
78423 if (x < 0)
78424 x = 0;
78425@@ -129,7 +129,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
78426 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
78427 enum zone_stat_item item)
78428 {
78429- long x = atomic_long_read(&zone->vm_stat[item]);
78430+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
78431
78432 #ifdef CONFIG_SMP
78433 int cpu;
78434@@ -220,8 +220,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
78435
78436 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
78437 {
78438- atomic_long_inc(&zone->vm_stat[item]);
78439- atomic_long_inc(&vm_stat[item]);
78440+ atomic_long_inc_unchecked(&zone->vm_stat[item]);
78441+ atomic_long_inc_unchecked(&vm_stat[item]);
78442 }
78443
78444 static inline void __inc_zone_page_state(struct page *page,
78445@@ -232,8 +232,8 @@ static inline void __inc_zone_page_state(struct page *page,
78446
78447 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
78448 {
78449- atomic_long_dec(&zone->vm_stat[item]);
78450- atomic_long_dec(&vm_stat[item]);
78451+ atomic_long_dec_unchecked(&zone->vm_stat[item]);
78452+ atomic_long_dec_unchecked(&vm_stat[item]);
78453 }
78454
78455 static inline void __dec_zone_page_state(struct page *page,
78456diff --git a/include/linux/xattr.h b/include/linux/xattr.h
78457index 91b0a68..0e9adf6 100644
78458--- a/include/linux/xattr.h
78459+++ b/include/linux/xattr.h
78460@@ -28,7 +28,7 @@ struct xattr_handler {
78461 size_t size, int handler_flags);
78462 int (*set)(struct dentry *dentry, const char *name, const void *buffer,
78463 size_t size, int flags, int handler_flags);
78464-};
78465+} __do_const;
78466
78467 struct xattr {
78468 const char *name;
78469@@ -37,6 +37,9 @@ struct xattr {
78470 };
78471
78472 ssize_t xattr_getsecurity(struct inode *, const char *, void *, size_t);
78473+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
78474+ssize_t pax_getxattr(struct dentry *, void *, size_t);
78475+#endif
78476 ssize_t vfs_getxattr(struct dentry *, const char *, void *, size_t);
78477 ssize_t vfs_listxattr(struct dentry *d, char *list, size_t size);
78478 int __vfs_setxattr_noperm(struct dentry *, const char *, const void *, size_t, int);
78479diff --git a/include/linux/zlib.h b/include/linux/zlib.h
78480index 9c5a6b4..09c9438 100644
78481--- a/include/linux/zlib.h
78482+++ b/include/linux/zlib.h
78483@@ -31,6 +31,7 @@
78484 #define _ZLIB_H
78485
78486 #include <linux/zconf.h>
78487+#include <linux/compiler.h>
78488
78489 /* zlib deflate based on ZLIB_VERSION "1.1.3" */
78490 /* zlib inflate based on ZLIB_VERSION "1.2.3" */
78491@@ -179,7 +180,7 @@ typedef z_stream *z_streamp;
78492
78493 /* basic functions */
78494
78495-extern int zlib_deflate_workspacesize (int windowBits, int memLevel);
78496+extern int zlib_deflate_workspacesize (int windowBits, int memLevel) __intentional_overflow(0);
78497 /*
78498 Returns the number of bytes that needs to be allocated for a per-
78499 stream workspace with the specified parameters. A pointer to this
78500diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
78501index c768c9f..bdcaa5a 100644
78502--- a/include/media/v4l2-dev.h
78503+++ b/include/media/v4l2-dev.h
78504@@ -76,7 +76,7 @@ struct v4l2_file_operations {
78505 int (*mmap) (struct file *, struct vm_area_struct *);
78506 int (*open) (struct file *);
78507 int (*release) (struct file *);
78508-};
78509+} __do_const;
78510
78511 /*
78512 * Newer version of video_device, handled by videodev2.c
78513diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h
78514index c9b1593..a572459 100644
78515--- a/include/media/v4l2-device.h
78516+++ b/include/media/v4l2-device.h
78517@@ -95,7 +95,7 @@ int __must_check v4l2_device_register(struct device *dev, struct v4l2_device *v4
78518 this function returns 0. If the name ends with a digit (e.g. cx18),
78519 then the name will be set to cx18-0 since cx180 looks really odd. */
78520 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
78521- atomic_t *instance);
78522+ atomic_unchecked_t *instance);
78523
78524 /* Set v4l2_dev->dev to NULL. Call when the USB parent disconnects.
78525 Since the parent disappears this ensures that v4l2_dev doesn't have an
78526diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
78527index 9a36d92..0aafe2a 100644
78528--- a/include/net/9p/transport.h
78529+++ b/include/net/9p/transport.h
78530@@ -60,7 +60,7 @@ struct p9_trans_module {
78531 int (*cancel) (struct p9_client *, struct p9_req_t *req);
78532 int (*zc_request)(struct p9_client *, struct p9_req_t *,
78533 char *, char *, int , int, int, int);
78534-};
78535+} __do_const;
78536
78537 void v9fs_register_trans(struct p9_trans_module *m);
78538 void v9fs_unregister_trans(struct p9_trans_module *m);
78539diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
78540index 1a966af..2767cf6 100644
78541--- a/include/net/bluetooth/l2cap.h
78542+++ b/include/net/bluetooth/l2cap.h
78543@@ -551,7 +551,7 @@ struct l2cap_ops {
78544 void (*defer) (struct l2cap_chan *chan);
78545 struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan,
78546 unsigned long len, int nb);
78547-};
78548+} __do_const;
78549
78550 struct l2cap_conn {
78551 struct hci_conn *hcon;
78552diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
78553index f2ae33d..c457cf0 100644
78554--- a/include/net/caif/cfctrl.h
78555+++ b/include/net/caif/cfctrl.h
78556@@ -52,7 +52,7 @@ struct cfctrl_rsp {
78557 void (*radioset_rsp)(void);
78558 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
78559 struct cflayer *client_layer);
78560-};
78561+} __no_const;
78562
78563 /* Link Setup Parameters for CAIF-Links. */
78564 struct cfctrl_link_param {
78565@@ -101,8 +101,8 @@ struct cfctrl_request_info {
78566 struct cfctrl {
78567 struct cfsrvl serv;
78568 struct cfctrl_rsp res;
78569- atomic_t req_seq_no;
78570- atomic_t rsp_seq_no;
78571+ atomic_unchecked_t req_seq_no;
78572+ atomic_unchecked_t rsp_seq_no;
78573 struct list_head list;
78574 /* Protects from simultaneous access to first_req list */
78575 spinlock_t info_list_lock;
78576diff --git a/include/net/flow.h b/include/net/flow.h
78577index 628e11b..4c475df 100644
78578--- a/include/net/flow.h
78579+++ b/include/net/flow.h
78580@@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
78581
78582 extern void flow_cache_flush(void);
78583 extern void flow_cache_flush_deferred(void);
78584-extern atomic_t flow_cache_genid;
78585+extern atomic_unchecked_t flow_cache_genid;
78586
78587 #endif
78588diff --git a/include/net/genetlink.h b/include/net/genetlink.h
78589index 8e0b6c8..73cf605 100644
78590--- a/include/net/genetlink.h
78591+++ b/include/net/genetlink.h
78592@@ -120,7 +120,7 @@ struct genl_ops {
78593 struct netlink_callback *cb);
78594 int (*done)(struct netlink_callback *cb);
78595 struct list_head ops_list;
78596-};
78597+} __do_const;
78598
78599 extern int __genl_register_family(struct genl_family *family);
78600
78601diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
78602index 734d9b5..48a9a4b 100644
78603--- a/include/net/gro_cells.h
78604+++ b/include/net/gro_cells.h
78605@@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
78606 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
78607
78608 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
78609- atomic_long_inc(&dev->rx_dropped);
78610+ atomic_long_inc_unchecked(&dev->rx_dropped);
78611 kfree_skb(skb);
78612 return;
78613 }
78614diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
78615index de2c785..0588a6b 100644
78616--- a/include/net/inet_connection_sock.h
78617+++ b/include/net/inet_connection_sock.h
78618@@ -62,7 +62,7 @@ struct inet_connection_sock_af_ops {
78619 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
78620 int (*bind_conflict)(const struct sock *sk,
78621 const struct inet_bind_bucket *tb, bool relax);
78622-};
78623+} __do_const;
78624
78625 /** inet_connection_sock - INET connection oriented sock
78626 *
78627diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
78628index 53f464d..0bd0b49 100644
78629--- a/include/net/inetpeer.h
78630+++ b/include/net/inetpeer.h
78631@@ -47,8 +47,8 @@ struct inet_peer {
78632 */
78633 union {
78634 struct {
78635- atomic_t rid; /* Frag reception counter */
78636- atomic_t ip_id_count; /* IP ID for the next packet */
78637+ atomic_unchecked_t rid; /* Frag reception counter */
78638+ atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
78639 };
78640 struct rcu_head rcu;
78641 struct inet_peer *gc_next;
78642@@ -178,16 +178,13 @@ static inline void inet_peer_refcheck(const struct inet_peer *p)
78643 /* can be called with or without local BH being disabled */
78644 static inline int inet_getid(struct inet_peer *p, int more)
78645 {
78646- int old, new;
78647+ int id;
78648 more++;
78649 inet_peer_refcheck(p);
78650- do {
78651- old = atomic_read(&p->ip_id_count);
78652- new = old + more;
78653- if (!new)
78654- new = 1;
78655- } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
78656- return new;
78657+ id = atomic_add_return_unchecked(more, &p->ip_id_count);
78658+ if (!id)
78659+ id = atomic_inc_return_unchecked(&p->ip_id_count);
78660+ return id;
78661 }
78662
78663 #endif /* _NET_INETPEER_H */
78664diff --git a/include/net/ip.h b/include/net/ip.h
78665index 5e52688..f181e95 100644
78666--- a/include/net/ip.h
78667+++ b/include/net/ip.h
78668@@ -212,7 +212,7 @@ extern struct local_ports {
78669 } sysctl_local_ports;
78670 extern void inet_get_local_port_range(int *low, int *high);
78671
78672-extern unsigned long *sysctl_local_reserved_ports;
78673+extern unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
78674 static inline int inet_is_reserved_local_port(int port)
78675 {
78676 return test_bit(port, sysctl_local_reserved_ports);
78677diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
78678index cbf2be3..3683f6d 100644
78679--- a/include/net/ip_fib.h
78680+++ b/include/net/ip_fib.h
78681@@ -169,7 +169,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
78682
78683 #define FIB_RES_SADDR(net, res) \
78684 ((FIB_RES_NH(res).nh_saddr_genid == \
78685- atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
78686+ atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
78687 FIB_RES_NH(res).nh_saddr : \
78688 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
78689 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
78690diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
78691index 9c4d37e..eed6d41 100644
78692--- a/include/net/ip_vs.h
78693+++ b/include/net/ip_vs.h
78694@@ -588,7 +588,7 @@ struct ip_vs_conn {
78695 struct ip_vs_conn *control; /* Master control connection */
78696 atomic_t n_control; /* Number of controlled ones */
78697 struct ip_vs_dest *dest; /* real server */
78698- atomic_t in_pkts; /* incoming packet counter */
78699+ atomic_unchecked_t in_pkts; /* incoming packet counter */
78700
78701 /* packet transmitter for different forwarding methods. If it
78702 mangles the packet, it must return NF_DROP or better NF_STOLEN,
78703@@ -735,7 +735,7 @@ struct ip_vs_dest {
78704 __be16 port; /* port number of the server */
78705 union nf_inet_addr addr; /* IP address of the server */
78706 volatile unsigned int flags; /* dest status flags */
78707- atomic_t conn_flags; /* flags to copy to conn */
78708+ atomic_unchecked_t conn_flags; /* flags to copy to conn */
78709 atomic_t weight; /* server weight */
78710
78711 atomic_t refcnt; /* reference counter */
78712@@ -990,11 +990,11 @@ struct netns_ipvs {
78713 /* ip_vs_lblc */
78714 int sysctl_lblc_expiration;
78715 struct ctl_table_header *lblc_ctl_header;
78716- struct ctl_table *lblc_ctl_table;
78717+ ctl_table_no_const *lblc_ctl_table;
78718 /* ip_vs_lblcr */
78719 int sysctl_lblcr_expiration;
78720 struct ctl_table_header *lblcr_ctl_header;
78721- struct ctl_table *lblcr_ctl_table;
78722+ ctl_table_no_const *lblcr_ctl_table;
78723 /* ip_vs_est */
78724 struct list_head est_list; /* estimator list */
78725 spinlock_t est_lock;
78726diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
78727index 80ffde3..968b0f4 100644
78728--- a/include/net/irda/ircomm_tty.h
78729+++ b/include/net/irda/ircomm_tty.h
78730@@ -35,6 +35,7 @@
78731 #include <linux/termios.h>
78732 #include <linux/timer.h>
78733 #include <linux/tty.h> /* struct tty_struct */
78734+#include <asm/local.h>
78735
78736 #include <net/irda/irias_object.h>
78737 #include <net/irda/ircomm_core.h>
78738diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
78739index 714cc9a..ea05f3e 100644
78740--- a/include/net/iucv/af_iucv.h
78741+++ b/include/net/iucv/af_iucv.h
78742@@ -149,7 +149,7 @@ struct iucv_skb_cb {
78743 struct iucv_sock_list {
78744 struct hlist_head head;
78745 rwlock_t lock;
78746- atomic_t autobind_name;
78747+ atomic_unchecked_t autobind_name;
78748 };
78749
78750 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
78751diff --git a/include/net/llc_c_ac.h b/include/net/llc_c_ac.h
78752index df83f69..9b640b8 100644
78753--- a/include/net/llc_c_ac.h
78754+++ b/include/net/llc_c_ac.h
78755@@ -87,7 +87,7 @@
78756 #define LLC_CONN_AC_STOP_SENDACK_TMR 70
78757 #define LLC_CONN_AC_START_SENDACK_TMR_IF_NOT_RUNNING 71
78758
78759-typedef int (*llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
78760+typedef int (* const llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
78761
78762 extern int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb);
78763 extern int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb);
78764diff --git a/include/net/llc_c_ev.h b/include/net/llc_c_ev.h
78765index 6ca3113..f8026dd 100644
78766--- a/include/net/llc_c_ev.h
78767+++ b/include/net/llc_c_ev.h
78768@@ -125,8 +125,8 @@ static __inline__ struct llc_conn_state_ev *llc_conn_ev(struct sk_buff *skb)
78769 return (struct llc_conn_state_ev *)skb->cb;
78770 }
78771
78772-typedef int (*llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
78773-typedef int (*llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
78774+typedef int (* const llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
78775+typedef int (* const llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
78776
78777 extern int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb);
78778 extern int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb);
78779diff --git a/include/net/llc_c_st.h b/include/net/llc_c_st.h
78780index 0e79cfb..f46db31 100644
78781--- a/include/net/llc_c_st.h
78782+++ b/include/net/llc_c_st.h
78783@@ -37,7 +37,7 @@ struct llc_conn_state_trans {
78784 u8 next_state;
78785 llc_conn_ev_qfyr_t *ev_qualifiers;
78786 llc_conn_action_t *ev_actions;
78787-};
78788+} __do_const;
78789
78790 struct llc_conn_state {
78791 u8 current_state;
78792diff --git a/include/net/llc_s_ac.h b/include/net/llc_s_ac.h
78793index 37a3bbd..55a4241 100644
78794--- a/include/net/llc_s_ac.h
78795+++ b/include/net/llc_s_ac.h
78796@@ -23,7 +23,7 @@
78797 #define SAP_ACT_TEST_IND 9
78798
78799 /* All action functions must look like this */
78800-typedef int (*llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
78801+typedef int (* const llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
78802
78803 extern int llc_sap_action_unitdata_ind(struct llc_sap *sap,
78804 struct sk_buff *skb);
78805diff --git a/include/net/llc_s_st.h b/include/net/llc_s_st.h
78806index 567c681..cd73ac0 100644
78807--- a/include/net/llc_s_st.h
78808+++ b/include/net/llc_s_st.h
78809@@ -20,7 +20,7 @@ struct llc_sap_state_trans {
78810 llc_sap_ev_t ev;
78811 u8 next_state;
78812 llc_sap_action_t *ev_actions;
78813-};
78814+} __do_const;
78815
78816 struct llc_sap_state {
78817 u8 curr_state;
78818diff --git a/include/net/mac80211.h b/include/net/mac80211.h
78819index cc6035f..a8406fc 100644
78820--- a/include/net/mac80211.h
78821+++ b/include/net/mac80211.h
78822@@ -4361,7 +4361,7 @@ struct rate_control_ops {
78823 void (*add_sta_debugfs)(void *priv, void *priv_sta,
78824 struct dentry *dir);
78825 void (*remove_sta_debugfs)(void *priv, void *priv_sta);
78826-};
78827+} __do_const;
78828
78829 static inline int rate_supported(struct ieee80211_sta *sta,
78830 enum ieee80211_band band,
78831diff --git a/include/net/neighbour.h b/include/net/neighbour.h
78832index 536501a..7c6193c 100644
78833--- a/include/net/neighbour.h
78834+++ b/include/net/neighbour.h
78835@@ -123,7 +123,7 @@ struct neigh_ops {
78836 void (*error_report)(struct neighbour *, struct sk_buff *);
78837 int (*output)(struct neighbour *, struct sk_buff *);
78838 int (*connected_output)(struct neighbour *, struct sk_buff *);
78839-};
78840+} __do_const;
78841
78842 struct pneigh_entry {
78843 struct pneigh_entry *next;
78844diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
78845index 9d22f08..980fbf8 100644
78846--- a/include/net/net_namespace.h
78847+++ b/include/net/net_namespace.h
78848@@ -120,7 +120,7 @@ struct net {
78849 struct netns_ipvs *ipvs;
78850 #endif
78851 struct sock *diag_nlsk;
78852- atomic_t fnhe_genid;
78853+ atomic_unchecked_t fnhe_genid;
78854 };
78855
78856 /*
78857@@ -277,7 +277,11 @@ static inline struct net *read_pnet(struct net * const *pnet)
78858 #define __net_init __init
78859 #define __net_exit __exit_refok
78860 #define __net_initdata __initdata
78861+#ifdef CONSTIFY_PLUGIN
78862 #define __net_initconst __initconst
78863+#else
78864+#define __net_initconst __initdata
78865+#endif
78866 #endif
78867
78868 struct pernet_operations {
78869@@ -287,7 +291,7 @@ struct pernet_operations {
78870 void (*exit_batch)(struct list_head *net_exit_list);
78871 int *id;
78872 size_t size;
78873-};
78874+} __do_const;
78875
78876 /*
78877 * Use these carefully. If you implement a network device and it
78878@@ -335,23 +339,23 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
78879
78880 static inline int rt_genid_ipv4(struct net *net)
78881 {
78882- return atomic_read(&net->ipv4.rt_genid);
78883+ return atomic_read_unchecked(&net->ipv4.rt_genid);
78884 }
78885
78886 static inline void rt_genid_bump_ipv4(struct net *net)
78887 {
78888- atomic_inc(&net->ipv4.rt_genid);
78889+ atomic_inc_unchecked(&net->ipv4.rt_genid);
78890 }
78891
78892 #if IS_ENABLED(CONFIG_IPV6)
78893 static inline int rt_genid_ipv6(struct net *net)
78894 {
78895- return atomic_read(&net->ipv6.rt_genid);
78896+ return atomic_read_unchecked(&net->ipv6.rt_genid);
78897 }
78898
78899 static inline void rt_genid_bump_ipv6(struct net *net)
78900 {
78901- atomic_inc(&net->ipv6.rt_genid);
78902+ atomic_inc_unchecked(&net->ipv6.rt_genid);
78903 }
78904 #else
78905 static inline int rt_genid_ipv6(struct net *net)
78906@@ -373,12 +377,12 @@ static inline void rt_genid_bump_all(struct net *net)
78907
78908 static inline int fnhe_genid(struct net *net)
78909 {
78910- return atomic_read(&net->fnhe_genid);
78911+ return atomic_read_unchecked(&net->fnhe_genid);
78912 }
78913
78914 static inline void fnhe_genid_bump(struct net *net)
78915 {
78916- atomic_inc(&net->fnhe_genid);
78917+ atomic_inc_unchecked(&net->fnhe_genid);
78918 }
78919
78920 #endif /* __NET_NET_NAMESPACE_H */
78921diff --git a/include/net/netdma.h b/include/net/netdma.h
78922index 8ba8ce2..99b7fff 100644
78923--- a/include/net/netdma.h
78924+++ b/include/net/netdma.h
78925@@ -24,7 +24,7 @@
78926 #include <linux/dmaengine.h>
78927 #include <linux/skbuff.h>
78928
78929-int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
78930+int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
78931 struct sk_buff *skb, int offset, struct iovec *to,
78932 size_t len, struct dma_pinned_list *pinned_list);
78933
78934diff --git a/include/net/netlink.h b/include/net/netlink.h
78935index 9690b0f..87aded7 100644
78936--- a/include/net/netlink.h
78937+++ b/include/net/netlink.h
78938@@ -534,7 +534,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
78939 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
78940 {
78941 if (mark)
78942- skb_trim(skb, (unsigned char *) mark - skb->data);
78943+ skb_trim(skb, (const unsigned char *) mark - skb->data);
78944 }
78945
78946 /**
78947diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
78948index c9c0c53..53f24c3 100644
78949--- a/include/net/netns/conntrack.h
78950+++ b/include/net/netns/conntrack.h
78951@@ -12,10 +12,10 @@ struct nf_conntrack_ecache;
78952 struct nf_proto_net {
78953 #ifdef CONFIG_SYSCTL
78954 struct ctl_table_header *ctl_table_header;
78955- struct ctl_table *ctl_table;
78956+ ctl_table_no_const *ctl_table;
78957 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
78958 struct ctl_table_header *ctl_compat_header;
78959- struct ctl_table *ctl_compat_table;
78960+ ctl_table_no_const *ctl_compat_table;
78961 #endif
78962 #endif
78963 unsigned int users;
78964@@ -58,7 +58,7 @@ struct nf_ip_net {
78965 struct nf_icmp_net icmpv6;
78966 #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
78967 struct ctl_table_header *ctl_table_header;
78968- struct ctl_table *ctl_table;
78969+ ctl_table_no_const *ctl_table;
78970 #endif
78971 };
78972
78973diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
78974index bf2ec22..5e7f9d9 100644
78975--- a/include/net/netns/ipv4.h
78976+++ b/include/net/netns/ipv4.h
78977@@ -67,7 +67,7 @@ struct netns_ipv4 {
78978 kgid_t sysctl_ping_group_range[2];
78979 long sysctl_tcp_mem[3];
78980
78981- atomic_t dev_addr_genid;
78982+ atomic_unchecked_t dev_addr_genid;
78983
78984 #ifdef CONFIG_IP_MROUTE
78985 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
78986@@ -77,6 +77,6 @@ struct netns_ipv4 {
78987 struct fib_rules_ops *mr_rules_ops;
78988 #endif
78989 #endif
78990- atomic_t rt_genid;
78991+ atomic_unchecked_t rt_genid;
78992 };
78993 #endif
78994diff --git a/include/net/netns/ipv6.h b/include/net/netns/ipv6.h
78995index 0fb2401..477d81c 100644
78996--- a/include/net/netns/ipv6.h
78997+++ b/include/net/netns/ipv6.h
78998@@ -71,8 +71,8 @@ struct netns_ipv6 {
78999 struct fib_rules_ops *mr6_rules_ops;
79000 #endif
79001 #endif
79002- atomic_t dev_addr_genid;
79003- atomic_t rt_genid;
79004+ atomic_unchecked_t dev_addr_genid;
79005+ atomic_unchecked_t rt_genid;
79006 };
79007
79008 #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
79009diff --git a/include/net/ping.h b/include/net/ping.h
79010index 5db0224..0d65365 100644
79011--- a/include/net/ping.h
79012+++ b/include/net/ping.h
79013@@ -55,7 +55,7 @@ struct ping_iter_state {
79014 extern struct proto ping_prot;
79015 extern struct ping_table ping_table;
79016 #if IS_ENABLED(CONFIG_IPV6)
79017-extern struct pingv6_ops pingv6_ops;
79018+extern struct pingv6_ops *pingv6_ops;
79019 #endif
79020
79021 struct pingfakehdr {
79022diff --git a/include/net/protocol.h b/include/net/protocol.h
79023index 047c047..b9dad15 100644
79024--- a/include/net/protocol.h
79025+++ b/include/net/protocol.h
79026@@ -44,7 +44,7 @@ struct net_protocol {
79027 void (*err_handler)(struct sk_buff *skb, u32 info);
79028 unsigned int no_policy:1,
79029 netns_ok:1;
79030-};
79031+} __do_const;
79032
79033 #if IS_ENABLED(CONFIG_IPV6)
79034 struct inet6_protocol {
79035@@ -57,7 +57,7 @@ struct inet6_protocol {
79036 u8 type, u8 code, int offset,
79037 __be32 info);
79038 unsigned int flags; /* INET6_PROTO_xxx */
79039-};
79040+} __do_const;
79041
79042 #define INET6_PROTO_NOPOLICY 0x1
79043 #define INET6_PROTO_FINAL 0x2
79044diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
79045index 7026648..584cc8c 100644
79046--- a/include/net/rtnetlink.h
79047+++ b/include/net/rtnetlink.h
79048@@ -81,7 +81,7 @@ struct rtnl_link_ops {
79049 const struct net_device *dev);
79050 unsigned int (*get_num_tx_queues)(void);
79051 unsigned int (*get_num_rx_queues)(void);
79052-};
79053+} __do_const;
79054
79055 extern int __rtnl_link_register(struct rtnl_link_ops *ops);
79056 extern void __rtnl_link_unregister(struct rtnl_link_ops *ops);
79057diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
79058index 4ef75af..5aa073a 100644
79059--- a/include/net/sctp/sm.h
79060+++ b/include/net/sctp/sm.h
79061@@ -81,7 +81,7 @@ typedef void (sctp_timer_event_t) (unsigned long);
79062 typedef struct {
79063 sctp_state_fn_t *fn;
79064 const char *name;
79065-} sctp_sm_table_entry_t;
79066+} __do_const sctp_sm_table_entry_t;
79067
79068 /* A naming convention of "sctp_sf_xxx" applies to all the state functions
79069 * currently in use.
79070@@ -293,7 +293,7 @@ __u32 sctp_generate_tag(const struct sctp_endpoint *);
79071 __u32 sctp_generate_tsn(const struct sctp_endpoint *);
79072
79073 /* Extern declarations for major data structures. */
79074-extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
79075+extern sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
79076
79077
79078 /* Get the size of a DATA chunk payload. */
79079diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
79080index 2174d8d..71d5257 100644
79081--- a/include/net/sctp/structs.h
79082+++ b/include/net/sctp/structs.h
79083@@ -508,7 +508,7 @@ struct sctp_pf {
79084 struct sctp_association *asoc);
79085 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
79086 struct sctp_af *af;
79087-};
79088+} __do_const;
79089
79090
79091 /* Structure to track chunk fragments that have been acked, but peer
79092diff --git a/include/net/sock.h b/include/net/sock.h
79093index 808cbc2..f6f6ac3 100644
79094--- a/include/net/sock.h
79095+++ b/include/net/sock.h
79096@@ -332,7 +332,7 @@ struct sock {
79097 unsigned int sk_napi_id;
79098 unsigned int sk_ll_usec;
79099 #endif
79100- atomic_t sk_drops;
79101+ atomic_unchecked_t sk_drops;
79102 int sk_rcvbuf;
79103
79104 struct sk_filter __rcu *sk_filter;
79105@@ -1821,7 +1821,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
79106 }
79107
79108 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
79109- char __user *from, char *to,
79110+ char __user *from, unsigned char *to,
79111 int copy, int offset)
79112 {
79113 if (skb->ip_summed == CHECKSUM_NONE) {
79114@@ -2083,7 +2083,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
79115 }
79116 }
79117
79118-struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
79119+struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
79120
79121 /**
79122 * sk_page_frag - return an appropriate page_frag
79123diff --git a/include/net/tcp.h b/include/net/tcp.h
79124index b1aa324..b8530ea 100644
79125--- a/include/net/tcp.h
79126+++ b/include/net/tcp.h
79127@@ -527,7 +527,7 @@ extern void tcp_retransmit_timer(struct sock *sk);
79128 extern void tcp_xmit_retransmit_queue(struct sock *);
79129 extern void tcp_simple_retransmit(struct sock *);
79130 extern int tcp_trim_head(struct sock *, struct sk_buff *, u32);
79131-extern int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
79132+extern int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
79133
79134 extern void tcp_send_probe0(struct sock *);
79135 extern void tcp_send_partial(struct sock *);
79136@@ -699,8 +699,8 @@ struct tcp_skb_cb {
79137 struct inet6_skb_parm h6;
79138 #endif
79139 } header; /* For incoming frames */
79140- __u32 seq; /* Starting sequence number */
79141- __u32 end_seq; /* SEQ + FIN + SYN + datalen */
79142+ __u32 seq __intentional_overflow(0); /* Starting sequence number */
79143+ __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
79144 __u32 when; /* used to compute rtt's */
79145 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
79146
79147@@ -714,7 +714,7 @@ struct tcp_skb_cb {
79148
79149 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
79150 /* 1 byte hole */
79151- __u32 ack_seq; /* Sequence number ACK'd */
79152+ __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
79153 };
79154
79155 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
79156diff --git a/include/net/xfrm.h b/include/net/xfrm.h
79157index e253bf0..2278b4b 100644
79158--- a/include/net/xfrm.h
79159+++ b/include/net/xfrm.h
79160@@ -287,7 +287,6 @@ struct xfrm_dst;
79161 struct xfrm_policy_afinfo {
79162 unsigned short family;
79163 struct dst_ops *dst_ops;
79164- void (*garbage_collect)(struct net *net);
79165 struct dst_entry *(*dst_lookup)(struct net *net, int tos,
79166 const xfrm_address_t *saddr,
79167 const xfrm_address_t *daddr);
79168@@ -305,7 +304,7 @@ struct xfrm_policy_afinfo {
79169 struct net_device *dev,
79170 const struct flowi *fl);
79171 struct dst_entry *(*blackhole_route)(struct net *net, struct dst_entry *orig);
79172-};
79173+} __do_const;
79174
79175 extern int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
79176 extern int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
79177@@ -342,7 +341,7 @@ struct xfrm_state_afinfo {
79178 int (*transport_finish)(struct sk_buff *skb,
79179 int async);
79180 void (*local_error)(struct sk_buff *skb, u32 mtu);
79181-};
79182+} __do_const;
79183
79184 extern int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
79185 extern int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
79186@@ -427,7 +426,7 @@ struct xfrm_mode {
79187 struct module *owner;
79188 unsigned int encap;
79189 int flags;
79190-};
79191+} __do_const;
79192
79193 /* Flags for xfrm_mode. */
79194 enum {
79195@@ -524,7 +523,7 @@ struct xfrm_policy {
79196 struct timer_list timer;
79197
79198 struct flow_cache_object flo;
79199- atomic_t genid;
79200+ atomic_unchecked_t genid;
79201 u32 priority;
79202 u32 index;
79203 struct xfrm_mark mark;
79204@@ -1164,6 +1163,7 @@ static inline void xfrm_sk_free_policy(struct sock *sk)
79205 }
79206
79207 extern void xfrm_garbage_collect(struct net *net);
79208+extern void xfrm_garbage_collect_deferred(struct net *net);
79209
79210 #else
79211
79212@@ -1202,6 +1202,9 @@ static inline int xfrm6_policy_check_reverse(struct sock *sk, int dir,
79213 static inline void xfrm_garbage_collect(struct net *net)
79214 {
79215 }
79216+static inline void xfrm_garbage_collect_deferred(struct net *net)
79217+{
79218+}
79219 #endif
79220
79221 static __inline__
79222diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
79223index 1017e0b..227aa4d 100644
79224--- a/include/rdma/iw_cm.h
79225+++ b/include/rdma/iw_cm.h
79226@@ -122,7 +122,7 @@ struct iw_cm_verbs {
79227 int backlog);
79228
79229 int (*destroy_listen)(struct iw_cm_id *cm_id);
79230-};
79231+} __no_const;
79232
79233 /**
79234 * iw_create_cm_id - Create an IW CM identifier.
79235diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
79236index e1379b4..67eafbe 100644
79237--- a/include/scsi/libfc.h
79238+++ b/include/scsi/libfc.h
79239@@ -762,6 +762,7 @@ struct libfc_function_template {
79240 */
79241 void (*disc_stop_final) (struct fc_lport *);
79242 };
79243+typedef struct libfc_function_template __no_const libfc_function_template_no_const;
79244
79245 /**
79246 * struct fc_disc - Discovery context
79247@@ -866,7 +867,7 @@ struct fc_lport {
79248 struct fc_vport *vport;
79249
79250 /* Operational Information */
79251- struct libfc_function_template tt;
79252+ libfc_function_template_no_const tt;
79253 u8 link_up;
79254 u8 qfull;
79255 enum fc_lport_state state;
79256diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
79257index d65fbec..f80fef2 100644
79258--- a/include/scsi/scsi_device.h
79259+++ b/include/scsi/scsi_device.h
79260@@ -180,9 +180,9 @@ struct scsi_device {
79261 unsigned int max_device_blocked; /* what device_blocked counts down from */
79262 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
79263
79264- atomic_t iorequest_cnt;
79265- atomic_t iodone_cnt;
79266- atomic_t ioerr_cnt;
79267+ atomic_unchecked_t iorequest_cnt;
79268+ atomic_unchecked_t iodone_cnt;
79269+ atomic_unchecked_t ioerr_cnt;
79270
79271 struct device sdev_gendev,
79272 sdev_dev;
79273diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
79274index b797e8f..8e2c3aa 100644
79275--- a/include/scsi/scsi_transport_fc.h
79276+++ b/include/scsi/scsi_transport_fc.h
79277@@ -751,7 +751,8 @@ struct fc_function_template {
79278 unsigned long show_host_system_hostname:1;
79279
79280 unsigned long disable_target_scan:1;
79281-};
79282+} __do_const;
79283+typedef struct fc_function_template __no_const fc_function_template_no_const;
79284
79285
79286 /**
79287diff --git a/include/sound/compress_driver.h b/include/sound/compress_driver.h
79288index 9031a26..750d592 100644
79289--- a/include/sound/compress_driver.h
79290+++ b/include/sound/compress_driver.h
79291@@ -128,7 +128,7 @@ struct snd_compr_ops {
79292 struct snd_compr_caps *caps);
79293 int (*get_codec_caps) (struct snd_compr_stream *stream,
79294 struct snd_compr_codec_caps *codec);
79295-};
79296+} __no_const;
79297
79298 /**
79299 * struct snd_compr: Compressed device
79300diff --git a/include/sound/soc.h b/include/sound/soc.h
79301index d22cb0a..c6ba150 100644
79302--- a/include/sound/soc.h
79303+++ b/include/sound/soc.h
79304@@ -780,7 +780,7 @@ struct snd_soc_codec_driver {
79305 /* probe ordering - for components with runtime dependencies */
79306 int probe_order;
79307 int remove_order;
79308-};
79309+} __do_const;
79310
79311 /* SoC platform interface */
79312 struct snd_soc_platform_driver {
79313@@ -826,7 +826,7 @@ struct snd_soc_platform_driver {
79314 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
79315 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
79316 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
79317-};
79318+} __do_const;
79319
79320 struct snd_soc_platform {
79321 const char *name;
79322diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
79323index 5bdb8b7..bb1096c 100644
79324--- a/include/target/target_core_base.h
79325+++ b/include/target/target_core_base.h
79326@@ -663,7 +663,7 @@ struct se_device {
79327 spinlock_t stats_lock;
79328 /* Active commands on this virtual SE device */
79329 atomic_t simple_cmds;
79330- atomic_t dev_ordered_id;
79331+ atomic_unchecked_t dev_ordered_id;
79332 atomic_t dev_ordered_sync;
79333 atomic_t dev_qf_count;
79334 int export_count;
79335diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
79336new file mode 100644
79337index 0000000..fb634b7
79338--- /dev/null
79339+++ b/include/trace/events/fs.h
79340@@ -0,0 +1,53 @@
79341+#undef TRACE_SYSTEM
79342+#define TRACE_SYSTEM fs
79343+
79344+#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
79345+#define _TRACE_FS_H
79346+
79347+#include <linux/fs.h>
79348+#include <linux/tracepoint.h>
79349+
79350+TRACE_EVENT(do_sys_open,
79351+
79352+ TP_PROTO(const char *filename, int flags, int mode),
79353+
79354+ TP_ARGS(filename, flags, mode),
79355+
79356+ TP_STRUCT__entry(
79357+ __string( filename, filename )
79358+ __field( int, flags )
79359+ __field( int, mode )
79360+ ),
79361+
79362+ TP_fast_assign(
79363+ __assign_str(filename, filename);
79364+ __entry->flags = flags;
79365+ __entry->mode = mode;
79366+ ),
79367+
79368+ TP_printk("\"%s\" %x %o",
79369+ __get_str(filename), __entry->flags, __entry->mode)
79370+);
79371+
79372+TRACE_EVENT(open_exec,
79373+
79374+ TP_PROTO(const char *filename),
79375+
79376+ TP_ARGS(filename),
79377+
79378+ TP_STRUCT__entry(
79379+ __string( filename, filename )
79380+ ),
79381+
79382+ TP_fast_assign(
79383+ __assign_str(filename, filename);
79384+ ),
79385+
79386+ TP_printk("\"%s\"",
79387+ __get_str(filename))
79388+);
79389+
79390+#endif /* _TRACE_FS_H */
79391+
79392+/* This part must be outside protection */
79393+#include <trace/define_trace.h>
79394diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
79395index 1c09820..7f5ec79 100644
79396--- a/include/trace/events/irq.h
79397+++ b/include/trace/events/irq.h
79398@@ -36,7 +36,7 @@ struct softirq_action;
79399 */
79400 TRACE_EVENT(irq_handler_entry,
79401
79402- TP_PROTO(int irq, struct irqaction *action),
79403+ TP_PROTO(int irq, const struct irqaction *action),
79404
79405 TP_ARGS(irq, action),
79406
79407@@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
79408 */
79409 TRACE_EVENT(irq_handler_exit,
79410
79411- TP_PROTO(int irq, struct irqaction *action, int ret),
79412+ TP_PROTO(int irq, const struct irqaction *action, int ret),
79413
79414 TP_ARGS(irq, action, ret),
79415
79416diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
79417index 7caf44c..23c6f27 100644
79418--- a/include/uapi/linux/a.out.h
79419+++ b/include/uapi/linux/a.out.h
79420@@ -39,6 +39,14 @@ enum machine_type {
79421 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
79422 };
79423
79424+/* Constants for the N_FLAGS field */
79425+#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
79426+#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
79427+#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
79428+#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
79429+/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
79430+#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
79431+
79432 #if !defined (N_MAGIC)
79433 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
79434 #endif
79435diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
79436index d876736..ccce5c0 100644
79437--- a/include/uapi/linux/byteorder/little_endian.h
79438+++ b/include/uapi/linux/byteorder/little_endian.h
79439@@ -42,51 +42,51 @@
79440
79441 static inline __le64 __cpu_to_le64p(const __u64 *p)
79442 {
79443- return (__force __le64)*p;
79444+ return (__force const __le64)*p;
79445 }
79446-static inline __u64 __le64_to_cpup(const __le64 *p)
79447+static inline __u64 __intentional_overflow(-1) __le64_to_cpup(const __le64 *p)
79448 {
79449- return (__force __u64)*p;
79450+ return (__force const __u64)*p;
79451 }
79452 static inline __le32 __cpu_to_le32p(const __u32 *p)
79453 {
79454- return (__force __le32)*p;
79455+ return (__force const __le32)*p;
79456 }
79457 static inline __u32 __le32_to_cpup(const __le32 *p)
79458 {
79459- return (__force __u32)*p;
79460+ return (__force const __u32)*p;
79461 }
79462 static inline __le16 __cpu_to_le16p(const __u16 *p)
79463 {
79464- return (__force __le16)*p;
79465+ return (__force const __le16)*p;
79466 }
79467 static inline __u16 __le16_to_cpup(const __le16 *p)
79468 {
79469- return (__force __u16)*p;
79470+ return (__force const __u16)*p;
79471 }
79472 static inline __be64 __cpu_to_be64p(const __u64 *p)
79473 {
79474- return (__force __be64)__swab64p(p);
79475+ return (__force const __be64)__swab64p(p);
79476 }
79477 static inline __u64 __be64_to_cpup(const __be64 *p)
79478 {
79479- return __swab64p((__u64 *)p);
79480+ return __swab64p((const __u64 *)p);
79481 }
79482 static inline __be32 __cpu_to_be32p(const __u32 *p)
79483 {
79484- return (__force __be32)__swab32p(p);
79485+ return (__force const __be32)__swab32p(p);
79486 }
79487-static inline __u32 __be32_to_cpup(const __be32 *p)
79488+static inline __u32 __intentional_overflow(-1) __be32_to_cpup(const __be32 *p)
79489 {
79490- return __swab32p((__u32 *)p);
79491+ return __swab32p((const __u32 *)p);
79492 }
79493 static inline __be16 __cpu_to_be16p(const __u16 *p)
79494 {
79495- return (__force __be16)__swab16p(p);
79496+ return (__force const __be16)__swab16p(p);
79497 }
79498 static inline __u16 __be16_to_cpup(const __be16 *p)
79499 {
79500- return __swab16p((__u16 *)p);
79501+ return __swab16p((const __u16 *)p);
79502 }
79503 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
79504 #define __le64_to_cpus(x) do { (void)(x); } while (0)
79505diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
79506index ef6103b..d4e65dd 100644
79507--- a/include/uapi/linux/elf.h
79508+++ b/include/uapi/linux/elf.h
79509@@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
79510 #define PT_GNU_EH_FRAME 0x6474e550
79511
79512 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
79513+#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
79514+
79515+#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
79516+
79517+/* Constants for the e_flags field */
79518+#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
79519+#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
79520+#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
79521+#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
79522+/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
79523+#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
79524
79525 /*
79526 * Extended Numbering
79527@@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
79528 #define DT_DEBUG 21
79529 #define DT_TEXTREL 22
79530 #define DT_JMPREL 23
79531+#define DT_FLAGS 30
79532+ #define DF_TEXTREL 0x00000004
79533 #define DT_ENCODING 32
79534 #define OLD_DT_LOOS 0x60000000
79535 #define DT_LOOS 0x6000000d
79536@@ -240,6 +253,19 @@ typedef struct elf64_hdr {
79537 #define PF_W 0x2
79538 #define PF_X 0x1
79539
79540+#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
79541+#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
79542+#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
79543+#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
79544+#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
79545+#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
79546+/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
79547+/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
79548+#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
79549+#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
79550+#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
79551+#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
79552+
79553 typedef struct elf32_phdr{
79554 Elf32_Word p_type;
79555 Elf32_Off p_offset;
79556@@ -332,6 +358,8 @@ typedef struct elf64_shdr {
79557 #define EI_OSABI 7
79558 #define EI_PAD 8
79559
79560+#define EI_PAX 14
79561+
79562 #define ELFMAG0 0x7f /* EI_MAG */
79563 #define ELFMAG1 'E'
79564 #define ELFMAG2 'L'
79565diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
79566index aa169c4..6a2771d 100644
79567--- a/include/uapi/linux/personality.h
79568+++ b/include/uapi/linux/personality.h
79569@@ -30,6 +30,7 @@ enum {
79570 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
79571 ADDR_NO_RANDOMIZE | \
79572 ADDR_COMPAT_LAYOUT | \
79573+ ADDR_LIMIT_3GB | \
79574 MMAP_PAGE_ZERO)
79575
79576 /*
79577diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
79578index 7530e74..e714828 100644
79579--- a/include/uapi/linux/screen_info.h
79580+++ b/include/uapi/linux/screen_info.h
79581@@ -43,7 +43,8 @@ struct screen_info {
79582 __u16 pages; /* 0x32 */
79583 __u16 vesa_attributes; /* 0x34 */
79584 __u32 capabilities; /* 0x36 */
79585- __u8 _reserved[6]; /* 0x3a */
79586+ __u16 vesapm_size; /* 0x3a */
79587+ __u8 _reserved[4]; /* 0x3c */
79588 } __attribute__((packed));
79589
79590 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
79591diff --git a/include/uapi/linux/swab.h b/include/uapi/linux/swab.h
79592index 0e011eb..82681b1 100644
79593--- a/include/uapi/linux/swab.h
79594+++ b/include/uapi/linux/swab.h
79595@@ -43,7 +43,7 @@
79596 * ___swab16, ___swab32, ___swab64, ___swahw32, ___swahb32
79597 */
79598
79599-static inline __attribute_const__ __u16 __fswab16(__u16 val)
79600+static inline __intentional_overflow(-1) __attribute_const__ __u16 __fswab16(__u16 val)
79601 {
79602 #ifdef __HAVE_BUILTIN_BSWAP16__
79603 return __builtin_bswap16(val);
79604@@ -54,7 +54,7 @@ static inline __attribute_const__ __u16 __fswab16(__u16 val)
79605 #endif
79606 }
79607
79608-static inline __attribute_const__ __u32 __fswab32(__u32 val)
79609+static inline __intentional_overflow(-1) __attribute_const__ __u32 __fswab32(__u32 val)
79610 {
79611 #ifdef __HAVE_BUILTIN_BSWAP32__
79612 return __builtin_bswap32(val);
79613@@ -65,7 +65,7 @@ static inline __attribute_const__ __u32 __fswab32(__u32 val)
79614 #endif
79615 }
79616
79617-static inline __attribute_const__ __u64 __fswab64(__u64 val)
79618+static inline __intentional_overflow(-1) __attribute_const__ __u64 __fswab64(__u64 val)
79619 {
79620 #ifdef __HAVE_BUILTIN_BSWAP64__
79621 return __builtin_bswap64(val);
79622diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
79623index 6d67213..8dab561 100644
79624--- a/include/uapi/linux/sysctl.h
79625+++ b/include/uapi/linux/sysctl.h
79626@@ -155,7 +155,11 @@ enum
79627 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
79628 };
79629
79630-
79631+#ifdef CONFIG_PAX_SOFTMODE
79632+enum {
79633+ PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
79634+};
79635+#endif
79636
79637 /* CTL_VM names: */
79638 enum
79639diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
79640index e4629b9..6958086 100644
79641--- a/include/uapi/linux/xattr.h
79642+++ b/include/uapi/linux/xattr.h
79643@@ -63,5 +63,9 @@
79644 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
79645 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
79646
79647+/* User namespace */
79648+#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
79649+#define XATTR_PAX_FLAGS_SUFFIX "flags"
79650+#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
79651
79652 #endif /* _UAPI_LINUX_XATTR_H */
79653diff --git a/include/video/udlfb.h b/include/video/udlfb.h
79654index f9466fa..f4e2b81 100644
79655--- a/include/video/udlfb.h
79656+++ b/include/video/udlfb.h
79657@@ -53,10 +53,10 @@ struct dlfb_data {
79658 u32 pseudo_palette[256];
79659 int blank_mode; /*one of FB_BLANK_ */
79660 /* blit-only rendering path metrics, exposed through sysfs */
79661- atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
79662- atomic_t bytes_identical; /* saved effort with backbuffer comparison */
79663- atomic_t bytes_sent; /* to usb, after compression including overhead */
79664- atomic_t cpu_kcycles_used; /* transpired during pixel processing */
79665+ atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
79666+ atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
79667+ atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
79668+ atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
79669 };
79670
79671 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
79672diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
79673index 30f5362..8ed8ac9 100644
79674--- a/include/video/uvesafb.h
79675+++ b/include/video/uvesafb.h
79676@@ -122,6 +122,7 @@ struct uvesafb_par {
79677 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
79678 u8 pmi_setpal; /* PMI for palette changes */
79679 u16 *pmi_base; /* protected mode interface location */
79680+ u8 *pmi_code; /* protected mode code location */
79681 void *pmi_start;
79682 void *pmi_pal;
79683 u8 *vbe_state_orig; /*
79684diff --git a/init/Kconfig b/init/Kconfig
79685index 3ecd8a1..627843f 100644
79686--- a/init/Kconfig
79687+++ b/init/Kconfig
79688@@ -1086,6 +1086,7 @@ endif # CGROUPS
79689
79690 config CHECKPOINT_RESTORE
79691 bool "Checkpoint/restore support" if EXPERT
79692+ depends on !GRKERNSEC
79693 default n
79694 help
79695 Enables additional kernel features in a sake of checkpoint/restore.
79696@@ -1557,7 +1558,7 @@ config SLUB_DEBUG
79697
79698 config COMPAT_BRK
79699 bool "Disable heap randomization"
79700- default y
79701+ default n
79702 help
79703 Randomizing heap placement makes heap exploits harder, but it
79704 also breaks ancient binaries (including anything libc5 based).
79705@@ -1832,7 +1833,7 @@ config INIT_ALL_POSSIBLE
79706 config STOP_MACHINE
79707 bool
79708 default y
79709- depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
79710+ depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
79711 help
79712 Need stop_machine() primitive.
79713
79714diff --git a/init/Makefile b/init/Makefile
79715index 7bc47ee..6da2dc7 100644
79716--- a/init/Makefile
79717+++ b/init/Makefile
79718@@ -2,6 +2,9 @@
79719 # Makefile for the linux kernel.
79720 #
79721
79722+ccflags-y := $(GCC_PLUGINS_CFLAGS)
79723+asflags-y := $(GCC_PLUGINS_AFLAGS)
79724+
79725 obj-y := main.o version.o mounts.o
79726 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
79727 obj-y += noinitramfs.o
79728diff --git a/init/do_mounts.c b/init/do_mounts.c
79729index a51cddc..25c2768 100644
79730--- a/init/do_mounts.c
79731+++ b/init/do_mounts.c
79732@@ -357,11 +357,11 @@ static void __init get_fs_names(char *page)
79733 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
79734 {
79735 struct super_block *s;
79736- int err = sys_mount(name, "/root", fs, flags, data);
79737+ int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
79738 if (err)
79739 return err;
79740
79741- sys_chdir("/root");
79742+ sys_chdir((const char __force_user *)"/root");
79743 s = current->fs->pwd.dentry->d_sb;
79744 ROOT_DEV = s->s_dev;
79745 printk(KERN_INFO
79746@@ -482,18 +482,18 @@ void __init change_floppy(char *fmt, ...)
79747 va_start(args, fmt);
79748 vsprintf(buf, fmt, args);
79749 va_end(args);
79750- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
79751+ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
79752 if (fd >= 0) {
79753 sys_ioctl(fd, FDEJECT, 0);
79754 sys_close(fd);
79755 }
79756 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
79757- fd = sys_open("/dev/console", O_RDWR, 0);
79758+ fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
79759 if (fd >= 0) {
79760 sys_ioctl(fd, TCGETS, (long)&termios);
79761 termios.c_lflag &= ~ICANON;
79762 sys_ioctl(fd, TCSETSF, (long)&termios);
79763- sys_read(fd, &c, 1);
79764+ sys_read(fd, (char __user *)&c, 1);
79765 termios.c_lflag |= ICANON;
79766 sys_ioctl(fd, TCSETSF, (long)&termios);
79767 sys_close(fd);
79768@@ -587,8 +587,8 @@ void __init prepare_namespace(void)
79769 mount_root();
79770 out:
79771 devtmpfs_mount("dev");
79772- sys_mount(".", "/", NULL, MS_MOVE, NULL);
79773- sys_chroot(".");
79774+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
79775+ sys_chroot((const char __force_user *)".");
79776 }
79777
79778 static bool is_tmpfs;
79779diff --git a/init/do_mounts.h b/init/do_mounts.h
79780index f5b978a..69dbfe8 100644
79781--- a/init/do_mounts.h
79782+++ b/init/do_mounts.h
79783@@ -15,15 +15,15 @@ extern int root_mountflags;
79784
79785 static inline int create_dev(char *name, dev_t dev)
79786 {
79787- sys_unlink(name);
79788- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
79789+ sys_unlink((char __force_user *)name);
79790+ return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
79791 }
79792
79793 #if BITS_PER_LONG == 32
79794 static inline u32 bstat(char *name)
79795 {
79796 struct stat64 stat;
79797- if (sys_stat64(name, &stat) != 0)
79798+ if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
79799 return 0;
79800 if (!S_ISBLK(stat.st_mode))
79801 return 0;
79802@@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
79803 static inline u32 bstat(char *name)
79804 {
79805 struct stat stat;
79806- if (sys_newstat(name, &stat) != 0)
79807+ if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
79808 return 0;
79809 if (!S_ISBLK(stat.st_mode))
79810 return 0;
79811diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
79812index 3e0878e..8a9d7a0 100644
79813--- a/init/do_mounts_initrd.c
79814+++ b/init/do_mounts_initrd.c
79815@@ -37,13 +37,13 @@ static int init_linuxrc(struct subprocess_info *info, struct cred *new)
79816 {
79817 sys_unshare(CLONE_FS | CLONE_FILES);
79818 /* stdin/stdout/stderr for /linuxrc */
79819- sys_open("/dev/console", O_RDWR, 0);
79820+ sys_open((const char __force_user *)"/dev/console", O_RDWR, 0);
79821 sys_dup(0);
79822 sys_dup(0);
79823 /* move initrd over / and chdir/chroot in initrd root */
79824- sys_chdir("/root");
79825- sys_mount(".", "/", NULL, MS_MOVE, NULL);
79826- sys_chroot(".");
79827+ sys_chdir((const char __force_user *)"/root");
79828+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
79829+ sys_chroot((const char __force_user *)".");
79830 sys_setsid();
79831 return 0;
79832 }
79833@@ -59,8 +59,8 @@ static void __init handle_initrd(void)
79834 create_dev("/dev/root.old", Root_RAM0);
79835 /* mount initrd on rootfs' /root */
79836 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
79837- sys_mkdir("/old", 0700);
79838- sys_chdir("/old");
79839+ sys_mkdir((const char __force_user *)"/old", 0700);
79840+ sys_chdir((const char __force_user *)"/old");
79841
79842 /* try loading default modules from initrd */
79843 load_default_modules();
79844@@ -80,31 +80,31 @@ static void __init handle_initrd(void)
79845 current->flags &= ~PF_FREEZER_SKIP;
79846
79847 /* move initrd to rootfs' /old */
79848- sys_mount("..", ".", NULL, MS_MOVE, NULL);
79849+ sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
79850 /* switch root and cwd back to / of rootfs */
79851- sys_chroot("..");
79852+ sys_chroot((const char __force_user *)"..");
79853
79854 if (new_decode_dev(real_root_dev) == Root_RAM0) {
79855- sys_chdir("/old");
79856+ sys_chdir((const char __force_user *)"/old");
79857 return;
79858 }
79859
79860- sys_chdir("/");
79861+ sys_chdir((const char __force_user *)"/");
79862 ROOT_DEV = new_decode_dev(real_root_dev);
79863 mount_root();
79864
79865 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
79866- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
79867+ error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
79868 if (!error)
79869 printk("okay\n");
79870 else {
79871- int fd = sys_open("/dev/root.old", O_RDWR, 0);
79872+ int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
79873 if (error == -ENOENT)
79874 printk("/initrd does not exist. Ignored.\n");
79875 else
79876 printk("failed\n");
79877 printk(KERN_NOTICE "Unmounting old root\n");
79878- sys_umount("/old", MNT_DETACH);
79879+ sys_umount((char __force_user *)"/old", MNT_DETACH);
79880 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
79881 if (fd < 0) {
79882 error = fd;
79883@@ -127,11 +127,11 @@ int __init initrd_load(void)
79884 * mounted in the normal path.
79885 */
79886 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
79887- sys_unlink("/initrd.image");
79888+ sys_unlink((const char __force_user *)"/initrd.image");
79889 handle_initrd();
79890 return 1;
79891 }
79892 }
79893- sys_unlink("/initrd.image");
79894+ sys_unlink((const char __force_user *)"/initrd.image");
79895 return 0;
79896 }
79897diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
79898index 8cb6db5..d729f50 100644
79899--- a/init/do_mounts_md.c
79900+++ b/init/do_mounts_md.c
79901@@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
79902 partitioned ? "_d" : "", minor,
79903 md_setup_args[ent].device_names);
79904
79905- fd = sys_open(name, 0, 0);
79906+ fd = sys_open((char __force_user *)name, 0, 0);
79907 if (fd < 0) {
79908 printk(KERN_ERR "md: open failed - cannot start "
79909 "array %s\n", name);
79910@@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
79911 * array without it
79912 */
79913 sys_close(fd);
79914- fd = sys_open(name, 0, 0);
79915+ fd = sys_open((char __force_user *)name, 0, 0);
79916 sys_ioctl(fd, BLKRRPART, 0);
79917 }
79918 sys_close(fd);
79919@@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
79920
79921 wait_for_device_probe();
79922
79923- fd = sys_open("/dev/md0", 0, 0);
79924+ fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
79925 if (fd >= 0) {
79926 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
79927 sys_close(fd);
79928diff --git a/init/init_task.c b/init/init_task.c
79929index ba0a7f36..2bcf1d5 100644
79930--- a/init/init_task.c
79931+++ b/init/init_task.c
79932@@ -22,5 +22,9 @@ EXPORT_SYMBOL(init_task);
79933 * Initial thread structure. Alignment of this is handled by a special
79934 * linker map entry.
79935 */
79936+#ifdef CONFIG_X86
79937+union thread_union init_thread_union __init_task_data;
79938+#else
79939 union thread_union init_thread_union __init_task_data =
79940 { INIT_THREAD_INFO(init_task) };
79941+#endif
79942diff --git a/init/initramfs.c b/init/initramfs.c
79943index a67ef9d..2d17ed9 100644
79944--- a/init/initramfs.c
79945+++ b/init/initramfs.c
79946@@ -84,7 +84,7 @@ static void __init free_hash(void)
79947 }
79948 }
79949
79950-static long __init do_utime(char *filename, time_t mtime)
79951+static long __init do_utime(char __force_user *filename, time_t mtime)
79952 {
79953 struct timespec t[2];
79954
79955@@ -119,7 +119,7 @@ static void __init dir_utime(void)
79956 struct dir_entry *de, *tmp;
79957 list_for_each_entry_safe(de, tmp, &dir_list, list) {
79958 list_del(&de->list);
79959- do_utime(de->name, de->mtime);
79960+ do_utime((char __force_user *)de->name, de->mtime);
79961 kfree(de->name);
79962 kfree(de);
79963 }
79964@@ -281,7 +281,7 @@ static int __init maybe_link(void)
79965 if (nlink >= 2) {
79966 char *old = find_link(major, minor, ino, mode, collected);
79967 if (old)
79968- return (sys_link(old, collected) < 0) ? -1 : 1;
79969+ return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
79970 }
79971 return 0;
79972 }
79973@@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
79974 {
79975 struct stat st;
79976
79977- if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
79978+ if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
79979 if (S_ISDIR(st.st_mode))
79980- sys_rmdir(path);
79981+ sys_rmdir((char __force_user *)path);
79982 else
79983- sys_unlink(path);
79984+ sys_unlink((char __force_user *)path);
79985 }
79986 }
79987
79988@@ -315,7 +315,7 @@ static int __init do_name(void)
79989 int openflags = O_WRONLY|O_CREAT;
79990 if (ml != 1)
79991 openflags |= O_TRUNC;
79992- wfd = sys_open(collected, openflags, mode);
79993+ wfd = sys_open((char __force_user *)collected, openflags, mode);
79994
79995 if (wfd >= 0) {
79996 sys_fchown(wfd, uid, gid);
79997@@ -327,17 +327,17 @@ static int __init do_name(void)
79998 }
79999 }
80000 } else if (S_ISDIR(mode)) {
80001- sys_mkdir(collected, mode);
80002- sys_chown(collected, uid, gid);
80003- sys_chmod(collected, mode);
80004+ sys_mkdir((char __force_user *)collected, mode);
80005+ sys_chown((char __force_user *)collected, uid, gid);
80006+ sys_chmod((char __force_user *)collected, mode);
80007 dir_add(collected, mtime);
80008 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
80009 S_ISFIFO(mode) || S_ISSOCK(mode)) {
80010 if (maybe_link() == 0) {
80011- sys_mknod(collected, mode, rdev);
80012- sys_chown(collected, uid, gid);
80013- sys_chmod(collected, mode);
80014- do_utime(collected, mtime);
80015+ sys_mknod((char __force_user *)collected, mode, rdev);
80016+ sys_chown((char __force_user *)collected, uid, gid);
80017+ sys_chmod((char __force_user *)collected, mode);
80018+ do_utime((char __force_user *)collected, mtime);
80019 }
80020 }
80021 return 0;
80022@@ -346,15 +346,15 @@ static int __init do_name(void)
80023 static int __init do_copy(void)
80024 {
80025 if (count >= body_len) {
80026- sys_write(wfd, victim, body_len);
80027+ sys_write(wfd, (char __force_user *)victim, body_len);
80028 sys_close(wfd);
80029- do_utime(vcollected, mtime);
80030+ do_utime((char __force_user *)vcollected, mtime);
80031 kfree(vcollected);
80032 eat(body_len);
80033 state = SkipIt;
80034 return 0;
80035 } else {
80036- sys_write(wfd, victim, count);
80037+ sys_write(wfd, (char __force_user *)victim, count);
80038 body_len -= count;
80039 eat(count);
80040 return 1;
80041@@ -365,9 +365,9 @@ static int __init do_symlink(void)
80042 {
80043 collected[N_ALIGN(name_len) + body_len] = '\0';
80044 clean_path(collected, 0);
80045- sys_symlink(collected + N_ALIGN(name_len), collected);
80046- sys_lchown(collected, uid, gid);
80047- do_utime(collected, mtime);
80048+ sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
80049+ sys_lchown((char __force_user *)collected, uid, gid);
80050+ do_utime((char __force_user *)collected, mtime);
80051 state = SkipIt;
80052 next_state = Reset;
80053 return 0;
80054@@ -583,7 +583,7 @@ static int __init populate_rootfs(void)
80055 {
80056 char *err = unpack_to_rootfs(__initramfs_start, __initramfs_size);
80057 if (err)
80058- panic(err); /* Failed to decompress INTERNAL initramfs */
80059+ panic("%s", err); /* Failed to decompress INTERNAL initramfs */
80060 if (initrd_start) {
80061 #ifdef CONFIG_BLK_DEV_RAM
80062 int fd;
80063diff --git a/init/main.c b/init/main.c
80064index 63d3e8f..291fa8a 100644
80065--- a/init/main.c
80066+++ b/init/main.c
80067@@ -103,6 +103,8 @@ static inline void mark_rodata_ro(void) { }
80068 extern void tc_init(void);
80069 #endif
80070
80071+extern void grsecurity_init(void);
80072+
80073 /*
80074 * Debug helper: via this flag we know that we are in 'early bootup code'
80075 * where only the boot processor is running with IRQ disabled. This means
80076@@ -156,6 +158,74 @@ static int __init set_reset_devices(char *str)
80077
80078 __setup("reset_devices", set_reset_devices);
80079
80080+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
80081+kgid_t grsec_proc_gid = KGIDT_INIT(CONFIG_GRKERNSEC_PROC_GID);
80082+static int __init setup_grsec_proc_gid(char *str)
80083+{
80084+ grsec_proc_gid = KGIDT_INIT(simple_strtol(str, NULL, 0));
80085+ return 1;
80086+}
80087+__setup("grsec_proc_gid=", setup_grsec_proc_gid);
80088+#endif
80089+
80090+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
80091+unsigned long pax_user_shadow_base __read_only;
80092+EXPORT_SYMBOL(pax_user_shadow_base);
80093+extern char pax_enter_kernel_user[];
80094+extern char pax_exit_kernel_user[];
80095+#endif
80096+
80097+#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
80098+static int __init setup_pax_nouderef(char *str)
80099+{
80100+#ifdef CONFIG_X86_32
80101+ unsigned int cpu;
80102+ struct desc_struct *gdt;
80103+
80104+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
80105+ gdt = get_cpu_gdt_table(cpu);
80106+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
80107+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
80108+ gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
80109+ gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
80110+ }
80111+ loadsegment(ds, __KERNEL_DS);
80112+ loadsegment(es, __KERNEL_DS);
80113+ loadsegment(ss, __KERNEL_DS);
80114+#else
80115+ memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
80116+ memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
80117+ clone_pgd_mask = ~(pgdval_t)0UL;
80118+ pax_user_shadow_base = 0UL;
80119+ setup_clear_cpu_cap(X86_FEATURE_PCID);
80120+#endif
80121+
80122+ return 0;
80123+}
80124+early_param("pax_nouderef", setup_pax_nouderef);
80125+
80126+#ifdef CONFIG_X86_64
80127+static int __init setup_pax_weakuderef(char *str)
80128+{
80129+ if (clone_pgd_mask != ~(pgdval_t)0UL)
80130+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
80131+ return 1;
80132+}
80133+__setup("pax_weakuderef", setup_pax_weakuderef);
80134+#endif
80135+#endif
80136+
80137+#ifdef CONFIG_PAX_SOFTMODE
80138+int pax_softmode;
80139+
80140+static int __init setup_pax_softmode(char *str)
80141+{
80142+ get_option(&str, &pax_softmode);
80143+ return 1;
80144+}
80145+__setup("pax_softmode=", setup_pax_softmode);
80146+#endif
80147+
80148 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
80149 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
80150 static const char *panic_later, *panic_param;
80151@@ -682,25 +752,24 @@ int __init_or_module do_one_initcall(initcall_t fn)
80152 {
80153 int count = preempt_count();
80154 int ret;
80155- char msgbuf[64];
80156+ const char *msg1 = "", *msg2 = "";
80157
80158 if (initcall_debug)
80159 ret = do_one_initcall_debug(fn);
80160 else
80161 ret = fn();
80162
80163- msgbuf[0] = 0;
80164-
80165 if (preempt_count() != count) {
80166- sprintf(msgbuf, "preemption imbalance ");
80167+ msg1 = " preemption imbalance";
80168 preempt_count() = count;
80169 }
80170 if (irqs_disabled()) {
80171- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
80172+ msg2 = " disabled interrupts";
80173 local_irq_enable();
80174 }
80175- WARN(msgbuf[0], "initcall %pF returned with %s\n", fn, msgbuf);
80176+ WARN(*msg1 || *msg2, "initcall %pF returned with%s%s\n", fn, msg1, msg2);
80177
80178+ add_latent_entropy();
80179 return ret;
80180 }
80181
80182@@ -807,10 +876,14 @@ static int run_init_process(const char *init_filename)
80183 {
80184 argv_init[0] = init_filename;
80185 return do_execve(init_filename,
80186- (const char __user *const __user *)argv_init,
80187- (const char __user *const __user *)envp_init);
80188+ (const char __user *const __force_user *)argv_init,
80189+ (const char __user *const __force_user *)envp_init);
80190 }
80191
80192+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
80193+extern int gr_init_ran;
80194+#endif
80195+
80196 static noinline void __init kernel_init_freeable(void);
80197
80198 static int __ref kernel_init(void *unused)
80199@@ -831,6 +904,11 @@ static int __ref kernel_init(void *unused)
80200 pr_err("Failed to execute %s\n", ramdisk_execute_command);
80201 }
80202
80203+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
80204+ /* if no initrd was used, be extra sure we enforce chroot restrictions */
80205+ gr_init_ran = 1;
80206+#endif
80207+
80208 /*
80209 * We try each of these until one succeeds.
80210 *
80211@@ -885,7 +963,7 @@ static noinline void __init kernel_init_freeable(void)
80212 do_basic_setup();
80213
80214 /* Open the /dev/console on the rootfs, this should never fail */
80215- if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
80216+ if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
80217 pr_err("Warning: unable to open an initial console.\n");
80218
80219 (void) sys_dup(0);
80220@@ -898,11 +976,13 @@ static noinline void __init kernel_init_freeable(void)
80221 if (!ramdisk_execute_command)
80222 ramdisk_execute_command = "/init";
80223
80224- if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
80225+ if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
80226 ramdisk_execute_command = NULL;
80227 prepare_namespace();
80228 }
80229
80230+ grsecurity_init();
80231+
80232 /*
80233 * Ok, we have completed the initial bootup, and
80234 * we're essentially up and running. Get rid of the
80235diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
80236index b0e99de..09f385c 100644
80237--- a/ipc/ipc_sysctl.c
80238+++ b/ipc/ipc_sysctl.c
80239@@ -30,7 +30,7 @@ static void *get_ipc(ctl_table *table)
80240 static int proc_ipc_dointvec(ctl_table *table, int write,
80241 void __user *buffer, size_t *lenp, loff_t *ppos)
80242 {
80243- struct ctl_table ipc_table;
80244+ ctl_table_no_const ipc_table;
80245
80246 memcpy(&ipc_table, table, sizeof(ipc_table));
80247 ipc_table.data = get_ipc(table);
80248@@ -41,7 +41,7 @@ static int proc_ipc_dointvec(ctl_table *table, int write,
80249 static int proc_ipc_dointvec_minmax(ctl_table *table, int write,
80250 void __user *buffer, size_t *lenp, loff_t *ppos)
80251 {
80252- struct ctl_table ipc_table;
80253+ ctl_table_no_const ipc_table;
80254
80255 memcpy(&ipc_table, table, sizeof(ipc_table));
80256 ipc_table.data = get_ipc(table);
80257@@ -65,7 +65,7 @@ static int proc_ipc_dointvec_minmax_orphans(ctl_table *table, int write,
80258 static int proc_ipc_callback_dointvec_minmax(ctl_table *table, int write,
80259 void __user *buffer, size_t *lenp, loff_t *ppos)
80260 {
80261- struct ctl_table ipc_table;
80262+ ctl_table_no_const ipc_table;
80263 size_t lenp_bef = *lenp;
80264 int rc;
80265
80266@@ -88,7 +88,7 @@ static int proc_ipc_callback_dointvec_minmax(ctl_table *table, int write,
80267 static int proc_ipc_doulongvec_minmax(ctl_table *table, int write,
80268 void __user *buffer, size_t *lenp, loff_t *ppos)
80269 {
80270- struct ctl_table ipc_table;
80271+ ctl_table_no_const ipc_table;
80272 memcpy(&ipc_table, table, sizeof(ipc_table));
80273 ipc_table.data = get_ipc(table);
80274
80275@@ -122,7 +122,7 @@ static void ipc_auto_callback(int val)
80276 static int proc_ipcauto_dointvec_minmax(ctl_table *table, int write,
80277 void __user *buffer, size_t *lenp, loff_t *ppos)
80278 {
80279- struct ctl_table ipc_table;
80280+ ctl_table_no_const ipc_table;
80281 size_t lenp_bef = *lenp;
80282 int oldval;
80283 int rc;
80284diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
80285index 383d638..943fdbb 100644
80286--- a/ipc/mq_sysctl.c
80287+++ b/ipc/mq_sysctl.c
80288@@ -25,7 +25,7 @@ static void *get_mq(ctl_table *table)
80289 static int proc_mq_dointvec_minmax(ctl_table *table, int write,
80290 void __user *buffer, size_t *lenp, loff_t *ppos)
80291 {
80292- struct ctl_table mq_table;
80293+ ctl_table_no_const mq_table;
80294 memcpy(&mq_table, table, sizeof(mq_table));
80295 mq_table.data = get_mq(table);
80296
80297diff --git a/ipc/mqueue.c b/ipc/mqueue.c
80298index ae1996d..a35f2cc 100644
80299--- a/ipc/mqueue.c
80300+++ b/ipc/mqueue.c
80301@@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
80302 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
80303 info->attr.mq_msgsize);
80304
80305+ gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
80306 spin_lock(&mq_lock);
80307 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
80308 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
80309diff --git a/ipc/msg.c b/ipc/msg.c
80310index 558aa91..359e718 100644
80311--- a/ipc/msg.c
80312+++ b/ipc/msg.c
80313@@ -297,18 +297,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
80314 return security_msg_queue_associate(msq, msgflg);
80315 }
80316
80317+static struct ipc_ops msg_ops = {
80318+ .getnew = newque,
80319+ .associate = msg_security,
80320+ .more_checks = NULL
80321+};
80322+
80323 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
80324 {
80325 struct ipc_namespace *ns;
80326- struct ipc_ops msg_ops;
80327 struct ipc_params msg_params;
80328
80329 ns = current->nsproxy->ipc_ns;
80330
80331- msg_ops.getnew = newque;
80332- msg_ops.associate = msg_security;
80333- msg_ops.more_checks = NULL;
80334-
80335 msg_params.key = key;
80336 msg_params.flg = msgflg;
80337
80338diff --git a/ipc/sem.c b/ipc/sem.c
80339index db9d241..bc8427c 100644
80340--- a/ipc/sem.c
80341+++ b/ipc/sem.c
80342@@ -562,10 +562,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
80343 return 0;
80344 }
80345
80346+static struct ipc_ops sem_ops = {
80347+ .getnew = newary,
80348+ .associate = sem_security,
80349+ .more_checks = sem_more_checks
80350+};
80351+
80352 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
80353 {
80354 struct ipc_namespace *ns;
80355- struct ipc_ops sem_ops;
80356 struct ipc_params sem_params;
80357
80358 ns = current->nsproxy->ipc_ns;
80359@@ -573,10 +578,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
80360 if (nsems < 0 || nsems > ns->sc_semmsl)
80361 return -EINVAL;
80362
80363- sem_ops.getnew = newary;
80364- sem_ops.associate = sem_security;
80365- sem_ops.more_checks = sem_more_checks;
80366-
80367 sem_params.key = key;
80368 sem_params.flg = semflg;
80369 sem_params.u.nsems = nsems;
80370diff --git a/ipc/shm.c b/ipc/shm.c
80371index d697396..5aadb3f 100644
80372--- a/ipc/shm.c
80373+++ b/ipc/shm.c
80374@@ -72,6 +72,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
80375 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
80376 #endif
80377
80378+#ifdef CONFIG_GRKERNSEC
80379+extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
80380+ const time_t shm_createtime, const kuid_t cuid,
80381+ const int shmid);
80382+extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
80383+ const time_t shm_createtime);
80384+#endif
80385+
80386 void shm_init_ns(struct ipc_namespace *ns)
80387 {
80388 ns->shm_ctlmax = SHMMAX;
80389@@ -551,6 +559,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
80390 shp->shm_lprid = 0;
80391 shp->shm_atim = shp->shm_dtim = 0;
80392 shp->shm_ctim = get_seconds();
80393+#ifdef CONFIG_GRKERNSEC
80394+ {
80395+ struct timespec timeval;
80396+ do_posix_clock_monotonic_gettime(&timeval);
80397+
80398+ shp->shm_createtime = timeval.tv_sec;
80399+ }
80400+#endif
80401 shp->shm_segsz = size;
80402 shp->shm_nattch = 0;
80403 shp->shm_file = file;
80404@@ -604,18 +620,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
80405 return 0;
80406 }
80407
80408+static struct ipc_ops shm_ops = {
80409+ .getnew = newseg,
80410+ .associate = shm_security,
80411+ .more_checks = shm_more_checks
80412+};
80413+
80414 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
80415 {
80416 struct ipc_namespace *ns;
80417- struct ipc_ops shm_ops;
80418 struct ipc_params shm_params;
80419
80420 ns = current->nsproxy->ipc_ns;
80421
80422- shm_ops.getnew = newseg;
80423- shm_ops.associate = shm_security;
80424- shm_ops.more_checks = shm_more_checks;
80425-
80426 shm_params.key = key;
80427 shm_params.flg = shmflg;
80428 shm_params.u.size = size;
80429@@ -1076,6 +1093,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
80430 f_mode = FMODE_READ | FMODE_WRITE;
80431 }
80432 if (shmflg & SHM_EXEC) {
80433+
80434+#ifdef CONFIG_PAX_MPROTECT
80435+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
80436+ goto out;
80437+#endif
80438+
80439 prot |= PROT_EXEC;
80440 acc_mode |= S_IXUGO;
80441 }
80442@@ -1100,10 +1123,23 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
80443 if (err)
80444 goto out_unlock;
80445
80446+#ifdef CONFIG_GRKERNSEC
80447+ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
80448+ shp->shm_perm.cuid, shmid) ||
80449+ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
80450+ err = -EACCES;
80451+ goto out_unlock;
80452+ }
80453+#endif
80454+
80455 ipc_lock_object(&shp->shm_perm);
80456+
80457 path = shp->shm_file->f_path;
80458 path_get(&path);
80459 shp->shm_nattch++;
80460+#ifdef CONFIG_GRKERNSEC
80461+ shp->shm_lapid = current->pid;
80462+#endif
80463 size = i_size_read(path.dentry->d_inode);
80464 ipc_unlock_object(&shp->shm_perm);
80465 rcu_read_unlock();
80466diff --git a/ipc/util.c b/ipc/util.c
80467index 7684f41..f7da711 100644
80468--- a/ipc/util.c
80469+++ b/ipc/util.c
80470@@ -71,6 +71,8 @@ struct ipc_proc_iface {
80471 int (*show)(struct seq_file *, void *);
80472 };
80473
80474+extern int gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode);
80475+
80476 static void ipc_memory_notifier(struct work_struct *work)
80477 {
80478 ipcns_notify(IPCNS_MEMCHANGED);
80479@@ -560,6 +562,9 @@ int ipcperms(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, short flag)
80480 granted_mode >>= 6;
80481 else if (in_group_p(ipcp->cgid) || in_group_p(ipcp->gid))
80482 granted_mode >>= 3;
80483+ else if (!gr_ipc_permitted(ns, ipcp, requested_mode, granted_mode))
80484+ return -1;
80485+
80486 /* is there some bit set in requested_mode but not in granted_mode? */
80487 if ((requested_mode & ~granted_mode & 0007) &&
80488 !ns_capable(ns->user_ns, CAP_IPC_OWNER))
80489diff --git a/kernel/acct.c b/kernel/acct.c
80490index 8d6e145..33e0b1e 100644
80491--- a/kernel/acct.c
80492+++ b/kernel/acct.c
80493@@ -556,7 +556,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
80494 */
80495 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
80496 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
80497- file->f_op->write(file, (char *)&ac,
80498+ file->f_op->write(file, (char __force_user *)&ac,
80499 sizeof(acct_t), &file->f_pos);
80500 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
80501 set_fs(fs);
80502diff --git a/kernel/audit.c b/kernel/audit.c
80503index 7b0e23a..f4d172f 100644
80504--- a/kernel/audit.c
80505+++ b/kernel/audit.c
80506@@ -118,7 +118,7 @@ u32 audit_sig_sid = 0;
80507 3) suppressed due to audit_rate_limit
80508 4) suppressed due to audit_backlog_limit
80509 */
80510-static atomic_t audit_lost = ATOMIC_INIT(0);
80511+static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
80512
80513 /* The netlink socket. */
80514 static struct sock *audit_sock;
80515@@ -240,7 +240,7 @@ void audit_log_lost(const char *message)
80516 unsigned long now;
80517 int print;
80518
80519- atomic_inc(&audit_lost);
80520+ atomic_inc_unchecked(&audit_lost);
80521
80522 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
80523
80524@@ -259,7 +259,7 @@ void audit_log_lost(const char *message)
80525 printk(KERN_WARNING
80526 "audit: audit_lost=%d audit_rate_limit=%d "
80527 "audit_backlog_limit=%d\n",
80528- atomic_read(&audit_lost),
80529+ atomic_read_unchecked(&audit_lost),
80530 audit_rate_limit,
80531 audit_backlog_limit);
80532 audit_panic(message);
80533@@ -659,18 +659,19 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
80534
80535 switch (msg_type) {
80536 case AUDIT_GET:
80537+ status_set.mask = 0;
80538 status_set.enabled = audit_enabled;
80539 status_set.failure = audit_failure;
80540 status_set.pid = audit_pid;
80541 status_set.rate_limit = audit_rate_limit;
80542 status_set.backlog_limit = audit_backlog_limit;
80543- status_set.lost = atomic_read(&audit_lost);
80544+ status_set.lost = atomic_read_unchecked(&audit_lost);
80545 status_set.backlog = skb_queue_len(&audit_skb_queue);
80546 audit_send_reply(NETLINK_CB(skb).portid, seq, AUDIT_GET, 0, 0,
80547 &status_set, sizeof(status_set));
80548 break;
80549 case AUDIT_SET:
80550- if (nlh->nlmsg_len < sizeof(struct audit_status))
80551+ if (nlmsg_len(nlh) < sizeof(struct audit_status))
80552 return -EINVAL;
80553 status_get = (struct audit_status *)data;
80554 if (status_get->mask & AUDIT_STATUS_ENABLED) {
80555@@ -832,7 +833,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
80556
80557 memset(&s, 0, sizeof(s));
80558 /* guard against past and future API changes */
80559- memcpy(&s, data, min(sizeof(s), (size_t)nlh->nlmsg_len));
80560+ memcpy(&s, data, min_t(size_t, sizeof(s), nlmsg_len(nlh)));
80561 if ((s.enabled != 0 && s.enabled != 1) ||
80562 (s.log_passwd != 0 && s.log_passwd != 1))
80563 return -EINVAL;
80564@@ -1251,7 +1252,7 @@ void audit_log_n_hex(struct audit_buffer *ab, const unsigned char *buf,
80565 int i, avail, new_len;
80566 unsigned char *ptr;
80567 struct sk_buff *skb;
80568- static const unsigned char *hex = "0123456789ABCDEF";
80569+ static const unsigned char hex[] = "0123456789ABCDEF";
80570
80571 if (!ab)
80572 return;
80573diff --git a/kernel/auditsc.c b/kernel/auditsc.c
80574index 9845cb3..3ec9369 100644
80575--- a/kernel/auditsc.c
80576+++ b/kernel/auditsc.c
80577@@ -1962,7 +1962,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
80578 }
80579
80580 /* global counter which is incremented every time something logs in */
80581-static atomic_t session_id = ATOMIC_INIT(0);
80582+static atomic_unchecked_t session_id = ATOMIC_INIT(0);
80583
80584 /**
80585 * audit_set_loginuid - set current task's audit_context loginuid
80586@@ -1986,7 +1986,7 @@ int audit_set_loginuid(kuid_t loginuid)
80587 return -EPERM;
80588 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
80589
80590- sessionid = atomic_inc_return(&session_id);
80591+ sessionid = atomic_inc_return_unchecked(&session_id);
80592 if (context && context->in_syscall) {
80593 struct audit_buffer *ab;
80594
80595diff --git a/kernel/capability.c b/kernel/capability.c
80596index 4e66bf9..cdccecf 100644
80597--- a/kernel/capability.c
80598+++ b/kernel/capability.c
80599@@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
80600 * before modification is attempted and the application
80601 * fails.
80602 */
80603+ if (tocopy > ARRAY_SIZE(kdata))
80604+ return -EFAULT;
80605+
80606 if (copy_to_user(dataptr, kdata, tocopy
80607 * sizeof(struct __user_cap_data_struct))) {
80608 return -EFAULT;
80609@@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
80610 int ret;
80611
80612 rcu_read_lock();
80613- ret = security_capable(__task_cred(t), ns, cap);
80614+ ret = security_capable(__task_cred(t), ns, cap) == 0 &&
80615+ gr_task_is_capable(t, __task_cred(t), cap);
80616 rcu_read_unlock();
80617
80618- return (ret == 0);
80619+ return ret;
80620 }
80621
80622 /**
80623@@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
80624 int ret;
80625
80626 rcu_read_lock();
80627- ret = security_capable_noaudit(__task_cred(t), ns, cap);
80628+ ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
80629 rcu_read_unlock();
80630
80631- return (ret == 0);
80632+ return ret;
80633 }
80634
80635 /**
80636@@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
80637 BUG();
80638 }
80639
80640- if (security_capable(current_cred(), ns, cap) == 0) {
80641+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
80642 current->flags |= PF_SUPERPRIV;
80643 return true;
80644 }
80645@@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
80646 }
80647 EXPORT_SYMBOL(ns_capable);
80648
80649+bool ns_capable_nolog(struct user_namespace *ns, int cap)
80650+{
80651+ if (unlikely(!cap_valid(cap))) {
80652+ printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
80653+ BUG();
80654+ }
80655+
80656+ if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
80657+ current->flags |= PF_SUPERPRIV;
80658+ return true;
80659+ }
80660+ return false;
80661+}
80662+EXPORT_SYMBOL(ns_capable_nolog);
80663+
80664 /**
80665 * file_ns_capable - Determine if the file's opener had a capability in effect
80666 * @file: The file we want to check
80667@@ -432,6 +451,12 @@ bool capable(int cap)
80668 }
80669 EXPORT_SYMBOL(capable);
80670
80671+bool capable_nolog(int cap)
80672+{
80673+ return ns_capable_nolog(&init_user_ns, cap);
80674+}
80675+EXPORT_SYMBOL(capable_nolog);
80676+
80677 /**
80678 * inode_capable - Check superior capability over inode
80679 * @inode: The inode in question
80680@@ -453,3 +478,11 @@ bool inode_capable(const struct inode *inode, int cap)
80681 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
80682 }
80683 EXPORT_SYMBOL(inode_capable);
80684+
80685+bool inode_capable_nolog(const struct inode *inode, int cap)
80686+{
80687+ struct user_namespace *ns = current_user_ns();
80688+
80689+ return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
80690+}
80691+EXPORT_SYMBOL(inode_capable_nolog);
80692diff --git a/kernel/cgroup.c b/kernel/cgroup.c
80693index 8bd9cfd..9faf120 100644
80694--- a/kernel/cgroup.c
80695+++ b/kernel/cgroup.c
80696@@ -5817,7 +5817,7 @@ static int cgroup_css_links_read(struct cgroup_subsys_state *css,
80697 struct css_set *cset = link->cset;
80698 struct task_struct *task;
80699 int count = 0;
80700- seq_printf(seq, "css_set %p\n", cset);
80701+ seq_printf(seq, "css_set %pK\n", cset);
80702 list_for_each_entry(task, &cset->tasks, cg_list) {
80703 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
80704 seq_puts(seq, " ...\n");
80705diff --git a/kernel/compat.c b/kernel/compat.c
80706index 0a09e48..f44f3f0 100644
80707--- a/kernel/compat.c
80708+++ b/kernel/compat.c
80709@@ -13,6 +13,7 @@
80710
80711 #include <linux/linkage.h>
80712 #include <linux/compat.h>
80713+#include <linux/module.h>
80714 #include <linux/errno.h>
80715 #include <linux/time.h>
80716 #include <linux/signal.h>
80717@@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
80718 mm_segment_t oldfs;
80719 long ret;
80720
80721- restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
80722+ restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
80723 oldfs = get_fs();
80724 set_fs(KERNEL_DS);
80725 ret = hrtimer_nanosleep_restart(restart);
80726@@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
80727 oldfs = get_fs();
80728 set_fs(KERNEL_DS);
80729 ret = hrtimer_nanosleep(&tu,
80730- rmtp ? (struct timespec __user *)&rmt : NULL,
80731+ rmtp ? (struct timespec __force_user *)&rmt : NULL,
80732 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
80733 set_fs(oldfs);
80734
80735@@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
80736 mm_segment_t old_fs = get_fs();
80737
80738 set_fs(KERNEL_DS);
80739- ret = sys_sigpending((old_sigset_t __user *) &s);
80740+ ret = sys_sigpending((old_sigset_t __force_user *) &s);
80741 set_fs(old_fs);
80742 if (ret == 0)
80743 ret = put_user(s, set);
80744@@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
80745 mm_segment_t old_fs = get_fs();
80746
80747 set_fs(KERNEL_DS);
80748- ret = sys_old_getrlimit(resource, &r);
80749+ ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
80750 set_fs(old_fs);
80751
80752 if (!ret) {
80753@@ -533,8 +534,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
80754 set_fs (KERNEL_DS);
80755 ret = sys_wait4(pid,
80756 (stat_addr ?
80757- (unsigned int __user *) &status : NULL),
80758- options, (struct rusage __user *) &r);
80759+ (unsigned int __force_user *) &status : NULL),
80760+ options, (struct rusage __force_user *) &r);
80761 set_fs (old_fs);
80762
80763 if (ret > 0) {
80764@@ -560,8 +561,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
80765 memset(&info, 0, sizeof(info));
80766
80767 set_fs(KERNEL_DS);
80768- ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
80769- uru ? (struct rusage __user *)&ru : NULL);
80770+ ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
80771+ uru ? (struct rusage __force_user *)&ru : NULL);
80772 set_fs(old_fs);
80773
80774 if ((ret < 0) || (info.si_signo == 0))
80775@@ -695,8 +696,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
80776 oldfs = get_fs();
80777 set_fs(KERNEL_DS);
80778 err = sys_timer_settime(timer_id, flags,
80779- (struct itimerspec __user *) &newts,
80780- (struct itimerspec __user *) &oldts);
80781+ (struct itimerspec __force_user *) &newts,
80782+ (struct itimerspec __force_user *) &oldts);
80783 set_fs(oldfs);
80784 if (!err && old && put_compat_itimerspec(old, &oldts))
80785 return -EFAULT;
80786@@ -713,7 +714,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
80787 oldfs = get_fs();
80788 set_fs(KERNEL_DS);
80789 err = sys_timer_gettime(timer_id,
80790- (struct itimerspec __user *) &ts);
80791+ (struct itimerspec __force_user *) &ts);
80792 set_fs(oldfs);
80793 if (!err && put_compat_itimerspec(setting, &ts))
80794 return -EFAULT;
80795@@ -732,7 +733,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
80796 oldfs = get_fs();
80797 set_fs(KERNEL_DS);
80798 err = sys_clock_settime(which_clock,
80799- (struct timespec __user *) &ts);
80800+ (struct timespec __force_user *) &ts);
80801 set_fs(oldfs);
80802 return err;
80803 }
80804@@ -747,7 +748,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
80805 oldfs = get_fs();
80806 set_fs(KERNEL_DS);
80807 err = sys_clock_gettime(which_clock,
80808- (struct timespec __user *) &ts);
80809+ (struct timespec __force_user *) &ts);
80810 set_fs(oldfs);
80811 if (!err && put_compat_timespec(&ts, tp))
80812 return -EFAULT;
80813@@ -767,7 +768,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
80814
80815 oldfs = get_fs();
80816 set_fs(KERNEL_DS);
80817- ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
80818+ ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
80819 set_fs(oldfs);
80820
80821 err = compat_put_timex(utp, &txc);
80822@@ -787,7 +788,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
80823 oldfs = get_fs();
80824 set_fs(KERNEL_DS);
80825 err = sys_clock_getres(which_clock,
80826- (struct timespec __user *) &ts);
80827+ (struct timespec __force_user *) &ts);
80828 set_fs(oldfs);
80829 if (!err && tp && put_compat_timespec(&ts, tp))
80830 return -EFAULT;
80831@@ -799,9 +800,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
80832 long err;
80833 mm_segment_t oldfs;
80834 struct timespec tu;
80835- struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
80836+ struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
80837
80838- restart->nanosleep.rmtp = (struct timespec __user *) &tu;
80839+ restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
80840 oldfs = get_fs();
80841 set_fs(KERNEL_DS);
80842 err = clock_nanosleep_restart(restart);
80843@@ -833,8 +834,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
80844 oldfs = get_fs();
80845 set_fs(KERNEL_DS);
80846 err = sys_clock_nanosleep(which_clock, flags,
80847- (struct timespec __user *) &in,
80848- (struct timespec __user *) &out);
80849+ (struct timespec __force_user *) &in,
80850+ (struct timespec __force_user *) &out);
80851 set_fs(oldfs);
80852
80853 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
80854diff --git a/kernel/configs.c b/kernel/configs.c
80855index c18b1f1..b9a0132 100644
80856--- a/kernel/configs.c
80857+++ b/kernel/configs.c
80858@@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
80859 struct proc_dir_entry *entry;
80860
80861 /* create the current config file */
80862+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
80863+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
80864+ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
80865+ &ikconfig_file_ops);
80866+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
80867+ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
80868+ &ikconfig_file_ops);
80869+#endif
80870+#else
80871 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
80872 &ikconfig_file_ops);
80873+#endif
80874+
80875 if (!entry)
80876 return -ENOMEM;
80877
80878diff --git a/kernel/cred.c b/kernel/cred.c
80879index e0573a4..3874e41 100644
80880--- a/kernel/cred.c
80881+++ b/kernel/cred.c
80882@@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
80883 validate_creds(cred);
80884 alter_cred_subscribers(cred, -1);
80885 put_cred(cred);
80886+
80887+#ifdef CONFIG_GRKERNSEC_SETXID
80888+ cred = (struct cred *) tsk->delayed_cred;
80889+ if (cred != NULL) {
80890+ tsk->delayed_cred = NULL;
80891+ validate_creds(cred);
80892+ alter_cred_subscribers(cred, -1);
80893+ put_cred(cred);
80894+ }
80895+#endif
80896 }
80897
80898 /**
80899@@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
80900 * Always returns 0 thus allowing this function to be tail-called at the end
80901 * of, say, sys_setgid().
80902 */
80903-int commit_creds(struct cred *new)
80904+static int __commit_creds(struct cred *new)
80905 {
80906 struct task_struct *task = current;
80907 const struct cred *old = task->real_cred;
80908@@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
80909
80910 get_cred(new); /* we will require a ref for the subj creds too */
80911
80912+ gr_set_role_label(task, new->uid, new->gid);
80913+
80914 /* dumpability changes */
80915 if (!uid_eq(old->euid, new->euid) ||
80916 !gid_eq(old->egid, new->egid) ||
80917@@ -479,6 +491,102 @@ int commit_creds(struct cred *new)
80918 put_cred(old);
80919 return 0;
80920 }
80921+#ifdef CONFIG_GRKERNSEC_SETXID
80922+extern int set_user(struct cred *new);
80923+
80924+void gr_delayed_cred_worker(void)
80925+{
80926+ const struct cred *new = current->delayed_cred;
80927+ struct cred *ncred;
80928+
80929+ current->delayed_cred = NULL;
80930+
80931+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID) && new != NULL) {
80932+ // from doing get_cred on it when queueing this
80933+ put_cred(new);
80934+ return;
80935+ } else if (new == NULL)
80936+ return;
80937+
80938+ ncred = prepare_creds();
80939+ if (!ncred)
80940+ goto die;
80941+ // uids
80942+ ncred->uid = new->uid;
80943+ ncred->euid = new->euid;
80944+ ncred->suid = new->suid;
80945+ ncred->fsuid = new->fsuid;
80946+ // gids
80947+ ncred->gid = new->gid;
80948+ ncred->egid = new->egid;
80949+ ncred->sgid = new->sgid;
80950+ ncred->fsgid = new->fsgid;
80951+ // groups
80952+ if (set_groups(ncred, new->group_info) < 0) {
80953+ abort_creds(ncred);
80954+ goto die;
80955+ }
80956+ // caps
80957+ ncred->securebits = new->securebits;
80958+ ncred->cap_inheritable = new->cap_inheritable;
80959+ ncred->cap_permitted = new->cap_permitted;
80960+ ncred->cap_effective = new->cap_effective;
80961+ ncred->cap_bset = new->cap_bset;
80962+
80963+ if (set_user(ncred)) {
80964+ abort_creds(ncred);
80965+ goto die;
80966+ }
80967+
80968+ // from doing get_cred on it when queueing this
80969+ put_cred(new);
80970+
80971+ __commit_creds(ncred);
80972+ return;
80973+die:
80974+ // from doing get_cred on it when queueing this
80975+ put_cred(new);
80976+ do_group_exit(SIGKILL);
80977+}
80978+#endif
80979+
80980+int commit_creds(struct cred *new)
80981+{
80982+#ifdef CONFIG_GRKERNSEC_SETXID
80983+ int ret;
80984+ int schedule_it = 0;
80985+ struct task_struct *t;
80986+
80987+ /* we won't get called with tasklist_lock held for writing
80988+ and interrupts disabled as the cred struct in that case is
80989+ init_cred
80990+ */
80991+ if (grsec_enable_setxid && !current_is_single_threaded() &&
80992+ uid_eq(current_uid(), GLOBAL_ROOT_UID) &&
80993+ !uid_eq(new->uid, GLOBAL_ROOT_UID)) {
80994+ schedule_it = 1;
80995+ }
80996+ ret = __commit_creds(new);
80997+ if (schedule_it) {
80998+ rcu_read_lock();
80999+ read_lock(&tasklist_lock);
81000+ for (t = next_thread(current); t != current;
81001+ t = next_thread(t)) {
81002+ if (t->delayed_cred == NULL) {
81003+ t->delayed_cred = get_cred(new);
81004+ set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
81005+ set_tsk_need_resched(t);
81006+ }
81007+ }
81008+ read_unlock(&tasklist_lock);
81009+ rcu_read_unlock();
81010+ }
81011+ return ret;
81012+#else
81013+ return __commit_creds(new);
81014+#endif
81015+}
81016+
81017 EXPORT_SYMBOL(commit_creds);
81018
81019 /**
81020diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
81021index 0506d44..2c20034 100644
81022--- a/kernel/debug/debug_core.c
81023+++ b/kernel/debug/debug_core.c
81024@@ -123,7 +123,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
81025 */
81026 static atomic_t masters_in_kgdb;
81027 static atomic_t slaves_in_kgdb;
81028-static atomic_t kgdb_break_tasklet_var;
81029+static atomic_unchecked_t kgdb_break_tasklet_var;
81030 atomic_t kgdb_setting_breakpoint;
81031
81032 struct task_struct *kgdb_usethread;
81033@@ -133,7 +133,7 @@ int kgdb_single_step;
81034 static pid_t kgdb_sstep_pid;
81035
81036 /* to keep track of the CPU which is doing the single stepping*/
81037-atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
81038+atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
81039
81040 /*
81041 * If you are debugging a problem where roundup (the collection of
81042@@ -541,7 +541,7 @@ return_normal:
81043 * kernel will only try for the value of sstep_tries before
81044 * giving up and continuing on.
81045 */
81046- if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
81047+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
81048 (kgdb_info[cpu].task &&
81049 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
81050 atomic_set(&kgdb_active, -1);
81051@@ -635,8 +635,8 @@ cpu_master_loop:
81052 }
81053
81054 kgdb_restore:
81055- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
81056- int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
81057+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
81058+ int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
81059 if (kgdb_info[sstep_cpu].task)
81060 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
81061 else
81062@@ -888,18 +888,18 @@ static void kgdb_unregister_callbacks(void)
81063 static void kgdb_tasklet_bpt(unsigned long ing)
81064 {
81065 kgdb_breakpoint();
81066- atomic_set(&kgdb_break_tasklet_var, 0);
81067+ atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
81068 }
81069
81070 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
81071
81072 void kgdb_schedule_breakpoint(void)
81073 {
81074- if (atomic_read(&kgdb_break_tasklet_var) ||
81075+ if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
81076 atomic_read(&kgdb_active) != -1 ||
81077 atomic_read(&kgdb_setting_breakpoint))
81078 return;
81079- atomic_inc(&kgdb_break_tasklet_var);
81080+ atomic_inc_unchecked(&kgdb_break_tasklet_var);
81081 tasklet_schedule(&kgdb_tasklet_breakpoint);
81082 }
81083 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
81084diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
81085index 00eb8f7..d7e3244 100644
81086--- a/kernel/debug/kdb/kdb_main.c
81087+++ b/kernel/debug/kdb/kdb_main.c
81088@@ -1974,7 +1974,7 @@ static int kdb_lsmod(int argc, const char **argv)
81089 continue;
81090
81091 kdb_printf("%-20s%8u 0x%p ", mod->name,
81092- mod->core_size, (void *)mod);
81093+ mod->core_size_rx + mod->core_size_rw, (void *)mod);
81094 #ifdef CONFIG_MODULE_UNLOAD
81095 kdb_printf("%4ld ", module_refcount(mod));
81096 #endif
81097@@ -1984,7 +1984,7 @@ static int kdb_lsmod(int argc, const char **argv)
81098 kdb_printf(" (Loading)");
81099 else
81100 kdb_printf(" (Live)");
81101- kdb_printf(" 0x%p", mod->module_core);
81102+ kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
81103
81104 #ifdef CONFIG_MODULE_UNLOAD
81105 {
81106diff --git a/kernel/events/core.c b/kernel/events/core.c
81107index 953c143..5646bb1 100644
81108--- a/kernel/events/core.c
81109+++ b/kernel/events/core.c
81110@@ -157,8 +157,15 @@ static struct srcu_struct pmus_srcu;
81111 * 0 - disallow raw tracepoint access for unpriv
81112 * 1 - disallow cpu events for unpriv
81113 * 2 - disallow kernel profiling for unpriv
81114+ * 3 - disallow all unpriv perf event use
81115 */
81116-int sysctl_perf_event_paranoid __read_mostly = 1;
81117+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
81118+int sysctl_perf_event_legitimately_concerned __read_mostly = 3;
81119+#elif defined(CONFIG_GRKERNSEC_HIDESYM)
81120+int sysctl_perf_event_legitimately_concerned __read_mostly = 2;
81121+#else
81122+int sysctl_perf_event_legitimately_concerned __read_mostly = 1;
81123+#endif
81124
81125 /* Minimum for 512 kiB + 1 user control page */
81126 int sysctl_perf_event_mlock __read_mostly = 512 + (PAGE_SIZE / 1024); /* 'free' kiB per user */
81127@@ -271,7 +278,7 @@ void perf_sample_event_took(u64 sample_len_ns)
81128 update_perf_cpu_limits();
81129 }
81130
81131-static atomic64_t perf_event_id;
81132+static atomic64_unchecked_t perf_event_id;
81133
81134 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
81135 enum event_type_t event_type);
81136@@ -2940,7 +2947,7 @@ static void __perf_event_read(void *info)
81137
81138 static inline u64 perf_event_count(struct perf_event *event)
81139 {
81140- return local64_read(&event->count) + atomic64_read(&event->child_count);
81141+ return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
81142 }
81143
81144 static u64 perf_event_read(struct perf_event *event)
81145@@ -3308,9 +3315,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
81146 mutex_lock(&event->child_mutex);
81147 total += perf_event_read(event);
81148 *enabled += event->total_time_enabled +
81149- atomic64_read(&event->child_total_time_enabled);
81150+ atomic64_read_unchecked(&event->child_total_time_enabled);
81151 *running += event->total_time_running +
81152- atomic64_read(&event->child_total_time_running);
81153+ atomic64_read_unchecked(&event->child_total_time_running);
81154
81155 list_for_each_entry(child, &event->child_list, child_list) {
81156 total += perf_event_read(child);
81157@@ -3725,10 +3732,10 @@ void perf_event_update_userpage(struct perf_event *event)
81158 userpg->offset -= local64_read(&event->hw.prev_count);
81159
81160 userpg->time_enabled = enabled +
81161- atomic64_read(&event->child_total_time_enabled);
81162+ atomic64_read_unchecked(&event->child_total_time_enabled);
81163
81164 userpg->time_running = running +
81165- atomic64_read(&event->child_total_time_running);
81166+ atomic64_read_unchecked(&event->child_total_time_running);
81167
81168 arch_perf_update_userpage(userpg, now);
81169
81170@@ -4279,7 +4286,7 @@ perf_output_sample_ustack(struct perf_output_handle *handle, u64 dump_size,
81171
81172 /* Data. */
81173 sp = perf_user_stack_pointer(regs);
81174- rem = __output_copy_user(handle, (void *) sp, dump_size);
81175+ rem = __output_copy_user(handle, (void __user *) sp, dump_size);
81176 dyn_size = dump_size - rem;
81177
81178 perf_output_skip(handle, rem);
81179@@ -4370,11 +4377,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
81180 values[n++] = perf_event_count(event);
81181 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
81182 values[n++] = enabled +
81183- atomic64_read(&event->child_total_time_enabled);
81184+ atomic64_read_unchecked(&event->child_total_time_enabled);
81185 }
81186 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
81187 values[n++] = running +
81188- atomic64_read(&event->child_total_time_running);
81189+ atomic64_read_unchecked(&event->child_total_time_running);
81190 }
81191 if (read_format & PERF_FORMAT_ID)
81192 values[n++] = primary_event_id(event);
81193@@ -5112,12 +5119,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
81194 * need to add enough zero bytes after the string to handle
81195 * the 64bit alignment we do later.
81196 */
81197- buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
81198+ buf = kzalloc(PATH_MAX, GFP_KERNEL);
81199 if (!buf) {
81200 name = strncpy(tmp, "//enomem", sizeof(tmp));
81201 goto got_name;
81202 }
81203- name = d_path(&file->f_path, buf, PATH_MAX);
81204+ name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
81205 if (IS_ERR(name)) {
81206 name = strncpy(tmp, "//toolong", sizeof(tmp));
81207 goto got_name;
81208@@ -6639,7 +6646,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
81209 event->parent = parent_event;
81210
81211 event->ns = get_pid_ns(task_active_pid_ns(current));
81212- event->id = atomic64_inc_return(&perf_event_id);
81213+ event->id = atomic64_inc_return_unchecked(&perf_event_id);
81214
81215 event->state = PERF_EVENT_STATE_INACTIVE;
81216
81217@@ -6938,6 +6945,11 @@ SYSCALL_DEFINE5(perf_event_open,
81218 if (flags & ~PERF_FLAG_ALL)
81219 return -EINVAL;
81220
81221+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
81222+ if (perf_paranoid_any() && !capable(CAP_SYS_ADMIN))
81223+ return -EACCES;
81224+#endif
81225+
81226 err = perf_copy_attr(attr_uptr, &attr);
81227 if (err)
81228 return err;
81229@@ -7271,10 +7283,10 @@ static void sync_child_event(struct perf_event *child_event,
81230 /*
81231 * Add back the child's count to the parent's count:
81232 */
81233- atomic64_add(child_val, &parent_event->child_count);
81234- atomic64_add(child_event->total_time_enabled,
81235+ atomic64_add_unchecked(child_val, &parent_event->child_count);
81236+ atomic64_add_unchecked(child_event->total_time_enabled,
81237 &parent_event->child_total_time_enabled);
81238- atomic64_add(child_event->total_time_running,
81239+ atomic64_add_unchecked(child_event->total_time_running,
81240 &parent_event->child_total_time_running);
81241
81242 /*
81243diff --git a/kernel/events/internal.h b/kernel/events/internal.h
81244index ca65997..60df03d 100644
81245--- a/kernel/events/internal.h
81246+++ b/kernel/events/internal.h
81247@@ -81,10 +81,10 @@ static inline unsigned long perf_data_size(struct ring_buffer *rb)
81248 return rb->nr_pages << (PAGE_SHIFT + page_order(rb));
81249 }
81250
81251-#define DEFINE_OUTPUT_COPY(func_name, memcpy_func) \
81252-static inline unsigned int \
81253+#define DEFINE_OUTPUT_COPY(func_name, memcpy_func, user) \
81254+static inline unsigned long \
81255 func_name(struct perf_output_handle *handle, \
81256- const void *buf, unsigned int len) \
81257+ const void user *buf, unsigned long len) \
81258 { \
81259 unsigned long size, written; \
81260 \
81261@@ -116,17 +116,17 @@ static inline int memcpy_common(void *dst, const void *src, size_t n)
81262 return n;
81263 }
81264
81265-DEFINE_OUTPUT_COPY(__output_copy, memcpy_common)
81266+DEFINE_OUTPUT_COPY(__output_copy, memcpy_common, )
81267
81268 #define MEMCPY_SKIP(dst, src, n) (n)
81269
81270-DEFINE_OUTPUT_COPY(__output_skip, MEMCPY_SKIP)
81271+DEFINE_OUTPUT_COPY(__output_skip, MEMCPY_SKIP, )
81272
81273 #ifndef arch_perf_out_copy_user
81274 #define arch_perf_out_copy_user __copy_from_user_inatomic
81275 #endif
81276
81277-DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user)
81278+DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user, __user)
81279
81280 /* Callchain handling */
81281 extern struct perf_callchain_entry *
81282diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
81283index ad8e1bd..fed7ba9 100644
81284--- a/kernel/events/uprobes.c
81285+++ b/kernel/events/uprobes.c
81286@@ -1556,7 +1556,7 @@ static int is_trap_at_addr(struct mm_struct *mm, unsigned long vaddr)
81287 {
81288 struct page *page;
81289 uprobe_opcode_t opcode;
81290- int result;
81291+ long result;
81292
81293 pagefault_disable();
81294 result = __copy_from_user_inatomic(&opcode, (void __user*)vaddr,
81295diff --git a/kernel/exit.c b/kernel/exit.c
81296index a949819..a5f127d 100644
81297--- a/kernel/exit.c
81298+++ b/kernel/exit.c
81299@@ -172,6 +172,10 @@ void release_task(struct task_struct * p)
81300 struct task_struct *leader;
81301 int zap_leader;
81302 repeat:
81303+#ifdef CONFIG_NET
81304+ gr_del_task_from_ip_table(p);
81305+#endif
81306+
81307 /* don't need to get the RCU readlock here - the process is dead and
81308 * can't be modifying its own credentials. But shut RCU-lockdep up */
81309 rcu_read_lock();
81310@@ -329,7 +333,7 @@ int allow_signal(int sig)
81311 * know it'll be handled, so that they don't get converted to
81312 * SIGKILL or just silently dropped.
81313 */
81314- current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
81315+ current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
81316 recalc_sigpending();
81317 spin_unlock_irq(&current->sighand->siglock);
81318 return 0;
81319@@ -698,6 +702,8 @@ void do_exit(long code)
81320 struct task_struct *tsk = current;
81321 int group_dead;
81322
81323+ set_fs(USER_DS);
81324+
81325 profile_task_exit(tsk);
81326
81327 WARN_ON(blk_needs_flush_plug(tsk));
81328@@ -714,7 +720,6 @@ void do_exit(long code)
81329 * mm_release()->clear_child_tid() from writing to a user-controlled
81330 * kernel address.
81331 */
81332- set_fs(USER_DS);
81333
81334 ptrace_event(PTRACE_EVENT_EXIT, code);
81335
81336@@ -773,6 +778,9 @@ void do_exit(long code)
81337 tsk->exit_code = code;
81338 taskstats_exit(tsk, group_dead);
81339
81340+ gr_acl_handle_psacct(tsk, code);
81341+ gr_acl_handle_exit();
81342+
81343 exit_mm(tsk);
81344
81345 if (group_dead)
81346@@ -894,7 +902,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
81347 * Take down every thread in the group. This is called by fatal signals
81348 * as well as by sys_exit_group (below).
81349 */
81350-void
81351+__noreturn void
81352 do_group_exit(int exit_code)
81353 {
81354 struct signal_struct *sig = current->signal;
81355diff --git a/kernel/fork.c b/kernel/fork.c
81356index 086fe73..72c1122 100644
81357--- a/kernel/fork.c
81358+++ b/kernel/fork.c
81359@@ -319,7 +319,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
81360 *stackend = STACK_END_MAGIC; /* for overflow detection */
81361
81362 #ifdef CONFIG_CC_STACKPROTECTOR
81363- tsk->stack_canary = get_random_int();
81364+ tsk->stack_canary = pax_get_random_long();
81365 #endif
81366
81367 /*
81368@@ -345,12 +345,80 @@ free_tsk:
81369 }
81370
81371 #ifdef CONFIG_MMU
81372-static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
81373+static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
81374+{
81375+ struct vm_area_struct *tmp;
81376+ unsigned long charge;
81377+ struct file *file;
81378+ int retval;
81379+
81380+ charge = 0;
81381+ if (mpnt->vm_flags & VM_ACCOUNT) {
81382+ unsigned long len = vma_pages(mpnt);
81383+
81384+ if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
81385+ goto fail_nomem;
81386+ charge = len;
81387+ }
81388+ tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
81389+ if (!tmp)
81390+ goto fail_nomem;
81391+ *tmp = *mpnt;
81392+ tmp->vm_mm = mm;
81393+ INIT_LIST_HEAD(&tmp->anon_vma_chain);
81394+ retval = vma_dup_policy(mpnt, tmp);
81395+ if (retval)
81396+ goto fail_nomem_policy;
81397+ if (anon_vma_fork(tmp, mpnt))
81398+ goto fail_nomem_anon_vma_fork;
81399+ tmp->vm_flags &= ~VM_LOCKED;
81400+ tmp->vm_next = tmp->vm_prev = NULL;
81401+ tmp->vm_mirror = NULL;
81402+ file = tmp->vm_file;
81403+ if (file) {
81404+ struct inode *inode = file_inode(file);
81405+ struct address_space *mapping = file->f_mapping;
81406+
81407+ get_file(file);
81408+ if (tmp->vm_flags & VM_DENYWRITE)
81409+ atomic_dec(&inode->i_writecount);
81410+ mutex_lock(&mapping->i_mmap_mutex);
81411+ if (tmp->vm_flags & VM_SHARED)
81412+ mapping->i_mmap_writable++;
81413+ flush_dcache_mmap_lock(mapping);
81414+ /* insert tmp into the share list, just after mpnt */
81415+ if (unlikely(tmp->vm_flags & VM_NONLINEAR))
81416+ vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
81417+ else
81418+ vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
81419+ flush_dcache_mmap_unlock(mapping);
81420+ mutex_unlock(&mapping->i_mmap_mutex);
81421+ }
81422+
81423+ /*
81424+ * Clear hugetlb-related page reserves for children. This only
81425+ * affects MAP_PRIVATE mappings. Faults generated by the child
81426+ * are not guaranteed to succeed, even if read-only
81427+ */
81428+ if (is_vm_hugetlb_page(tmp))
81429+ reset_vma_resv_huge_pages(tmp);
81430+
81431+ return tmp;
81432+
81433+fail_nomem_anon_vma_fork:
81434+ mpol_put(vma_policy(tmp));
81435+fail_nomem_policy:
81436+ kmem_cache_free(vm_area_cachep, tmp);
81437+fail_nomem:
81438+ vm_unacct_memory(charge);
81439+ return NULL;
81440+}
81441+
81442+static __latent_entropy int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
81443 {
81444 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
81445 struct rb_node **rb_link, *rb_parent;
81446 int retval;
81447- unsigned long charge;
81448
81449 uprobe_start_dup_mmap();
81450 down_write(&oldmm->mmap_sem);
81451@@ -379,55 +447,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
81452
81453 prev = NULL;
81454 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
81455- struct file *file;
81456-
81457 if (mpnt->vm_flags & VM_DONTCOPY) {
81458 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
81459 -vma_pages(mpnt));
81460 continue;
81461 }
81462- charge = 0;
81463- if (mpnt->vm_flags & VM_ACCOUNT) {
81464- unsigned long len = vma_pages(mpnt);
81465-
81466- if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
81467- goto fail_nomem;
81468- charge = len;
81469- }
81470- tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
81471- if (!tmp)
81472- goto fail_nomem;
81473- *tmp = *mpnt;
81474- INIT_LIST_HEAD(&tmp->anon_vma_chain);
81475- retval = vma_dup_policy(mpnt, tmp);
81476- if (retval)
81477- goto fail_nomem_policy;
81478- tmp->vm_mm = mm;
81479- if (anon_vma_fork(tmp, mpnt))
81480- goto fail_nomem_anon_vma_fork;
81481- tmp->vm_flags &= ~VM_LOCKED;
81482- tmp->vm_next = tmp->vm_prev = NULL;
81483- file = tmp->vm_file;
81484- if (file) {
81485- struct inode *inode = file_inode(file);
81486- struct address_space *mapping = file->f_mapping;
81487-
81488- get_file(file);
81489- if (tmp->vm_flags & VM_DENYWRITE)
81490- atomic_dec(&inode->i_writecount);
81491- mutex_lock(&mapping->i_mmap_mutex);
81492- if (tmp->vm_flags & VM_SHARED)
81493- mapping->i_mmap_writable++;
81494- flush_dcache_mmap_lock(mapping);
81495- /* insert tmp into the share list, just after mpnt */
81496- if (unlikely(tmp->vm_flags & VM_NONLINEAR))
81497- vma_nonlinear_insert(tmp,
81498- &mapping->i_mmap_nonlinear);
81499- else
81500- vma_interval_tree_insert_after(tmp, mpnt,
81501- &mapping->i_mmap);
81502- flush_dcache_mmap_unlock(mapping);
81503- mutex_unlock(&mapping->i_mmap_mutex);
81504+ tmp = dup_vma(mm, oldmm, mpnt);
81505+ if (!tmp) {
81506+ retval = -ENOMEM;
81507+ goto out;
81508 }
81509
81510 /*
81511@@ -459,6 +487,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
81512 if (retval)
81513 goto out;
81514 }
81515+
81516+#ifdef CONFIG_PAX_SEGMEXEC
81517+ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
81518+ struct vm_area_struct *mpnt_m;
81519+
81520+ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
81521+ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
81522+
81523+ if (!mpnt->vm_mirror)
81524+ continue;
81525+
81526+ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
81527+ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
81528+ mpnt->vm_mirror = mpnt_m;
81529+ } else {
81530+ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
81531+ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
81532+ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
81533+ mpnt->vm_mirror->vm_mirror = mpnt;
81534+ }
81535+ }
81536+ BUG_ON(mpnt_m);
81537+ }
81538+#endif
81539+
81540 /* a new mm has just been created */
81541 arch_dup_mmap(oldmm, mm);
81542 retval = 0;
81543@@ -468,14 +521,6 @@ out:
81544 up_write(&oldmm->mmap_sem);
81545 uprobe_end_dup_mmap();
81546 return retval;
81547-fail_nomem_anon_vma_fork:
81548- mpol_put(vma_policy(tmp));
81549-fail_nomem_policy:
81550- kmem_cache_free(vm_area_cachep, tmp);
81551-fail_nomem:
81552- retval = -ENOMEM;
81553- vm_unacct_memory(charge);
81554- goto out;
81555 }
81556
81557 static inline int mm_alloc_pgd(struct mm_struct *mm)
81558@@ -688,8 +733,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
81559 return ERR_PTR(err);
81560
81561 mm = get_task_mm(task);
81562- if (mm && mm != current->mm &&
81563- !ptrace_may_access(task, mode)) {
81564+ if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
81565+ (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
81566 mmput(mm);
81567 mm = ERR_PTR(-EACCES);
81568 }
81569@@ -911,13 +956,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
81570 spin_unlock(&fs->lock);
81571 return -EAGAIN;
81572 }
81573- fs->users++;
81574+ atomic_inc(&fs->users);
81575 spin_unlock(&fs->lock);
81576 return 0;
81577 }
81578 tsk->fs = copy_fs_struct(fs);
81579 if (!tsk->fs)
81580 return -ENOMEM;
81581+ /* Carry through gr_chroot_dentry and is_chrooted instead
81582+ of recomputing it here. Already copied when the task struct
81583+ is duplicated. This allows pivot_root to not be treated as
81584+ a chroot
81585+ */
81586+ //gr_set_chroot_entries(tsk, &tsk->fs->root);
81587+
81588 return 0;
81589 }
81590
81591@@ -1128,7 +1180,7 @@ init_task_pid(struct task_struct *task, enum pid_type type, struct pid *pid)
81592 * parts of the process environment (as per the clone
81593 * flags). The actual kick-off is left to the caller.
81594 */
81595-static struct task_struct *copy_process(unsigned long clone_flags,
81596+static __latent_entropy struct task_struct *copy_process(unsigned long clone_flags,
81597 unsigned long stack_start,
81598 unsigned long stack_size,
81599 int __user *child_tidptr,
81600@@ -1200,6 +1252,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
81601 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
81602 #endif
81603 retval = -EAGAIN;
81604+
81605+ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
81606+
81607 if (atomic_read(&p->real_cred->user->processes) >=
81608 task_rlimit(p, RLIMIT_NPROC)) {
81609 if (p->real_cred->user != INIT_USER &&
81610@@ -1449,6 +1504,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
81611 goto bad_fork_free_pid;
81612 }
81613
81614+ /* synchronizes with gr_set_acls()
81615+ we need to call this past the point of no return for fork()
81616+ */
81617+ gr_copy_label(p);
81618+
81619 if (likely(p->pid)) {
81620 ptrace_init_task(p, (clone_flags & CLONE_PTRACE) || trace);
81621
81622@@ -1534,6 +1594,8 @@ bad_fork_cleanup_count:
81623 bad_fork_free:
81624 free_task(p);
81625 fork_out:
81626+ gr_log_forkfail(retval);
81627+
81628 return ERR_PTR(retval);
81629 }
81630
81631@@ -1595,6 +1657,7 @@ long do_fork(unsigned long clone_flags,
81632
81633 p = copy_process(clone_flags, stack_start, stack_size,
81634 child_tidptr, NULL, trace);
81635+ add_latent_entropy();
81636 /*
81637 * Do this prior waking up the new thread - the thread pointer
81638 * might get invalid after that point, if the thread exits quickly.
81639@@ -1609,6 +1672,8 @@ long do_fork(unsigned long clone_flags,
81640 if (clone_flags & CLONE_PARENT_SETTID)
81641 put_user(nr, parent_tidptr);
81642
81643+ gr_handle_brute_check();
81644+
81645 if (clone_flags & CLONE_VFORK) {
81646 p->vfork_done = &vfork;
81647 init_completion(&vfork);
81648@@ -1725,7 +1790,7 @@ void __init proc_caches_init(void)
81649 mm_cachep = kmem_cache_create("mm_struct",
81650 sizeof(struct mm_struct), ARCH_MIN_MMSTRUCT_ALIGN,
81651 SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_NOTRACK, NULL);
81652- vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC);
81653+ vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC | SLAB_NO_SANITIZE);
81654 mmap_init();
81655 nsproxy_cache_init();
81656 }
81657@@ -1765,7 +1830,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
81658 return 0;
81659
81660 /* don't need lock here; in the worst case we'll do useless copy */
81661- if (fs->users == 1)
81662+ if (atomic_read(&fs->users) == 1)
81663 return 0;
81664
81665 *new_fsp = copy_fs_struct(fs);
81666@@ -1872,7 +1937,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
81667 fs = current->fs;
81668 spin_lock(&fs->lock);
81669 current->fs = new_fs;
81670- if (--fs->users)
81671+ gr_set_chroot_entries(current, &current->fs->root);
81672+ if (atomic_dec_return(&fs->users))
81673 new_fs = NULL;
81674 else
81675 new_fs = fs;
81676diff --git a/kernel/futex.c b/kernel/futex.c
81677index c3a1a55..e32b4a98 100644
81678--- a/kernel/futex.c
81679+++ b/kernel/futex.c
81680@@ -54,6 +54,7 @@
81681 #include <linux/mount.h>
81682 #include <linux/pagemap.h>
81683 #include <linux/syscalls.h>
81684+#include <linux/ptrace.h>
81685 #include <linux/signal.h>
81686 #include <linux/export.h>
81687 #include <linux/magic.h>
81688@@ -243,6 +244,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
81689 struct page *page, *page_head;
81690 int err, ro = 0;
81691
81692+#ifdef CONFIG_PAX_SEGMEXEC
81693+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
81694+ return -EFAULT;
81695+#endif
81696+
81697 /*
81698 * The futex address must be "naturally" aligned.
81699 */
81700@@ -441,7 +447,7 @@ static int cmpxchg_futex_value_locked(u32 *curval, u32 __user *uaddr,
81701
81702 static int get_futex_value_locked(u32 *dest, u32 __user *from)
81703 {
81704- int ret;
81705+ unsigned long ret;
81706
81707 pagefault_disable();
81708 ret = __copy_from_user_inatomic(dest, from, sizeof(u32));
81709@@ -2734,6 +2740,7 @@ static int __init futex_init(void)
81710 {
81711 u32 curval;
81712 int i;
81713+ mm_segment_t oldfs;
81714
81715 /*
81716 * This will fail and we want it. Some arch implementations do
81717@@ -2745,8 +2752,11 @@ static int __init futex_init(void)
81718 * implementation, the non-functional ones will return
81719 * -ENOSYS.
81720 */
81721+ oldfs = get_fs();
81722+ set_fs(USER_DS);
81723 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
81724 futex_cmpxchg_enabled = 1;
81725+ set_fs(oldfs);
81726
81727 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
81728 plist_head_init(&futex_queues[i].chain);
81729diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
81730index f9f44fd..29885e4 100644
81731--- a/kernel/futex_compat.c
81732+++ b/kernel/futex_compat.c
81733@@ -32,7 +32,7 @@ fetch_robust_entry(compat_uptr_t *uentry, struct robust_list __user **entry,
81734 return 0;
81735 }
81736
81737-static void __user *futex_uaddr(struct robust_list __user *entry,
81738+static void __user __intentional_overflow(-1) *futex_uaddr(struct robust_list __user *entry,
81739 compat_long_t futex_offset)
81740 {
81741 compat_uptr_t base = ptr_to_compat(entry);
81742diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
81743index 9b22d03..6295b62 100644
81744--- a/kernel/gcov/base.c
81745+++ b/kernel/gcov/base.c
81746@@ -102,11 +102,6 @@ void gcov_enable_events(void)
81747 }
81748
81749 #ifdef CONFIG_MODULES
81750-static inline int within(void *addr, void *start, unsigned long size)
81751-{
81752- return ((addr >= start) && (addr < start + size));
81753-}
81754-
81755 /* Update list and generate events when modules are unloaded. */
81756 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
81757 void *data)
81758@@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
81759 prev = NULL;
81760 /* Remove entries located in module from linked list. */
81761 for (info = gcov_info_head; info; info = info->next) {
81762- if (within(info, mod->module_core, mod->core_size)) {
81763+ if (within_module_core_rw((unsigned long)info, mod)) {
81764 if (prev)
81765 prev->next = info->next;
81766 else
81767diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
81768index 383319b..56ebb13 100644
81769--- a/kernel/hrtimer.c
81770+++ b/kernel/hrtimer.c
81771@@ -1438,7 +1438,7 @@ void hrtimer_peek_ahead_timers(void)
81772 local_irq_restore(flags);
81773 }
81774
81775-static void run_hrtimer_softirq(struct softirq_action *h)
81776+static __latent_entropy void run_hrtimer_softirq(void)
81777 {
81778 hrtimer_peek_ahead_timers();
81779 }
81780diff --git a/kernel/irq_work.c b/kernel/irq_work.c
81781index 55fcce6..0e4cf34 100644
81782--- a/kernel/irq_work.c
81783+++ b/kernel/irq_work.c
81784@@ -189,12 +189,13 @@ static int irq_work_cpu_notify(struct notifier_block *self,
81785 return NOTIFY_OK;
81786 }
81787
81788-static struct notifier_block cpu_notify;
81789+static struct notifier_block cpu_notify = {
81790+ .notifier_call = irq_work_cpu_notify,
81791+ .priority = 0,
81792+};
81793
81794 static __init int irq_work_init_cpu_notifier(void)
81795 {
81796- cpu_notify.notifier_call = irq_work_cpu_notify;
81797- cpu_notify.priority = 0;
81798 register_cpu_notifier(&cpu_notify);
81799 return 0;
81800 }
81801diff --git a/kernel/jump_label.c b/kernel/jump_label.c
81802index 297a924..7290070 100644
81803--- a/kernel/jump_label.c
81804+++ b/kernel/jump_label.c
81805@@ -14,6 +14,7 @@
81806 #include <linux/err.h>
81807 #include <linux/static_key.h>
81808 #include <linux/jump_label_ratelimit.h>
81809+#include <linux/mm.h>
81810
81811 #ifdef HAVE_JUMP_LABEL
81812
81813@@ -51,7 +52,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
81814
81815 size = (((unsigned long)stop - (unsigned long)start)
81816 / sizeof(struct jump_entry));
81817+ pax_open_kernel();
81818 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
81819+ pax_close_kernel();
81820 }
81821
81822 static void jump_label_update(struct static_key *key, int enable);
81823@@ -358,10 +361,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
81824 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
81825 struct jump_entry *iter;
81826
81827+ pax_open_kernel();
81828 for (iter = iter_start; iter < iter_stop; iter++) {
81829 if (within_module_init(iter->code, mod))
81830 iter->code = 0;
81831 }
81832+ pax_close_kernel();
81833 }
81834
81835 static int
81836diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
81837index 3127ad5..159d880 100644
81838--- a/kernel/kallsyms.c
81839+++ b/kernel/kallsyms.c
81840@@ -11,6 +11,9 @@
81841 * Changed the compression method from stem compression to "table lookup"
81842 * compression (see scripts/kallsyms.c for a more complete description)
81843 */
81844+#ifdef CONFIG_GRKERNSEC_HIDESYM
81845+#define __INCLUDED_BY_HIDESYM 1
81846+#endif
81847 #include <linux/kallsyms.h>
81848 #include <linux/module.h>
81849 #include <linux/init.h>
81850@@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
81851
81852 static inline int is_kernel_inittext(unsigned long addr)
81853 {
81854+ if (system_state != SYSTEM_BOOTING)
81855+ return 0;
81856+
81857 if (addr >= (unsigned long)_sinittext
81858 && addr <= (unsigned long)_einittext)
81859 return 1;
81860 return 0;
81861 }
81862
81863+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
81864+#ifdef CONFIG_MODULES
81865+static inline int is_module_text(unsigned long addr)
81866+{
81867+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
81868+ return 1;
81869+
81870+ addr = ktla_ktva(addr);
81871+ return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
81872+}
81873+#else
81874+static inline int is_module_text(unsigned long addr)
81875+{
81876+ return 0;
81877+}
81878+#endif
81879+#endif
81880+
81881 static inline int is_kernel_text(unsigned long addr)
81882 {
81883 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
81884@@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
81885
81886 static inline int is_kernel(unsigned long addr)
81887 {
81888+
81889+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
81890+ if (is_kernel_text(addr) || is_kernel_inittext(addr))
81891+ return 1;
81892+
81893+ if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
81894+#else
81895 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
81896+#endif
81897+
81898 return 1;
81899 return in_gate_area_no_mm(addr);
81900 }
81901
81902 static int is_ksym_addr(unsigned long addr)
81903 {
81904+
81905+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
81906+ if (is_module_text(addr))
81907+ return 0;
81908+#endif
81909+
81910 if (all_var)
81911 return is_kernel(addr);
81912
81913@@ -480,7 +519,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
81914
81915 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
81916 {
81917- iter->name[0] = '\0';
81918 iter->nameoff = get_symbol_offset(new_pos);
81919 iter->pos = new_pos;
81920 }
81921@@ -528,6 +566,11 @@ static int s_show(struct seq_file *m, void *p)
81922 {
81923 struct kallsym_iter *iter = m->private;
81924
81925+#ifdef CONFIG_GRKERNSEC_HIDESYM
81926+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID))
81927+ return 0;
81928+#endif
81929+
81930 /* Some debugging symbols have no name. Ignore them. */
81931 if (!iter->name[0])
81932 return 0;
81933@@ -541,6 +584,7 @@ static int s_show(struct seq_file *m, void *p)
81934 */
81935 type = iter->exported ? toupper(iter->type) :
81936 tolower(iter->type);
81937+
81938 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
81939 type, iter->name, iter->module_name);
81940 } else
81941@@ -566,7 +610,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
81942 struct kallsym_iter *iter;
81943 int ret;
81944
81945- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
81946+ iter = kzalloc(sizeof(*iter), GFP_KERNEL);
81947 if (!iter)
81948 return -ENOMEM;
81949 reset_iter(iter, 0);
81950diff --git a/kernel/kcmp.c b/kernel/kcmp.c
81951index e30ac0f..3528cac 100644
81952--- a/kernel/kcmp.c
81953+++ b/kernel/kcmp.c
81954@@ -99,6 +99,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
81955 struct task_struct *task1, *task2;
81956 int ret;
81957
81958+#ifdef CONFIG_GRKERNSEC
81959+ return -ENOSYS;
81960+#endif
81961+
81962 rcu_read_lock();
81963
81964 /*
81965diff --git a/kernel/kexec.c b/kernel/kexec.c
81966index 2a74f30..d139351 100644
81967--- a/kernel/kexec.c
81968+++ b/kernel/kexec.c
81969@@ -1041,7 +1041,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
81970 unsigned long flags)
81971 {
81972 struct compat_kexec_segment in;
81973- struct kexec_segment out, __user *ksegments;
81974+ struct kexec_segment out;
81975+ struct kexec_segment __user *ksegments;
81976 unsigned long i, result;
81977
81978 /* Don't allow clients that don't understand the native
81979diff --git a/kernel/kmod.c b/kernel/kmod.c
81980index b086006..56b1feb 100644
81981--- a/kernel/kmod.c
81982+++ b/kernel/kmod.c
81983@@ -75,7 +75,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
81984 kfree(info->argv);
81985 }
81986
81987-static int call_modprobe(char *module_name, int wait)
81988+static int call_modprobe(char *module_name, char *module_param, int wait)
81989 {
81990 struct subprocess_info *info;
81991 static char *envp[] = {
81992@@ -85,7 +85,7 @@ static int call_modprobe(char *module_name, int wait)
81993 NULL
81994 };
81995
81996- char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
81997+ char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
81998 if (!argv)
81999 goto out;
82000
82001@@ -97,7 +97,8 @@ static int call_modprobe(char *module_name, int wait)
82002 argv[1] = "-q";
82003 argv[2] = "--";
82004 argv[3] = module_name; /* check free_modprobe_argv() */
82005- argv[4] = NULL;
82006+ argv[4] = module_param;
82007+ argv[5] = NULL;
82008
82009 info = call_usermodehelper_setup(modprobe_path, argv, envp, GFP_KERNEL,
82010 NULL, free_modprobe_argv, NULL);
82011@@ -129,9 +130,8 @@ out:
82012 * If module auto-loading support is disabled then this function
82013 * becomes a no-operation.
82014 */
82015-int __request_module(bool wait, const char *fmt, ...)
82016+static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
82017 {
82018- va_list args;
82019 char module_name[MODULE_NAME_LEN];
82020 unsigned int max_modprobes;
82021 int ret;
82022@@ -150,9 +150,7 @@ int __request_module(bool wait, const char *fmt, ...)
82023 if (!modprobe_path[0])
82024 return 0;
82025
82026- va_start(args, fmt);
82027- ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
82028- va_end(args);
82029+ ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
82030 if (ret >= MODULE_NAME_LEN)
82031 return -ENAMETOOLONG;
82032
82033@@ -160,6 +158,20 @@ int __request_module(bool wait, const char *fmt, ...)
82034 if (ret)
82035 return ret;
82036
82037+#ifdef CONFIG_GRKERNSEC_MODHARDEN
82038+ if (uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
82039+ /* hack to workaround consolekit/udisks stupidity */
82040+ read_lock(&tasklist_lock);
82041+ if (!strcmp(current->comm, "mount") &&
82042+ current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
82043+ read_unlock(&tasklist_lock);
82044+ printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
82045+ return -EPERM;
82046+ }
82047+ read_unlock(&tasklist_lock);
82048+ }
82049+#endif
82050+
82051 /* If modprobe needs a service that is in a module, we get a recursive
82052 * loop. Limit the number of running kmod threads to max_threads/2 or
82053 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
82054@@ -188,11 +200,52 @@ int __request_module(bool wait, const char *fmt, ...)
82055
82056 trace_module_request(module_name, wait, _RET_IP_);
82057
82058- ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
82059+ ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
82060
82061 atomic_dec(&kmod_concurrent);
82062 return ret;
82063 }
82064+
82065+int ___request_module(bool wait, char *module_param, const char *fmt, ...)
82066+{
82067+ va_list args;
82068+ int ret;
82069+
82070+ va_start(args, fmt);
82071+ ret = ____request_module(wait, module_param, fmt, args);
82072+ va_end(args);
82073+
82074+ return ret;
82075+}
82076+
82077+int __request_module(bool wait, const char *fmt, ...)
82078+{
82079+ va_list args;
82080+ int ret;
82081+
82082+#ifdef CONFIG_GRKERNSEC_MODHARDEN
82083+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
82084+ char module_param[MODULE_NAME_LEN];
82085+
82086+ memset(module_param, 0, sizeof(module_param));
82087+
82088+ snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", GR_GLOBAL_UID(current_uid()));
82089+
82090+ va_start(args, fmt);
82091+ ret = ____request_module(wait, module_param, fmt, args);
82092+ va_end(args);
82093+
82094+ return ret;
82095+ }
82096+#endif
82097+
82098+ va_start(args, fmt);
82099+ ret = ____request_module(wait, NULL, fmt, args);
82100+ va_end(args);
82101+
82102+ return ret;
82103+}
82104+
82105 EXPORT_SYMBOL(__request_module);
82106 #endif /* CONFIG_MODULES */
82107
82108@@ -218,6 +271,18 @@ static int ____call_usermodehelper(void *data)
82109 */
82110 set_user_nice(current, 0);
82111
82112+#ifdef CONFIG_GRKERNSEC
82113+ /* this is race-free as far as userland is concerned as we copied
82114+ out the path to be used prior to this point and are now operating
82115+ on that copy
82116+ */
82117+ if ((strncmp(sub_info->path, "/sbin/", 6) && strncmp(sub_info->path, "/usr/lib/systemd/", 17)) || strstr(sub_info->path, "..")) {
82118+ printk(KERN_ALERT "grsec: denied exec of usermode helper binary %.950s located outside of /sbin and /usr/lib/systemd\n", sub_info->path);
82119+ retval = -EPERM;
82120+ goto fail;
82121+ }
82122+#endif
82123+
82124 retval = -ENOMEM;
82125 new = prepare_kernel_cred(current);
82126 if (!new)
82127@@ -260,6 +325,10 @@ static int call_helper(void *data)
82128
82129 static void call_usermodehelper_freeinfo(struct subprocess_info *info)
82130 {
82131+#ifdef CONFIG_GRKERNSEC
82132+ kfree(info->path);
82133+ info->path = info->origpath;
82134+#endif
82135 if (info->cleanup)
82136 (*info->cleanup)(info);
82137 kfree(info);
82138@@ -303,7 +372,7 @@ static int wait_for_helper(void *data)
82139 *
82140 * Thus the __user pointer cast is valid here.
82141 */
82142- sys_wait4(pid, (int __user *)&ret, 0, NULL);
82143+ sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
82144
82145 /*
82146 * If ret is 0, either ____call_usermodehelper failed and the
82147@@ -542,7 +611,12 @@ struct subprocess_info *call_usermodehelper_setup(char *path, char **argv,
82148 goto out;
82149
82150 INIT_WORK(&sub_info->work, __call_usermodehelper);
82151+#ifdef CONFIG_GRKERNSEC
82152+ sub_info->origpath = path;
82153+ sub_info->path = kstrdup(path, gfp_mask);
82154+#else
82155 sub_info->path = path;
82156+#endif
82157 sub_info->argv = argv;
82158 sub_info->envp = envp;
82159
82160@@ -650,7 +724,7 @@ EXPORT_SYMBOL(call_usermodehelper);
82161 static int proc_cap_handler(struct ctl_table *table, int write,
82162 void __user *buffer, size_t *lenp, loff_t *ppos)
82163 {
82164- struct ctl_table t;
82165+ ctl_table_no_const t;
82166 unsigned long cap_array[_KERNEL_CAPABILITY_U32S];
82167 kernel_cap_t new_cap;
82168 int err, i;
82169diff --git a/kernel/kprobes.c b/kernel/kprobes.c
82170index a0d367a..11c18b6 100644
82171--- a/kernel/kprobes.c
82172+++ b/kernel/kprobes.c
82173@@ -31,6 +31,9 @@
82174 * <jkenisto@us.ibm.com> and Prasanna S Panchamukhi
82175 * <prasanna@in.ibm.com> added function-return probes.
82176 */
82177+#ifdef CONFIG_GRKERNSEC_HIDESYM
82178+#define __INCLUDED_BY_HIDESYM 1
82179+#endif
82180 #include <linux/kprobes.h>
82181 #include <linux/hash.h>
82182 #include <linux/init.h>
82183@@ -135,12 +138,12 @@ enum kprobe_slot_state {
82184
82185 static void *alloc_insn_page(void)
82186 {
82187- return module_alloc(PAGE_SIZE);
82188+ return module_alloc_exec(PAGE_SIZE);
82189 }
82190
82191 static void free_insn_page(void *page)
82192 {
82193- module_free(NULL, page);
82194+ module_free_exec(NULL, page);
82195 }
82196
82197 struct kprobe_insn_cache kprobe_insn_slots = {
82198@@ -2066,7 +2069,7 @@ static int __init init_kprobes(void)
82199 {
82200 int i, err = 0;
82201 unsigned long offset = 0, size = 0;
82202- char *modname, namebuf[128];
82203+ char *modname, namebuf[KSYM_NAME_LEN];
82204 const char *symbol_name;
82205 void *addr;
82206 struct kprobe_blackpoint *kb;
82207@@ -2151,11 +2154,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
82208 kprobe_type = "k";
82209
82210 if (sym)
82211- seq_printf(pi, "%p %s %s+0x%x %s ",
82212+ seq_printf(pi, "%pK %s %s+0x%x %s ",
82213 p->addr, kprobe_type, sym, offset,
82214 (modname ? modname : " "));
82215 else
82216- seq_printf(pi, "%p %s %p ",
82217+ seq_printf(pi, "%pK %s %pK ",
82218 p->addr, kprobe_type, p->addr);
82219
82220 if (!pp)
82221@@ -2192,7 +2195,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
82222 const char *sym = NULL;
82223 unsigned int i = *(loff_t *) v;
82224 unsigned long offset = 0;
82225- char *modname, namebuf[128];
82226+ char *modname, namebuf[KSYM_NAME_LEN];
82227
82228 head = &kprobe_table[i];
82229 preempt_disable();
82230diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
82231index 9659d38..bffd520 100644
82232--- a/kernel/ksysfs.c
82233+++ b/kernel/ksysfs.c
82234@@ -46,6 +46,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
82235 {
82236 if (count+1 > UEVENT_HELPER_PATH_LEN)
82237 return -ENOENT;
82238+ if (!capable(CAP_SYS_ADMIN))
82239+ return -EPERM;
82240 memcpy(uevent_helper, buf, count);
82241 uevent_helper[count] = '\0';
82242 if (count && uevent_helper[count-1] == '\n')
82243@@ -172,7 +174,7 @@ static ssize_t notes_read(struct file *filp, struct kobject *kobj,
82244 return count;
82245 }
82246
82247-static struct bin_attribute notes_attr = {
82248+static bin_attribute_no_const notes_attr __read_only = {
82249 .attr = {
82250 .name = "notes",
82251 .mode = S_IRUGO,
82252diff --git a/kernel/lockdep.c b/kernel/lockdep.c
82253index e16c45b..6f49c48 100644
82254--- a/kernel/lockdep.c
82255+++ b/kernel/lockdep.c
82256@@ -596,6 +596,10 @@ static int static_obj(void *obj)
82257 end = (unsigned long) &_end,
82258 addr = (unsigned long) obj;
82259
82260+#ifdef CONFIG_PAX_KERNEXEC
82261+ start = ktla_ktva(start);
82262+#endif
82263+
82264 /*
82265 * static variable?
82266 */
82267@@ -736,6 +740,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
82268 if (!static_obj(lock->key)) {
82269 debug_locks_off();
82270 printk("INFO: trying to register non-static key.\n");
82271+ printk("lock:%pS key:%pS.\n", lock, lock->key);
82272 printk("the code is fine but needs lockdep annotation.\n");
82273 printk("turning off the locking correctness validator.\n");
82274 dump_stack();
82275@@ -3080,7 +3085,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
82276 if (!class)
82277 return 0;
82278 }
82279- atomic_inc((atomic_t *)&class->ops);
82280+ atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
82281 if (very_verbose(class)) {
82282 printk("\nacquire class [%p] %s", class->key, class->name);
82283 if (class->name_version > 1)
82284diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
82285index b2c71c5..7b88d63 100644
82286--- a/kernel/lockdep_proc.c
82287+++ b/kernel/lockdep_proc.c
82288@@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
82289 return 0;
82290 }
82291
82292- seq_printf(m, "%p", class->key);
82293+ seq_printf(m, "%pK", class->key);
82294 #ifdef CONFIG_DEBUG_LOCKDEP
82295 seq_printf(m, " OPS:%8ld", class->ops);
82296 #endif
82297@@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
82298
82299 list_for_each_entry(entry, &class->locks_after, entry) {
82300 if (entry->distance == 1) {
82301- seq_printf(m, " -> [%p] ", entry->class->key);
82302+ seq_printf(m, " -> [%pK] ", entry->class->key);
82303 print_name(m, entry->class);
82304 seq_puts(m, "\n");
82305 }
82306@@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
82307 if (!class->key)
82308 continue;
82309
82310- seq_printf(m, "[%p] ", class->key);
82311+ seq_printf(m, "[%pK] ", class->key);
82312 print_name(m, class);
82313 seq_puts(m, "\n");
82314 }
82315@@ -495,7 +495,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
82316 if (!i)
82317 seq_line(m, '-', 40-namelen, namelen);
82318
82319- snprintf(ip, sizeof(ip), "[<%p>]",
82320+ snprintf(ip, sizeof(ip), "[<%pK>]",
82321 (void *)class->contention_point[i]);
82322 seq_printf(m, "%40s %14lu %29s %pS\n",
82323 name, stats->contention_point[i],
82324@@ -510,7 +510,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
82325 if (!i)
82326 seq_line(m, '-', 40-namelen, namelen);
82327
82328- snprintf(ip, sizeof(ip), "[<%p>]",
82329+ snprintf(ip, sizeof(ip), "[<%pK>]",
82330 (void *)class->contending_point[i]);
82331 seq_printf(m, "%40s %14lu %29s %pS\n",
82332 name, stats->contending_point[i],
82333diff --git a/kernel/module.c b/kernel/module.c
82334index dc58274..3ddfa55 100644
82335--- a/kernel/module.c
82336+++ b/kernel/module.c
82337@@ -61,6 +61,7 @@
82338 #include <linux/pfn.h>
82339 #include <linux/bsearch.h>
82340 #include <linux/fips.h>
82341+#include <linux/grsecurity.h>
82342 #include <uapi/linux/module.h>
82343 #include "module-internal.h"
82344
82345@@ -157,7 +158,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
82346
82347 /* Bounds of module allocation, for speeding __module_address.
82348 * Protected by module_mutex. */
82349-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
82350+static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
82351+static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
82352
82353 int register_module_notifier(struct notifier_block * nb)
82354 {
82355@@ -324,7 +326,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
82356 return true;
82357
82358 list_for_each_entry_rcu(mod, &modules, list) {
82359- struct symsearch arr[] = {
82360+ struct symsearch modarr[] = {
82361 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
82362 NOT_GPL_ONLY, false },
82363 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
82364@@ -349,7 +351,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
82365 if (mod->state == MODULE_STATE_UNFORMED)
82366 continue;
82367
82368- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
82369+ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
82370 return true;
82371 }
82372 return false;
82373@@ -491,7 +493,7 @@ static int percpu_modalloc(struct module *mod, struct load_info *info)
82374 if (!pcpusec->sh_size)
82375 return 0;
82376
82377- if (align > PAGE_SIZE) {
82378+ if (align-1 >= PAGE_SIZE) {
82379 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
82380 mod->name, align, PAGE_SIZE);
82381 align = PAGE_SIZE;
82382@@ -1097,7 +1099,7 @@ struct module_attribute module_uevent =
82383 static ssize_t show_coresize(struct module_attribute *mattr,
82384 struct module_kobject *mk, char *buffer)
82385 {
82386- return sprintf(buffer, "%u\n", mk->mod->core_size);
82387+ return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
82388 }
82389
82390 static struct module_attribute modinfo_coresize =
82391@@ -1106,7 +1108,7 @@ static struct module_attribute modinfo_coresize =
82392 static ssize_t show_initsize(struct module_attribute *mattr,
82393 struct module_kobject *mk, char *buffer)
82394 {
82395- return sprintf(buffer, "%u\n", mk->mod->init_size);
82396+ return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
82397 }
82398
82399 static struct module_attribute modinfo_initsize =
82400@@ -1321,7 +1323,7 @@ resolve_symbol_wait(struct module *mod,
82401 */
82402 #ifdef CONFIG_SYSFS
82403
82404-#ifdef CONFIG_KALLSYMS
82405+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
82406 static inline bool sect_empty(const Elf_Shdr *sect)
82407 {
82408 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
82409@@ -1461,7 +1463,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
82410 {
82411 unsigned int notes, loaded, i;
82412 struct module_notes_attrs *notes_attrs;
82413- struct bin_attribute *nattr;
82414+ bin_attribute_no_const *nattr;
82415
82416 /* failed to create section attributes, so can't create notes */
82417 if (!mod->sect_attrs)
82418@@ -1573,7 +1575,7 @@ static void del_usage_links(struct module *mod)
82419 static int module_add_modinfo_attrs(struct module *mod)
82420 {
82421 struct module_attribute *attr;
82422- struct module_attribute *temp_attr;
82423+ module_attribute_no_const *temp_attr;
82424 int error = 0;
82425 int i;
82426
82427@@ -1795,21 +1797,21 @@ static void set_section_ro_nx(void *base,
82428
82429 static void unset_module_core_ro_nx(struct module *mod)
82430 {
82431- set_page_attributes(mod->module_core + mod->core_text_size,
82432- mod->module_core + mod->core_size,
82433+ set_page_attributes(mod->module_core_rw,
82434+ mod->module_core_rw + mod->core_size_rw,
82435 set_memory_x);
82436- set_page_attributes(mod->module_core,
82437- mod->module_core + mod->core_ro_size,
82438+ set_page_attributes(mod->module_core_rx,
82439+ mod->module_core_rx + mod->core_size_rx,
82440 set_memory_rw);
82441 }
82442
82443 static void unset_module_init_ro_nx(struct module *mod)
82444 {
82445- set_page_attributes(mod->module_init + mod->init_text_size,
82446- mod->module_init + mod->init_size,
82447+ set_page_attributes(mod->module_init_rw,
82448+ mod->module_init_rw + mod->init_size_rw,
82449 set_memory_x);
82450- set_page_attributes(mod->module_init,
82451- mod->module_init + mod->init_ro_size,
82452+ set_page_attributes(mod->module_init_rx,
82453+ mod->module_init_rx + mod->init_size_rx,
82454 set_memory_rw);
82455 }
82456
82457@@ -1822,14 +1824,14 @@ void set_all_modules_text_rw(void)
82458 list_for_each_entry_rcu(mod, &modules, list) {
82459 if (mod->state == MODULE_STATE_UNFORMED)
82460 continue;
82461- if ((mod->module_core) && (mod->core_text_size)) {
82462- set_page_attributes(mod->module_core,
82463- mod->module_core + mod->core_text_size,
82464+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
82465+ set_page_attributes(mod->module_core_rx,
82466+ mod->module_core_rx + mod->core_size_rx,
82467 set_memory_rw);
82468 }
82469- if ((mod->module_init) && (mod->init_text_size)) {
82470- set_page_attributes(mod->module_init,
82471- mod->module_init + mod->init_text_size,
82472+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
82473+ set_page_attributes(mod->module_init_rx,
82474+ mod->module_init_rx + mod->init_size_rx,
82475 set_memory_rw);
82476 }
82477 }
82478@@ -1845,14 +1847,14 @@ void set_all_modules_text_ro(void)
82479 list_for_each_entry_rcu(mod, &modules, list) {
82480 if (mod->state == MODULE_STATE_UNFORMED)
82481 continue;
82482- if ((mod->module_core) && (mod->core_text_size)) {
82483- set_page_attributes(mod->module_core,
82484- mod->module_core + mod->core_text_size,
82485+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
82486+ set_page_attributes(mod->module_core_rx,
82487+ mod->module_core_rx + mod->core_size_rx,
82488 set_memory_ro);
82489 }
82490- if ((mod->module_init) && (mod->init_text_size)) {
82491- set_page_attributes(mod->module_init,
82492- mod->module_init + mod->init_text_size,
82493+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
82494+ set_page_attributes(mod->module_init_rx,
82495+ mod->module_init_rx + mod->init_size_rx,
82496 set_memory_ro);
82497 }
82498 }
82499@@ -1903,16 +1905,19 @@ static void free_module(struct module *mod)
82500
82501 /* This may be NULL, but that's OK */
82502 unset_module_init_ro_nx(mod);
82503- module_free(mod, mod->module_init);
82504+ module_free(mod, mod->module_init_rw);
82505+ module_free_exec(mod, mod->module_init_rx);
82506 kfree(mod->args);
82507 percpu_modfree(mod);
82508
82509 /* Free lock-classes: */
82510- lockdep_free_key_range(mod->module_core, mod->core_size);
82511+ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
82512+ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
82513
82514 /* Finally, free the core (containing the module structure) */
82515 unset_module_core_ro_nx(mod);
82516- module_free(mod, mod->module_core);
82517+ module_free_exec(mod, mod->module_core_rx);
82518+ module_free(mod, mod->module_core_rw);
82519
82520 #ifdef CONFIG_MPU
82521 update_protections(current->mm);
82522@@ -1982,9 +1987,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
82523 int ret = 0;
82524 const struct kernel_symbol *ksym;
82525
82526+#ifdef CONFIG_GRKERNSEC_MODHARDEN
82527+ int is_fs_load = 0;
82528+ int register_filesystem_found = 0;
82529+ char *p;
82530+
82531+ p = strstr(mod->args, "grsec_modharden_fs");
82532+ if (p) {
82533+ char *endptr = p + sizeof("grsec_modharden_fs") - 1;
82534+ /* copy \0 as well */
82535+ memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
82536+ is_fs_load = 1;
82537+ }
82538+#endif
82539+
82540 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
82541 const char *name = info->strtab + sym[i].st_name;
82542
82543+#ifdef CONFIG_GRKERNSEC_MODHARDEN
82544+ /* it's a real shame this will never get ripped and copied
82545+ upstream! ;(
82546+ */
82547+ if (is_fs_load && !strcmp(name, "register_filesystem"))
82548+ register_filesystem_found = 1;
82549+#endif
82550+
82551 switch (sym[i].st_shndx) {
82552 case SHN_COMMON:
82553 /* We compiled with -fno-common. These are not
82554@@ -2005,7 +2032,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
82555 ksym = resolve_symbol_wait(mod, info, name);
82556 /* Ok if resolved. */
82557 if (ksym && !IS_ERR(ksym)) {
82558+ pax_open_kernel();
82559 sym[i].st_value = ksym->value;
82560+ pax_close_kernel();
82561 break;
82562 }
82563
82564@@ -2024,11 +2053,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
82565 secbase = (unsigned long)mod_percpu(mod);
82566 else
82567 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
82568+ pax_open_kernel();
82569 sym[i].st_value += secbase;
82570+ pax_close_kernel();
82571 break;
82572 }
82573 }
82574
82575+#ifdef CONFIG_GRKERNSEC_MODHARDEN
82576+ if (is_fs_load && !register_filesystem_found) {
82577+ printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
82578+ ret = -EPERM;
82579+ }
82580+#endif
82581+
82582 return ret;
82583 }
82584
82585@@ -2112,22 +2150,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
82586 || s->sh_entsize != ~0UL
82587 || strstarts(sname, ".init"))
82588 continue;
82589- s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
82590+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
82591+ s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
82592+ else
82593+ s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
82594 pr_debug("\t%s\n", sname);
82595 }
82596- switch (m) {
82597- case 0: /* executable */
82598- mod->core_size = debug_align(mod->core_size);
82599- mod->core_text_size = mod->core_size;
82600- break;
82601- case 1: /* RO: text and ro-data */
82602- mod->core_size = debug_align(mod->core_size);
82603- mod->core_ro_size = mod->core_size;
82604- break;
82605- case 3: /* whole core */
82606- mod->core_size = debug_align(mod->core_size);
82607- break;
82608- }
82609 }
82610
82611 pr_debug("Init section allocation order:\n");
82612@@ -2141,23 +2169,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
82613 || s->sh_entsize != ~0UL
82614 || !strstarts(sname, ".init"))
82615 continue;
82616- s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
82617- | INIT_OFFSET_MASK);
82618+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
82619+ s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
82620+ else
82621+ s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
82622+ s->sh_entsize |= INIT_OFFSET_MASK;
82623 pr_debug("\t%s\n", sname);
82624 }
82625- switch (m) {
82626- case 0: /* executable */
82627- mod->init_size = debug_align(mod->init_size);
82628- mod->init_text_size = mod->init_size;
82629- break;
82630- case 1: /* RO: text and ro-data */
82631- mod->init_size = debug_align(mod->init_size);
82632- mod->init_ro_size = mod->init_size;
82633- break;
82634- case 3: /* whole init */
82635- mod->init_size = debug_align(mod->init_size);
82636- break;
82637- }
82638 }
82639 }
82640
82641@@ -2330,7 +2348,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
82642
82643 /* Put symbol section at end of init part of module. */
82644 symsect->sh_flags |= SHF_ALLOC;
82645- symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
82646+ symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
82647 info->index.sym) | INIT_OFFSET_MASK;
82648 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
82649
82650@@ -2347,13 +2365,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
82651 }
82652
82653 /* Append room for core symbols at end of core part. */
82654- info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
82655- info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
82656- mod->core_size += strtab_size;
82657+ info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
82658+ info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
82659+ mod->core_size_rx += strtab_size;
82660
82661 /* Put string table section at end of init part of module. */
82662 strsect->sh_flags |= SHF_ALLOC;
82663- strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
82664+ strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
82665 info->index.str) | INIT_OFFSET_MASK;
82666 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
82667 }
82668@@ -2371,12 +2389,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
82669 /* Make sure we get permanent strtab: don't use info->strtab. */
82670 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
82671
82672+ pax_open_kernel();
82673+
82674 /* Set types up while we still have access to sections. */
82675 for (i = 0; i < mod->num_symtab; i++)
82676 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
82677
82678- mod->core_symtab = dst = mod->module_core + info->symoffs;
82679- mod->core_strtab = s = mod->module_core + info->stroffs;
82680+ mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
82681+ mod->core_strtab = s = mod->module_core_rx + info->stroffs;
82682 src = mod->symtab;
82683 for (ndst = i = 0; i < mod->num_symtab; i++) {
82684 if (i == 0 ||
82685@@ -2388,6 +2408,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
82686 }
82687 }
82688 mod->core_num_syms = ndst;
82689+
82690+ pax_close_kernel();
82691 }
82692 #else
82693 static inline void layout_symtab(struct module *mod, struct load_info *info)
82694@@ -2421,17 +2443,33 @@ void * __weak module_alloc(unsigned long size)
82695 return vmalloc_exec(size);
82696 }
82697
82698-static void *module_alloc_update_bounds(unsigned long size)
82699+static void *module_alloc_update_bounds_rw(unsigned long size)
82700 {
82701 void *ret = module_alloc(size);
82702
82703 if (ret) {
82704 mutex_lock(&module_mutex);
82705 /* Update module bounds. */
82706- if ((unsigned long)ret < module_addr_min)
82707- module_addr_min = (unsigned long)ret;
82708- if ((unsigned long)ret + size > module_addr_max)
82709- module_addr_max = (unsigned long)ret + size;
82710+ if ((unsigned long)ret < module_addr_min_rw)
82711+ module_addr_min_rw = (unsigned long)ret;
82712+ if ((unsigned long)ret + size > module_addr_max_rw)
82713+ module_addr_max_rw = (unsigned long)ret + size;
82714+ mutex_unlock(&module_mutex);
82715+ }
82716+ return ret;
82717+}
82718+
82719+static void *module_alloc_update_bounds_rx(unsigned long size)
82720+{
82721+ void *ret = module_alloc_exec(size);
82722+
82723+ if (ret) {
82724+ mutex_lock(&module_mutex);
82725+ /* Update module bounds. */
82726+ if ((unsigned long)ret < module_addr_min_rx)
82727+ module_addr_min_rx = (unsigned long)ret;
82728+ if ((unsigned long)ret + size > module_addr_max_rx)
82729+ module_addr_max_rx = (unsigned long)ret + size;
82730 mutex_unlock(&module_mutex);
82731 }
82732 return ret;
82733@@ -2706,8 +2744,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
82734 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
82735 {
82736 const char *modmagic = get_modinfo(info, "vermagic");
82737+ const char *license = get_modinfo(info, "license");
82738 int err;
82739
82740+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
82741+ if (!license || !license_is_gpl_compatible(license))
82742+ return -ENOEXEC;
82743+#endif
82744+
82745 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
82746 modmagic = NULL;
82747
82748@@ -2733,7 +2777,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
82749 }
82750
82751 /* Set up license info based on the info section */
82752- set_license(mod, get_modinfo(info, "license"));
82753+ set_license(mod, license);
82754
82755 return 0;
82756 }
82757@@ -2814,7 +2858,7 @@ static int move_module(struct module *mod, struct load_info *info)
82758 void *ptr;
82759
82760 /* Do the allocs. */
82761- ptr = module_alloc_update_bounds(mod->core_size);
82762+ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
82763 /*
82764 * The pointer to this block is stored in the module structure
82765 * which is inside the block. Just mark it as not being a
82766@@ -2824,11 +2868,11 @@ static int move_module(struct module *mod, struct load_info *info)
82767 if (!ptr)
82768 return -ENOMEM;
82769
82770- memset(ptr, 0, mod->core_size);
82771- mod->module_core = ptr;
82772+ memset(ptr, 0, mod->core_size_rw);
82773+ mod->module_core_rw = ptr;
82774
82775- if (mod->init_size) {
82776- ptr = module_alloc_update_bounds(mod->init_size);
82777+ if (mod->init_size_rw) {
82778+ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
82779 /*
82780 * The pointer to this block is stored in the module structure
82781 * which is inside the block. This block doesn't need to be
82782@@ -2837,13 +2881,45 @@ static int move_module(struct module *mod, struct load_info *info)
82783 */
82784 kmemleak_ignore(ptr);
82785 if (!ptr) {
82786- module_free(mod, mod->module_core);
82787+ module_free(mod, mod->module_core_rw);
82788 return -ENOMEM;
82789 }
82790- memset(ptr, 0, mod->init_size);
82791- mod->module_init = ptr;
82792+ memset(ptr, 0, mod->init_size_rw);
82793+ mod->module_init_rw = ptr;
82794 } else
82795- mod->module_init = NULL;
82796+ mod->module_init_rw = NULL;
82797+
82798+ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
82799+ kmemleak_not_leak(ptr);
82800+ if (!ptr) {
82801+ if (mod->module_init_rw)
82802+ module_free(mod, mod->module_init_rw);
82803+ module_free(mod, mod->module_core_rw);
82804+ return -ENOMEM;
82805+ }
82806+
82807+ pax_open_kernel();
82808+ memset(ptr, 0, mod->core_size_rx);
82809+ pax_close_kernel();
82810+ mod->module_core_rx = ptr;
82811+
82812+ if (mod->init_size_rx) {
82813+ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
82814+ kmemleak_ignore(ptr);
82815+ if (!ptr && mod->init_size_rx) {
82816+ module_free_exec(mod, mod->module_core_rx);
82817+ if (mod->module_init_rw)
82818+ module_free(mod, mod->module_init_rw);
82819+ module_free(mod, mod->module_core_rw);
82820+ return -ENOMEM;
82821+ }
82822+
82823+ pax_open_kernel();
82824+ memset(ptr, 0, mod->init_size_rx);
82825+ pax_close_kernel();
82826+ mod->module_init_rx = ptr;
82827+ } else
82828+ mod->module_init_rx = NULL;
82829
82830 /* Transfer each section which specifies SHF_ALLOC */
82831 pr_debug("final section addresses:\n");
82832@@ -2854,16 +2930,45 @@ static int move_module(struct module *mod, struct load_info *info)
82833 if (!(shdr->sh_flags & SHF_ALLOC))
82834 continue;
82835
82836- if (shdr->sh_entsize & INIT_OFFSET_MASK)
82837- dest = mod->module_init
82838- + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
82839- else
82840- dest = mod->module_core + shdr->sh_entsize;
82841+ if (shdr->sh_entsize & INIT_OFFSET_MASK) {
82842+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
82843+ dest = mod->module_init_rw
82844+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
82845+ else
82846+ dest = mod->module_init_rx
82847+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
82848+ } else {
82849+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
82850+ dest = mod->module_core_rw + shdr->sh_entsize;
82851+ else
82852+ dest = mod->module_core_rx + shdr->sh_entsize;
82853+ }
82854+
82855+ if (shdr->sh_type != SHT_NOBITS) {
82856+
82857+#ifdef CONFIG_PAX_KERNEXEC
82858+#ifdef CONFIG_X86_64
82859+ if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
82860+ set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
82861+#endif
82862+ if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
82863+ pax_open_kernel();
82864+ memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
82865+ pax_close_kernel();
82866+ } else
82867+#endif
82868
82869- if (shdr->sh_type != SHT_NOBITS)
82870 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
82871+ }
82872 /* Update sh_addr to point to copy in image. */
82873- shdr->sh_addr = (unsigned long)dest;
82874+
82875+#ifdef CONFIG_PAX_KERNEXEC
82876+ if (shdr->sh_flags & SHF_EXECINSTR)
82877+ shdr->sh_addr = ktva_ktla((unsigned long)dest);
82878+ else
82879+#endif
82880+
82881+ shdr->sh_addr = (unsigned long)dest;
82882 pr_debug("\t0x%lx %s\n",
82883 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
82884 }
82885@@ -2920,12 +3025,12 @@ static void flush_module_icache(const struct module *mod)
82886 * Do it before processing of module parameters, so the module
82887 * can provide parameter accessor functions of its own.
82888 */
82889- if (mod->module_init)
82890- flush_icache_range((unsigned long)mod->module_init,
82891- (unsigned long)mod->module_init
82892- + mod->init_size);
82893- flush_icache_range((unsigned long)mod->module_core,
82894- (unsigned long)mod->module_core + mod->core_size);
82895+ if (mod->module_init_rx)
82896+ flush_icache_range((unsigned long)mod->module_init_rx,
82897+ (unsigned long)mod->module_init_rx
82898+ + mod->init_size_rx);
82899+ flush_icache_range((unsigned long)mod->module_core_rx,
82900+ (unsigned long)mod->module_core_rx + mod->core_size_rx);
82901
82902 set_fs(old_fs);
82903 }
82904@@ -2982,8 +3087,10 @@ static struct module *layout_and_allocate(struct load_info *info, int flags)
82905 static void module_deallocate(struct module *mod, struct load_info *info)
82906 {
82907 percpu_modfree(mod);
82908- module_free(mod, mod->module_init);
82909- module_free(mod, mod->module_core);
82910+ module_free_exec(mod, mod->module_init_rx);
82911+ module_free_exec(mod, mod->module_core_rx);
82912+ module_free(mod, mod->module_init_rw);
82913+ module_free(mod, mod->module_core_rw);
82914 }
82915
82916 int __weak module_finalize(const Elf_Ehdr *hdr,
82917@@ -2996,7 +3103,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
82918 static int post_relocation(struct module *mod, const struct load_info *info)
82919 {
82920 /* Sort exception table now relocations are done. */
82921+ pax_open_kernel();
82922 sort_extable(mod->extable, mod->extable + mod->num_exentries);
82923+ pax_close_kernel();
82924
82925 /* Copy relocated percpu area over. */
82926 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
82927@@ -3050,16 +3159,16 @@ static int do_init_module(struct module *mod)
82928 MODULE_STATE_COMING, mod);
82929
82930 /* Set RO and NX regions for core */
82931- set_section_ro_nx(mod->module_core,
82932- mod->core_text_size,
82933- mod->core_ro_size,
82934- mod->core_size);
82935+ set_section_ro_nx(mod->module_core_rx,
82936+ mod->core_size_rx,
82937+ mod->core_size_rx,
82938+ mod->core_size_rx);
82939
82940 /* Set RO and NX regions for init */
82941- set_section_ro_nx(mod->module_init,
82942- mod->init_text_size,
82943- mod->init_ro_size,
82944- mod->init_size);
82945+ set_section_ro_nx(mod->module_init_rx,
82946+ mod->init_size_rx,
82947+ mod->init_size_rx,
82948+ mod->init_size_rx);
82949
82950 do_mod_ctors(mod);
82951 /* Start the module */
82952@@ -3121,11 +3230,12 @@ static int do_init_module(struct module *mod)
82953 mod->strtab = mod->core_strtab;
82954 #endif
82955 unset_module_init_ro_nx(mod);
82956- module_free(mod, mod->module_init);
82957- mod->module_init = NULL;
82958- mod->init_size = 0;
82959- mod->init_ro_size = 0;
82960- mod->init_text_size = 0;
82961+ module_free(mod, mod->module_init_rw);
82962+ module_free_exec(mod, mod->module_init_rx);
82963+ mod->module_init_rw = NULL;
82964+ mod->module_init_rx = NULL;
82965+ mod->init_size_rw = 0;
82966+ mod->init_size_rx = 0;
82967 mutex_unlock(&module_mutex);
82968 wake_up_all(&module_wq);
82969
82970@@ -3269,9 +3379,38 @@ static int load_module(struct load_info *info, const char __user *uargs,
82971 if (err)
82972 goto free_unload;
82973
82974+ /* Now copy in args */
82975+ mod->args = strndup_user(uargs, ~0UL >> 1);
82976+ if (IS_ERR(mod->args)) {
82977+ err = PTR_ERR(mod->args);
82978+ goto free_unload;
82979+ }
82980+
82981 /* Set up MODINFO_ATTR fields */
82982 setup_modinfo(mod, info);
82983
82984+#ifdef CONFIG_GRKERNSEC_MODHARDEN
82985+ {
82986+ char *p, *p2;
82987+
82988+ if (strstr(mod->args, "grsec_modharden_netdev")) {
82989+ 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);
82990+ err = -EPERM;
82991+ goto free_modinfo;
82992+ } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
82993+ p += sizeof("grsec_modharden_normal") - 1;
82994+ p2 = strstr(p, "_");
82995+ if (p2) {
82996+ *p2 = '\0';
82997+ printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
82998+ *p2 = '_';
82999+ }
83000+ err = -EPERM;
83001+ goto free_modinfo;
83002+ }
83003+ }
83004+#endif
83005+
83006 /* Fix up syms, so that st_value is a pointer to location. */
83007 err = simplify_symbols(mod, info);
83008 if (err < 0)
83009@@ -3287,13 +3426,6 @@ static int load_module(struct load_info *info, const char __user *uargs,
83010
83011 flush_module_icache(mod);
83012
83013- /* Now copy in args */
83014- mod->args = strndup_user(uargs, ~0UL >> 1);
83015- if (IS_ERR(mod->args)) {
83016- err = PTR_ERR(mod->args);
83017- goto free_arch_cleanup;
83018- }
83019-
83020 dynamic_debug_setup(info->debug, info->num_debug);
83021
83022 /* Finally it's fully formed, ready to start executing. */
83023@@ -3328,11 +3460,10 @@ static int load_module(struct load_info *info, const char __user *uargs,
83024 ddebug_cleanup:
83025 dynamic_debug_remove(info->debug);
83026 synchronize_sched();
83027- kfree(mod->args);
83028- free_arch_cleanup:
83029 module_arch_cleanup(mod);
83030 free_modinfo:
83031 free_modinfo(mod);
83032+ kfree(mod->args);
83033 free_unload:
83034 module_unload_free(mod);
83035 unlink_mod:
83036@@ -3415,10 +3546,16 @@ static const char *get_ksymbol(struct module *mod,
83037 unsigned long nextval;
83038
83039 /* At worse, next value is at end of module */
83040- if (within_module_init(addr, mod))
83041- nextval = (unsigned long)mod->module_init+mod->init_text_size;
83042+ if (within_module_init_rx(addr, mod))
83043+ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
83044+ else if (within_module_init_rw(addr, mod))
83045+ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
83046+ else if (within_module_core_rx(addr, mod))
83047+ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
83048+ else if (within_module_core_rw(addr, mod))
83049+ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
83050 else
83051- nextval = (unsigned long)mod->module_core+mod->core_text_size;
83052+ return NULL;
83053
83054 /* Scan for closest preceding symbol, and next symbol. (ELF
83055 starts real symbols at 1). */
83056@@ -3669,7 +3806,7 @@ static int m_show(struct seq_file *m, void *p)
83057 return 0;
83058
83059 seq_printf(m, "%s %u",
83060- mod->name, mod->init_size + mod->core_size);
83061+ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
83062 print_unload_info(m, mod);
83063
83064 /* Informative for users. */
83065@@ -3678,7 +3815,7 @@ static int m_show(struct seq_file *m, void *p)
83066 mod->state == MODULE_STATE_COMING ? "Loading":
83067 "Live");
83068 /* Used by oprofile and other similar tools. */
83069- seq_printf(m, " 0x%pK", mod->module_core);
83070+ seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
83071
83072 /* Taints info */
83073 if (mod->taints)
83074@@ -3714,7 +3851,17 @@ static const struct file_operations proc_modules_operations = {
83075
83076 static int __init proc_modules_init(void)
83077 {
83078+#ifndef CONFIG_GRKERNSEC_HIDESYM
83079+#ifdef CONFIG_GRKERNSEC_PROC_USER
83080+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
83081+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
83082+ proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
83083+#else
83084 proc_create("modules", 0, NULL, &proc_modules_operations);
83085+#endif
83086+#else
83087+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
83088+#endif
83089 return 0;
83090 }
83091 module_init(proc_modules_init);
83092@@ -3775,14 +3922,14 @@ struct module *__module_address(unsigned long addr)
83093 {
83094 struct module *mod;
83095
83096- if (addr < module_addr_min || addr > module_addr_max)
83097+ if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
83098+ (addr < module_addr_min_rw || addr > module_addr_max_rw))
83099 return NULL;
83100
83101 list_for_each_entry_rcu(mod, &modules, list) {
83102 if (mod->state == MODULE_STATE_UNFORMED)
83103 continue;
83104- if (within_module_core(addr, mod)
83105- || within_module_init(addr, mod))
83106+ if (within_module_init(addr, mod) || within_module_core(addr, mod))
83107 return mod;
83108 }
83109 return NULL;
83110@@ -3817,11 +3964,20 @@ bool is_module_text_address(unsigned long addr)
83111 */
83112 struct module *__module_text_address(unsigned long addr)
83113 {
83114- struct module *mod = __module_address(addr);
83115+ struct module *mod;
83116+
83117+#ifdef CONFIG_X86_32
83118+ addr = ktla_ktva(addr);
83119+#endif
83120+
83121+ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
83122+ return NULL;
83123+
83124+ mod = __module_address(addr);
83125+
83126 if (mod) {
83127 /* Make sure it's within the text section. */
83128- if (!within(addr, mod->module_init, mod->init_text_size)
83129- && !within(addr, mod->module_core, mod->core_text_size))
83130+ if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
83131 mod = NULL;
83132 }
83133 return mod;
83134diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
83135index 7e3443f..b2a1e6b 100644
83136--- a/kernel/mutex-debug.c
83137+++ b/kernel/mutex-debug.c
83138@@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
83139 }
83140
83141 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
83142- struct thread_info *ti)
83143+ struct task_struct *task)
83144 {
83145 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
83146
83147 /* Mark the current thread as blocked on the lock: */
83148- ti->task->blocked_on = waiter;
83149+ task->blocked_on = waiter;
83150 }
83151
83152 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
83153- struct thread_info *ti)
83154+ struct task_struct *task)
83155 {
83156 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
83157- DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
83158- DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
83159- ti->task->blocked_on = NULL;
83160+ DEBUG_LOCKS_WARN_ON(waiter->task != task);
83161+ DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
83162+ task->blocked_on = NULL;
83163
83164 list_del_init(&waiter->list);
83165 waiter->task = NULL;
83166diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
83167index 0799fd3..d06ae3b 100644
83168--- a/kernel/mutex-debug.h
83169+++ b/kernel/mutex-debug.h
83170@@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
83171 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
83172 extern void debug_mutex_add_waiter(struct mutex *lock,
83173 struct mutex_waiter *waiter,
83174- struct thread_info *ti);
83175+ struct task_struct *task);
83176 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
83177- struct thread_info *ti);
83178+ struct task_struct *task);
83179 extern void debug_mutex_unlock(struct mutex *lock);
83180 extern void debug_mutex_init(struct mutex *lock, const char *name,
83181 struct lock_class_key *key);
83182diff --git a/kernel/mutex.c b/kernel/mutex.c
83183index d24105b..15648eb 100644
83184--- a/kernel/mutex.c
83185+++ b/kernel/mutex.c
83186@@ -135,7 +135,7 @@ void mspin_lock(struct mspin_node **lock, struct mspin_node *node)
83187 node->locked = 1;
83188 return;
83189 }
83190- ACCESS_ONCE(prev->next) = node;
83191+ ACCESS_ONCE_RW(prev->next) = node;
83192 smp_wmb();
83193 /* Wait until the lock holder passes the lock down */
83194 while (!ACCESS_ONCE(node->locked))
83195@@ -156,7 +156,7 @@ static void mspin_unlock(struct mspin_node **lock, struct mspin_node *node)
83196 while (!(next = ACCESS_ONCE(node->next)))
83197 arch_mutex_cpu_relax();
83198 }
83199- ACCESS_ONCE(next->locked) = 1;
83200+ ACCESS_ONCE_RW(next->locked) = 1;
83201 smp_wmb();
83202 }
83203
83204@@ -520,7 +520,7 @@ slowpath:
83205 goto skip_wait;
83206
83207 debug_mutex_lock_common(lock, &waiter);
83208- debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
83209+ debug_mutex_add_waiter(lock, &waiter, task);
83210
83211 /* add waiting tasks to the end of the waitqueue (FIFO): */
83212 list_add_tail(&waiter.list, &lock->wait_list);
83213@@ -564,7 +564,7 @@ slowpath:
83214 schedule_preempt_disabled();
83215 spin_lock_mutex(&lock->wait_lock, flags);
83216 }
83217- mutex_remove_waiter(lock, &waiter, current_thread_info());
83218+ mutex_remove_waiter(lock, &waiter, task);
83219 /* set it to 0 if there are no waiters left: */
83220 if (likely(list_empty(&lock->wait_list)))
83221 atomic_set(&lock->count, 0);
83222@@ -601,7 +601,7 @@ skip_wait:
83223 return 0;
83224
83225 err:
83226- mutex_remove_waiter(lock, &waiter, task_thread_info(task));
83227+ mutex_remove_waiter(lock, &waiter, task);
83228 spin_unlock_mutex(&lock->wait_lock, flags);
83229 debug_mutex_free_waiter(&waiter);
83230 mutex_release(&lock->dep_map, 1, ip);
83231diff --git a/kernel/notifier.c b/kernel/notifier.c
83232index 2d5cc4c..d9ea600 100644
83233--- a/kernel/notifier.c
83234+++ b/kernel/notifier.c
83235@@ -5,6 +5,7 @@
83236 #include <linux/rcupdate.h>
83237 #include <linux/vmalloc.h>
83238 #include <linux/reboot.h>
83239+#include <linux/mm.h>
83240
83241 /*
83242 * Notifier list for kernel code which wants to be called
83243@@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
83244 while ((*nl) != NULL) {
83245 if (n->priority > (*nl)->priority)
83246 break;
83247- nl = &((*nl)->next);
83248+ nl = (struct notifier_block **)&((*nl)->next);
83249 }
83250- n->next = *nl;
83251+ pax_open_kernel();
83252+ *(const void **)&n->next = *nl;
83253 rcu_assign_pointer(*nl, n);
83254+ pax_close_kernel();
83255 return 0;
83256 }
83257
83258@@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
83259 return 0;
83260 if (n->priority > (*nl)->priority)
83261 break;
83262- nl = &((*nl)->next);
83263+ nl = (struct notifier_block **)&((*nl)->next);
83264 }
83265- n->next = *nl;
83266+ pax_open_kernel();
83267+ *(const void **)&n->next = *nl;
83268 rcu_assign_pointer(*nl, n);
83269+ pax_close_kernel();
83270 return 0;
83271 }
83272
83273@@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
83274 {
83275 while ((*nl) != NULL) {
83276 if ((*nl) == n) {
83277+ pax_open_kernel();
83278 rcu_assign_pointer(*nl, n->next);
83279+ pax_close_kernel();
83280 return 0;
83281 }
83282- nl = &((*nl)->next);
83283+ nl = (struct notifier_block **)&((*nl)->next);
83284 }
83285 return -ENOENT;
83286 }
83287diff --git a/kernel/panic.c b/kernel/panic.c
83288index b6c482c..5578061 100644
83289--- a/kernel/panic.c
83290+++ b/kernel/panic.c
83291@@ -407,7 +407,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
83292 disable_trace_on_warning();
83293
83294 pr_warn("------------[ cut here ]------------\n");
83295- pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pS()\n",
83296+ pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pA()\n",
83297 raw_smp_processor_id(), current->pid, file, line, caller);
83298
83299 if (args)
83300@@ -461,7 +461,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
83301 */
83302 void __stack_chk_fail(void)
83303 {
83304- panic("stack-protector: Kernel stack is corrupted in: %p\n",
83305+ dump_stack();
83306+ panic("stack-protector: Kernel stack is corrupted in: %pA\n",
83307 __builtin_return_address(0));
83308 }
83309 EXPORT_SYMBOL(__stack_chk_fail);
83310diff --git a/kernel/pid.c b/kernel/pid.c
83311index 9b9a266..c20ef80 100644
83312--- a/kernel/pid.c
83313+++ b/kernel/pid.c
83314@@ -33,6 +33,7 @@
83315 #include <linux/rculist.h>
83316 #include <linux/bootmem.h>
83317 #include <linux/hash.h>
83318+#include <linux/security.h>
83319 #include <linux/pid_namespace.h>
83320 #include <linux/init_task.h>
83321 #include <linux/syscalls.h>
83322@@ -47,7 +48,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
83323
83324 int pid_max = PID_MAX_DEFAULT;
83325
83326-#define RESERVED_PIDS 300
83327+#define RESERVED_PIDS 500
83328
83329 int pid_max_min = RESERVED_PIDS + 1;
83330 int pid_max_max = PID_MAX_LIMIT;
83331@@ -445,10 +446,18 @@ EXPORT_SYMBOL(pid_task);
83332 */
83333 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
83334 {
83335+ struct task_struct *task;
83336+
83337 rcu_lockdep_assert(rcu_read_lock_held(),
83338 "find_task_by_pid_ns() needs rcu_read_lock()"
83339 " protection");
83340- return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
83341+
83342+ task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
83343+
83344+ if (gr_pid_is_chrooted(task))
83345+ return NULL;
83346+
83347+ return task;
83348 }
83349
83350 struct task_struct *find_task_by_vpid(pid_t vnr)
83351@@ -456,6 +465,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
83352 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
83353 }
83354
83355+struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
83356+{
83357+ rcu_lockdep_assert(rcu_read_lock_held(),
83358+ "find_task_by_pid_ns() needs rcu_read_lock()"
83359+ " protection");
83360+ return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
83361+}
83362+
83363 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
83364 {
83365 struct pid *pid;
83366diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
83367index 4208655..19f36a5 100644
83368--- a/kernel/pid_namespace.c
83369+++ b/kernel/pid_namespace.c
83370@@ -247,7 +247,7 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
83371 void __user *buffer, size_t *lenp, loff_t *ppos)
83372 {
83373 struct pid_namespace *pid_ns = task_active_pid_ns(current);
83374- struct ctl_table tmp = *table;
83375+ ctl_table_no_const tmp = *table;
83376
83377 if (write && !ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN))
83378 return -EPERM;
83379diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
83380index c7f31aa..2b44977 100644
83381--- a/kernel/posix-cpu-timers.c
83382+++ b/kernel/posix-cpu-timers.c
83383@@ -1521,14 +1521,14 @@ struct k_clock clock_posix_cpu = {
83384
83385 static __init int init_posix_cpu_timers(void)
83386 {
83387- struct k_clock process = {
83388+ static struct k_clock process = {
83389 .clock_getres = process_cpu_clock_getres,
83390 .clock_get = process_cpu_clock_get,
83391 .timer_create = process_cpu_timer_create,
83392 .nsleep = process_cpu_nsleep,
83393 .nsleep_restart = process_cpu_nsleep_restart,
83394 };
83395- struct k_clock thread = {
83396+ static struct k_clock thread = {
83397 .clock_getres = thread_cpu_clock_getres,
83398 .clock_get = thread_cpu_clock_get,
83399 .timer_create = thread_cpu_timer_create,
83400diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
83401index 424c2d4..679242f 100644
83402--- a/kernel/posix-timers.c
83403+++ b/kernel/posix-timers.c
83404@@ -43,6 +43,7 @@
83405 #include <linux/hash.h>
83406 #include <linux/posix-clock.h>
83407 #include <linux/posix-timers.h>
83408+#include <linux/grsecurity.h>
83409 #include <linux/syscalls.h>
83410 #include <linux/wait.h>
83411 #include <linux/workqueue.h>
83412@@ -122,7 +123,7 @@ static DEFINE_SPINLOCK(hash_lock);
83413 * which we beg off on and pass to do_sys_settimeofday().
83414 */
83415
83416-static struct k_clock posix_clocks[MAX_CLOCKS];
83417+static struct k_clock *posix_clocks[MAX_CLOCKS];
83418
83419 /*
83420 * These ones are defined below.
83421@@ -275,7 +276,7 @@ static int posix_get_tai(clockid_t which_clock, struct timespec *tp)
83422 */
83423 static __init int init_posix_timers(void)
83424 {
83425- struct k_clock clock_realtime = {
83426+ static struct k_clock clock_realtime = {
83427 .clock_getres = hrtimer_get_res,
83428 .clock_get = posix_clock_realtime_get,
83429 .clock_set = posix_clock_realtime_set,
83430@@ -287,7 +288,7 @@ static __init int init_posix_timers(void)
83431 .timer_get = common_timer_get,
83432 .timer_del = common_timer_del,
83433 };
83434- struct k_clock clock_monotonic = {
83435+ static struct k_clock clock_monotonic = {
83436 .clock_getres = hrtimer_get_res,
83437 .clock_get = posix_ktime_get_ts,
83438 .nsleep = common_nsleep,
83439@@ -297,19 +298,19 @@ static __init int init_posix_timers(void)
83440 .timer_get = common_timer_get,
83441 .timer_del = common_timer_del,
83442 };
83443- struct k_clock clock_monotonic_raw = {
83444+ static struct k_clock clock_monotonic_raw = {
83445 .clock_getres = hrtimer_get_res,
83446 .clock_get = posix_get_monotonic_raw,
83447 };
83448- struct k_clock clock_realtime_coarse = {
83449+ static struct k_clock clock_realtime_coarse = {
83450 .clock_getres = posix_get_coarse_res,
83451 .clock_get = posix_get_realtime_coarse,
83452 };
83453- struct k_clock clock_monotonic_coarse = {
83454+ static struct k_clock clock_monotonic_coarse = {
83455 .clock_getres = posix_get_coarse_res,
83456 .clock_get = posix_get_monotonic_coarse,
83457 };
83458- struct k_clock clock_tai = {
83459+ static struct k_clock clock_tai = {
83460 .clock_getres = hrtimer_get_res,
83461 .clock_get = posix_get_tai,
83462 .nsleep = common_nsleep,
83463@@ -319,7 +320,7 @@ static __init int init_posix_timers(void)
83464 .timer_get = common_timer_get,
83465 .timer_del = common_timer_del,
83466 };
83467- struct k_clock clock_boottime = {
83468+ static struct k_clock clock_boottime = {
83469 .clock_getres = hrtimer_get_res,
83470 .clock_get = posix_get_boottime,
83471 .nsleep = common_nsleep,
83472@@ -531,7 +532,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
83473 return;
83474 }
83475
83476- posix_clocks[clock_id] = *new_clock;
83477+ posix_clocks[clock_id] = new_clock;
83478 }
83479 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
83480
83481@@ -577,9 +578,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
83482 return (id & CLOCKFD_MASK) == CLOCKFD ?
83483 &clock_posix_dynamic : &clock_posix_cpu;
83484
83485- if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
83486+ if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
83487 return NULL;
83488- return &posix_clocks[id];
83489+ return posix_clocks[id];
83490 }
83491
83492 static int common_timer_create(struct k_itimer *new_timer)
83493@@ -597,7 +598,7 @@ SYSCALL_DEFINE3(timer_create, const clockid_t, which_clock,
83494 struct k_clock *kc = clockid_to_kclock(which_clock);
83495 struct k_itimer *new_timer;
83496 int error, new_timer_id;
83497- sigevent_t event;
83498+ sigevent_t event = { };
83499 int it_id_set = IT_ID_NOT_SET;
83500
83501 if (!kc)
83502@@ -1011,6 +1012,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
83503 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
83504 return -EFAULT;
83505
83506+ /* only the CLOCK_REALTIME clock can be set, all other clocks
83507+ have their clock_set fptr set to a nosettime dummy function
83508+ CLOCK_REALTIME has a NULL clock_set fptr which causes it to
83509+ call common_clock_set, which calls do_sys_settimeofday, which
83510+ we hook
83511+ */
83512+
83513 return kc->clock_set(which_clock, &new_tp);
83514 }
83515
83516diff --git a/kernel/power/process.c b/kernel/power/process.c
83517index 06ec886..9dba35e 100644
83518--- a/kernel/power/process.c
83519+++ b/kernel/power/process.c
83520@@ -34,6 +34,7 @@ static int try_to_freeze_tasks(bool user_only)
83521 unsigned int elapsed_msecs;
83522 bool wakeup = false;
83523 int sleep_usecs = USEC_PER_MSEC;
83524+ bool timedout = false;
83525
83526 do_gettimeofday(&start);
83527
83528@@ -44,13 +45,20 @@ static int try_to_freeze_tasks(bool user_only)
83529
83530 while (true) {
83531 todo = 0;
83532+ if (time_after(jiffies, end_time))
83533+ timedout = true;
83534 read_lock(&tasklist_lock);
83535 do_each_thread(g, p) {
83536 if (p == current || !freeze_task(p))
83537 continue;
83538
83539- if (!freezer_should_skip(p))
83540+ if (!freezer_should_skip(p)) {
83541 todo++;
83542+ if (timedout) {
83543+ printk(KERN_ERR "Task refusing to freeze:\n");
83544+ sched_show_task(p);
83545+ }
83546+ }
83547 } while_each_thread(g, p);
83548 read_unlock(&tasklist_lock);
83549
83550@@ -59,7 +67,7 @@ static int try_to_freeze_tasks(bool user_only)
83551 todo += wq_busy;
83552 }
83553
83554- if (!todo || time_after(jiffies, end_time))
83555+ if (!todo || timedout)
83556 break;
83557
83558 if (pm_wakeup_pending()) {
83559diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
83560index b4e8500..b457a6c 100644
83561--- a/kernel/printk/printk.c
83562+++ b/kernel/printk/printk.c
83563@@ -385,6 +385,11 @@ static int check_syslog_permissions(int type, bool from_file)
83564 if (from_file && type != SYSLOG_ACTION_OPEN)
83565 return 0;
83566
83567+#ifdef CONFIG_GRKERNSEC_DMESG
83568+ if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
83569+ return -EPERM;
83570+#endif
83571+
83572 if (syslog_action_restricted(type)) {
83573 if (capable(CAP_SYSLOG))
83574 return 0;
83575diff --git a/kernel/profile.c b/kernel/profile.c
83576index 6631e1e..310c266 100644
83577--- a/kernel/profile.c
83578+++ b/kernel/profile.c
83579@@ -37,7 +37,7 @@ struct profile_hit {
83580 #define NR_PROFILE_HIT (PAGE_SIZE/sizeof(struct profile_hit))
83581 #define NR_PROFILE_GRP (NR_PROFILE_HIT/PROFILE_GRPSZ)
83582
83583-static atomic_t *prof_buffer;
83584+static atomic_unchecked_t *prof_buffer;
83585 static unsigned long prof_len, prof_shift;
83586
83587 int prof_on __read_mostly;
83588@@ -260,7 +260,7 @@ static void profile_flip_buffers(void)
83589 hits[i].pc = 0;
83590 continue;
83591 }
83592- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
83593+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
83594 hits[i].hits = hits[i].pc = 0;
83595 }
83596 }
83597@@ -321,9 +321,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
83598 * Add the current hit(s) and flush the write-queue out
83599 * to the global buffer:
83600 */
83601- atomic_add(nr_hits, &prof_buffer[pc]);
83602+ atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
83603 for (i = 0; i < NR_PROFILE_HIT; ++i) {
83604- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
83605+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
83606 hits[i].pc = hits[i].hits = 0;
83607 }
83608 out:
83609@@ -398,7 +398,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
83610 {
83611 unsigned long pc;
83612 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
83613- atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
83614+ atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
83615 }
83616 #endif /* !CONFIG_SMP */
83617
83618@@ -494,7 +494,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
83619 return -EFAULT;
83620 buf++; p++; count--; read++;
83621 }
83622- pnt = (char *)prof_buffer + p - sizeof(atomic_t);
83623+ pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
83624 if (copy_to_user(buf, (void *)pnt, count))
83625 return -EFAULT;
83626 read += count;
83627@@ -525,7 +525,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
83628 }
83629 #endif
83630 profile_discard_flip_buffers();
83631- memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
83632+ memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
83633 return count;
83634 }
83635
83636diff --git a/kernel/ptrace.c b/kernel/ptrace.c
83637index dd562e9..74fc16d 100644
83638--- a/kernel/ptrace.c
83639+++ b/kernel/ptrace.c
83640@@ -326,7 +326,7 @@ static int ptrace_attach(struct task_struct *task, long request,
83641 if (seize)
83642 flags |= PT_SEIZED;
83643 rcu_read_lock();
83644- if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
83645+ if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
83646 flags |= PT_PTRACE_CAP;
83647 rcu_read_unlock();
83648 task->ptrace = flags;
83649@@ -537,7 +537,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
83650 break;
83651 return -EIO;
83652 }
83653- if (copy_to_user(dst, buf, retval))
83654+ if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
83655 return -EFAULT;
83656 copied += retval;
83657 src += retval;
83658@@ -805,7 +805,7 @@ int ptrace_request(struct task_struct *child, long request,
83659 bool seized = child->ptrace & PT_SEIZED;
83660 int ret = -EIO;
83661 siginfo_t siginfo, *si;
83662- void __user *datavp = (void __user *) data;
83663+ void __user *datavp = (__force void __user *) data;
83664 unsigned long __user *datalp = datavp;
83665 unsigned long flags;
83666
83667@@ -1051,14 +1051,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
83668 goto out;
83669 }
83670
83671+ if (gr_handle_ptrace(child, request)) {
83672+ ret = -EPERM;
83673+ goto out_put_task_struct;
83674+ }
83675+
83676 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
83677 ret = ptrace_attach(child, request, addr, data);
83678 /*
83679 * Some architectures need to do book-keeping after
83680 * a ptrace attach.
83681 */
83682- if (!ret)
83683+ if (!ret) {
83684 arch_ptrace_attach(child);
83685+ gr_audit_ptrace(child);
83686+ }
83687 goto out_put_task_struct;
83688 }
83689
83690@@ -1086,7 +1093,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
83691 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
83692 if (copied != sizeof(tmp))
83693 return -EIO;
83694- return put_user(tmp, (unsigned long __user *)data);
83695+ return put_user(tmp, (__force unsigned long __user *)data);
83696 }
83697
83698 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
83699@@ -1180,7 +1187,7 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
83700 }
83701
83702 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
83703- compat_long_t addr, compat_long_t data)
83704+ compat_ulong_t addr, compat_ulong_t data)
83705 {
83706 struct task_struct *child;
83707 long ret;
83708@@ -1196,14 +1203,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
83709 goto out;
83710 }
83711
83712+ if (gr_handle_ptrace(child, request)) {
83713+ ret = -EPERM;
83714+ goto out_put_task_struct;
83715+ }
83716+
83717 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
83718 ret = ptrace_attach(child, request, addr, data);
83719 /*
83720 * Some architectures need to do book-keeping after
83721 * a ptrace attach.
83722 */
83723- if (!ret)
83724+ if (!ret) {
83725 arch_ptrace_attach(child);
83726+ gr_audit_ptrace(child);
83727+ }
83728 goto out_put_task_struct;
83729 }
83730
83731diff --git a/kernel/rcupdate.c b/kernel/rcupdate.c
83732index b02a339..ce2d20c 100644
83733--- a/kernel/rcupdate.c
83734+++ b/kernel/rcupdate.c
83735@@ -312,10 +312,10 @@ int rcu_jiffies_till_stall_check(void)
83736 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
83737 */
83738 if (till_stall_check < 3) {
83739- ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
83740+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
83741 till_stall_check = 3;
83742 } else if (till_stall_check > 300) {
83743- ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
83744+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
83745 till_stall_check = 300;
83746 }
83747 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
83748diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
83749index 9ed6075..c9e8a63 100644
83750--- a/kernel/rcutiny.c
83751+++ b/kernel/rcutiny.c
83752@@ -45,7 +45,7 @@
83753 /* Forward declarations for rcutiny_plugin.h. */
83754 struct rcu_ctrlblk;
83755 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
83756-static void rcu_process_callbacks(struct softirq_action *unused);
83757+static void rcu_process_callbacks(void);
83758 static void __call_rcu(struct rcu_head *head,
83759 void (*func)(struct rcu_head *rcu),
83760 struct rcu_ctrlblk *rcp);
83761@@ -309,7 +309,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
83762 false));
83763 }
83764
83765-static void rcu_process_callbacks(struct softirq_action *unused)
83766+static __latent_entropy void rcu_process_callbacks(void)
83767 {
83768 __rcu_process_callbacks(&rcu_sched_ctrlblk);
83769 __rcu_process_callbacks(&rcu_bh_ctrlblk);
83770diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
83771index be63101..05cf721 100644
83772--- a/kernel/rcutorture.c
83773+++ b/kernel/rcutorture.c
83774@@ -170,12 +170,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
83775 { 0 };
83776 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
83777 { 0 };
83778-static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
83779-static atomic_t n_rcu_torture_alloc;
83780-static atomic_t n_rcu_torture_alloc_fail;
83781-static atomic_t n_rcu_torture_free;
83782-static atomic_t n_rcu_torture_mberror;
83783-static atomic_t n_rcu_torture_error;
83784+static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
83785+static atomic_unchecked_t n_rcu_torture_alloc;
83786+static atomic_unchecked_t n_rcu_torture_alloc_fail;
83787+static atomic_unchecked_t n_rcu_torture_free;
83788+static atomic_unchecked_t n_rcu_torture_mberror;
83789+static atomic_unchecked_t n_rcu_torture_error;
83790 static long n_rcu_torture_barrier_error;
83791 static long n_rcu_torture_boost_ktrerror;
83792 static long n_rcu_torture_boost_rterror;
83793@@ -293,11 +293,11 @@ rcu_torture_alloc(void)
83794
83795 spin_lock_bh(&rcu_torture_lock);
83796 if (list_empty(&rcu_torture_freelist)) {
83797- atomic_inc(&n_rcu_torture_alloc_fail);
83798+ atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
83799 spin_unlock_bh(&rcu_torture_lock);
83800 return NULL;
83801 }
83802- atomic_inc(&n_rcu_torture_alloc);
83803+ atomic_inc_unchecked(&n_rcu_torture_alloc);
83804 p = rcu_torture_freelist.next;
83805 list_del_init(p);
83806 spin_unlock_bh(&rcu_torture_lock);
83807@@ -310,7 +310,7 @@ rcu_torture_alloc(void)
83808 static void
83809 rcu_torture_free(struct rcu_torture *p)
83810 {
83811- atomic_inc(&n_rcu_torture_free);
83812+ atomic_inc_unchecked(&n_rcu_torture_free);
83813 spin_lock_bh(&rcu_torture_lock);
83814 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
83815 spin_unlock_bh(&rcu_torture_lock);
83816@@ -431,7 +431,7 @@ rcu_torture_cb(struct rcu_head *p)
83817 i = rp->rtort_pipe_count;
83818 if (i > RCU_TORTURE_PIPE_LEN)
83819 i = RCU_TORTURE_PIPE_LEN;
83820- atomic_inc(&rcu_torture_wcount[i]);
83821+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
83822 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
83823 rp->rtort_mbtest = 0;
83824 rcu_torture_free(rp);
83825@@ -821,7 +821,7 @@ rcu_torture_writer(void *arg)
83826 i = old_rp->rtort_pipe_count;
83827 if (i > RCU_TORTURE_PIPE_LEN)
83828 i = RCU_TORTURE_PIPE_LEN;
83829- atomic_inc(&rcu_torture_wcount[i]);
83830+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
83831 old_rp->rtort_pipe_count++;
83832 if (gp_normal == gp_exp)
83833 exp = !!(rcu_random(&rand) & 0x80);
83834@@ -839,7 +839,7 @@ rcu_torture_writer(void *arg)
83835 i = rp->rtort_pipe_count;
83836 if (i > RCU_TORTURE_PIPE_LEN)
83837 i = RCU_TORTURE_PIPE_LEN;
83838- atomic_inc(&rcu_torture_wcount[i]);
83839+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
83840 if (++rp->rtort_pipe_count >=
83841 RCU_TORTURE_PIPE_LEN) {
83842 rp->rtort_mbtest = 0;
83843@@ -938,7 +938,7 @@ static void rcu_torture_timer(unsigned long unused)
83844 return;
83845 }
83846 if (p->rtort_mbtest == 0)
83847- atomic_inc(&n_rcu_torture_mberror);
83848+ atomic_inc_unchecked(&n_rcu_torture_mberror);
83849 spin_lock(&rand_lock);
83850 cur_ops->read_delay(&rand);
83851 n_rcu_torture_timers++;
83852@@ -1008,7 +1008,7 @@ rcu_torture_reader(void *arg)
83853 continue;
83854 }
83855 if (p->rtort_mbtest == 0)
83856- atomic_inc(&n_rcu_torture_mberror);
83857+ atomic_inc_unchecked(&n_rcu_torture_mberror);
83858 cur_ops->read_delay(&rand);
83859 preempt_disable();
83860 pipe_count = p->rtort_pipe_count;
83861@@ -1071,11 +1071,11 @@ rcu_torture_printk(char *page)
83862 rcu_torture_current,
83863 rcu_torture_current_version,
83864 list_empty(&rcu_torture_freelist),
83865- atomic_read(&n_rcu_torture_alloc),
83866- atomic_read(&n_rcu_torture_alloc_fail),
83867- atomic_read(&n_rcu_torture_free));
83868+ atomic_read_unchecked(&n_rcu_torture_alloc),
83869+ atomic_read_unchecked(&n_rcu_torture_alloc_fail),
83870+ atomic_read_unchecked(&n_rcu_torture_free));
83871 cnt += sprintf(&page[cnt], "rtmbe: %d rtbke: %ld rtbre: %ld ",
83872- atomic_read(&n_rcu_torture_mberror),
83873+ atomic_read_unchecked(&n_rcu_torture_mberror),
83874 n_rcu_torture_boost_ktrerror,
83875 n_rcu_torture_boost_rterror);
83876 cnt += sprintf(&page[cnt], "rtbf: %ld rtb: %ld nt: %ld ",
83877@@ -1094,14 +1094,14 @@ rcu_torture_printk(char *page)
83878 n_barrier_attempts,
83879 n_rcu_torture_barrier_error);
83880 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
83881- if (atomic_read(&n_rcu_torture_mberror) != 0 ||
83882+ if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
83883 n_rcu_torture_barrier_error != 0 ||
83884 n_rcu_torture_boost_ktrerror != 0 ||
83885 n_rcu_torture_boost_rterror != 0 ||
83886 n_rcu_torture_boost_failure != 0 ||
83887 i > 1) {
83888 cnt += sprintf(&page[cnt], "!!! ");
83889- atomic_inc(&n_rcu_torture_error);
83890+ atomic_inc_unchecked(&n_rcu_torture_error);
83891 WARN_ON_ONCE(1);
83892 }
83893 cnt += sprintf(&page[cnt], "Reader Pipe: ");
83894@@ -1115,7 +1115,7 @@ rcu_torture_printk(char *page)
83895 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
83896 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
83897 cnt += sprintf(&page[cnt], " %d",
83898- atomic_read(&rcu_torture_wcount[i]));
83899+ atomic_read_unchecked(&rcu_torture_wcount[i]));
83900 }
83901 cnt += sprintf(&page[cnt], "\n");
83902 if (cur_ops->stats)
83903@@ -1830,7 +1830,7 @@ rcu_torture_cleanup(void)
83904
83905 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
83906
83907- if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
83908+ if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
83909 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
83910 else if (n_online_successes != n_online_attempts ||
83911 n_offline_successes != n_offline_attempts)
83912@@ -1952,18 +1952,18 @@ rcu_torture_init(void)
83913
83914 rcu_torture_current = NULL;
83915 rcu_torture_current_version = 0;
83916- atomic_set(&n_rcu_torture_alloc, 0);
83917- atomic_set(&n_rcu_torture_alloc_fail, 0);
83918- atomic_set(&n_rcu_torture_free, 0);
83919- atomic_set(&n_rcu_torture_mberror, 0);
83920- atomic_set(&n_rcu_torture_error, 0);
83921+ atomic_set_unchecked(&n_rcu_torture_alloc, 0);
83922+ atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
83923+ atomic_set_unchecked(&n_rcu_torture_free, 0);
83924+ atomic_set_unchecked(&n_rcu_torture_mberror, 0);
83925+ atomic_set_unchecked(&n_rcu_torture_error, 0);
83926 n_rcu_torture_barrier_error = 0;
83927 n_rcu_torture_boost_ktrerror = 0;
83928 n_rcu_torture_boost_rterror = 0;
83929 n_rcu_torture_boost_failure = 0;
83930 n_rcu_torture_boosts = 0;
83931 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
83932- atomic_set(&rcu_torture_wcount[i], 0);
83933+ atomic_set_unchecked(&rcu_torture_wcount[i], 0);
83934 for_each_possible_cpu(cpu) {
83935 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
83936 per_cpu(rcu_torture_count, cpu)[i] = 0;
83937diff --git a/kernel/rcutree.c b/kernel/rcutree.c
83938index 32618b3..c1fb822 100644
83939--- a/kernel/rcutree.c
83940+++ b/kernel/rcutree.c
83941@@ -382,9 +382,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
83942 rcu_prepare_for_idle(smp_processor_id());
83943 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
83944 smp_mb__before_atomic_inc(); /* See above. */
83945- atomic_inc(&rdtp->dynticks);
83946+ atomic_inc_unchecked(&rdtp->dynticks);
83947 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
83948- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
83949+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
83950
83951 /*
83952 * It is illegal to enter an extended quiescent state while
83953@@ -501,10 +501,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
83954 int user)
83955 {
83956 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
83957- atomic_inc(&rdtp->dynticks);
83958+ atomic_inc_unchecked(&rdtp->dynticks);
83959 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
83960 smp_mb__after_atomic_inc(); /* See above. */
83961- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
83962+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
83963 rcu_cleanup_after_idle(smp_processor_id());
83964 trace_rcu_dyntick(TPS("End"), oldval, rdtp->dynticks_nesting);
83965 if (!user && !is_idle_task(current)) {
83966@@ -623,14 +623,14 @@ void rcu_nmi_enter(void)
83967 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
83968
83969 if (rdtp->dynticks_nmi_nesting == 0 &&
83970- (atomic_read(&rdtp->dynticks) & 0x1))
83971+ (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
83972 return;
83973 rdtp->dynticks_nmi_nesting++;
83974 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
83975- atomic_inc(&rdtp->dynticks);
83976+ atomic_inc_unchecked(&rdtp->dynticks);
83977 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
83978 smp_mb__after_atomic_inc(); /* See above. */
83979- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
83980+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
83981 }
83982
83983 /**
83984@@ -649,9 +649,9 @@ void rcu_nmi_exit(void)
83985 return;
83986 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
83987 smp_mb__before_atomic_inc(); /* See above. */
83988- atomic_inc(&rdtp->dynticks);
83989+ atomic_inc_unchecked(&rdtp->dynticks);
83990 smp_mb__after_atomic_inc(); /* Force delay to next write. */
83991- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
83992+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
83993 }
83994
83995 /**
83996@@ -665,7 +665,7 @@ int rcu_is_cpu_idle(void)
83997 int ret;
83998
83999 preempt_disable();
84000- ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
84001+ ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
84002 preempt_enable();
84003 return ret;
84004 }
84005@@ -734,7 +734,7 @@ static int rcu_is_cpu_rrupt_from_idle(void)
84006 static int dyntick_save_progress_counter(struct rcu_data *rdp,
84007 bool *isidle, unsigned long *maxj)
84008 {
84009- rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
84010+ rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
84011 rcu_sysidle_check_cpu(rdp, isidle, maxj);
84012 return (rdp->dynticks_snap & 0x1) == 0;
84013 }
84014@@ -751,7 +751,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp,
84015 unsigned int curr;
84016 unsigned int snap;
84017
84018- curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
84019+ curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
84020 snap = (unsigned int)rdp->dynticks_snap;
84021
84022 /*
84023@@ -1341,9 +1341,9 @@ static int rcu_gp_init(struct rcu_state *rsp)
84024 rdp = this_cpu_ptr(rsp->rda);
84025 rcu_preempt_check_blocked_tasks(rnp);
84026 rnp->qsmask = rnp->qsmaskinit;
84027- ACCESS_ONCE(rnp->gpnum) = rsp->gpnum;
84028+ ACCESS_ONCE_RW(rnp->gpnum) = rsp->gpnum;
84029 WARN_ON_ONCE(rnp->completed != rsp->completed);
84030- ACCESS_ONCE(rnp->completed) = rsp->completed;
84031+ ACCESS_ONCE_RW(rnp->completed) = rsp->completed;
84032 if (rnp == rdp->mynode)
84033 __note_gp_changes(rsp, rnp, rdp);
84034 rcu_preempt_boost_start_gp(rnp);
84035@@ -1434,7 +1434,7 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
84036 */
84037 rcu_for_each_node_breadth_first(rsp, rnp) {
84038 raw_spin_lock_irq(&rnp->lock);
84039- ACCESS_ONCE(rnp->completed) = rsp->gpnum;
84040+ ACCESS_ONCE_RW(rnp->completed) = rsp->gpnum;
84041 rdp = this_cpu_ptr(rsp->rda);
84042 if (rnp == rdp->mynode)
84043 __note_gp_changes(rsp, rnp, rdp);
84044@@ -1766,7 +1766,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
84045 rsp->qlen += rdp->qlen;
84046 rdp->n_cbs_orphaned += rdp->qlen;
84047 rdp->qlen_lazy = 0;
84048- ACCESS_ONCE(rdp->qlen) = 0;
84049+ ACCESS_ONCE_RW(rdp->qlen) = 0;
84050 }
84051
84052 /*
84053@@ -2012,7 +2012,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
84054 }
84055 smp_mb(); /* List handling before counting for rcu_barrier(). */
84056 rdp->qlen_lazy -= count_lazy;
84057- ACCESS_ONCE(rdp->qlen) -= count;
84058+ ACCESS_ONCE_RW(rdp->qlen) -= count;
84059 rdp->n_cbs_invoked += count;
84060
84061 /* Reinstate batch limit if we have worked down the excess. */
84062@@ -2209,7 +2209,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
84063 /*
84064 * Do RCU core processing for the current CPU.
84065 */
84066-static void rcu_process_callbacks(struct softirq_action *unused)
84067+static __latent_entropy void rcu_process_callbacks(void)
84068 {
84069 struct rcu_state *rsp;
84070
84071@@ -2316,7 +2316,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
84072 WARN_ON_ONCE((unsigned long)head & 0x3); /* Misaligned rcu_head! */
84073 if (debug_rcu_head_queue(head)) {
84074 /* Probable double call_rcu(), so leak the callback. */
84075- ACCESS_ONCE(head->func) = rcu_leak_callback;
84076+ ACCESS_ONCE_RW(head->func) = rcu_leak_callback;
84077 WARN_ONCE(1, "__call_rcu(): Leaked duplicate callback\n");
84078 return;
84079 }
84080@@ -2344,7 +2344,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
84081 local_irq_restore(flags);
84082 return;
84083 }
84084- ACCESS_ONCE(rdp->qlen)++;
84085+ ACCESS_ONCE_RW(rdp->qlen)++;
84086 if (lazy)
84087 rdp->qlen_lazy++;
84088 else
84089@@ -2553,11 +2553,11 @@ void synchronize_sched_expedited(void)
84090 * counter wrap on a 32-bit system. Quite a few more CPUs would of
84091 * course be required on a 64-bit system.
84092 */
84093- if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
84094+ if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
84095 (ulong)atomic_long_read(&rsp->expedited_done) +
84096 ULONG_MAX / 8)) {
84097 synchronize_sched();
84098- atomic_long_inc(&rsp->expedited_wrap);
84099+ atomic_long_inc_unchecked(&rsp->expedited_wrap);
84100 return;
84101 }
84102
84103@@ -2565,7 +2565,7 @@ void synchronize_sched_expedited(void)
84104 * Take a ticket. Note that atomic_inc_return() implies a
84105 * full memory barrier.
84106 */
84107- snap = atomic_long_inc_return(&rsp->expedited_start);
84108+ snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
84109 firstsnap = snap;
84110 get_online_cpus();
84111 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
84112@@ -2578,14 +2578,14 @@ void synchronize_sched_expedited(void)
84113 synchronize_sched_expedited_cpu_stop,
84114 NULL) == -EAGAIN) {
84115 put_online_cpus();
84116- atomic_long_inc(&rsp->expedited_tryfail);
84117+ atomic_long_inc_unchecked(&rsp->expedited_tryfail);
84118
84119 /* Check to see if someone else did our work for us. */
84120 s = atomic_long_read(&rsp->expedited_done);
84121 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
84122 /* ensure test happens before caller kfree */
84123 smp_mb__before_atomic_inc(); /* ^^^ */
84124- atomic_long_inc(&rsp->expedited_workdone1);
84125+ atomic_long_inc_unchecked(&rsp->expedited_workdone1);
84126 return;
84127 }
84128
84129@@ -2594,7 +2594,7 @@ void synchronize_sched_expedited(void)
84130 udelay(trycount * num_online_cpus());
84131 } else {
84132 wait_rcu_gp(call_rcu_sched);
84133- atomic_long_inc(&rsp->expedited_normal);
84134+ atomic_long_inc_unchecked(&rsp->expedited_normal);
84135 return;
84136 }
84137
84138@@ -2603,7 +2603,7 @@ void synchronize_sched_expedited(void)
84139 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
84140 /* ensure test happens before caller kfree */
84141 smp_mb__before_atomic_inc(); /* ^^^ */
84142- atomic_long_inc(&rsp->expedited_workdone2);
84143+ atomic_long_inc_unchecked(&rsp->expedited_workdone2);
84144 return;
84145 }
84146
84147@@ -2615,10 +2615,10 @@ void synchronize_sched_expedited(void)
84148 * period works for us.
84149 */
84150 get_online_cpus();
84151- snap = atomic_long_read(&rsp->expedited_start);
84152+ snap = atomic_long_read_unchecked(&rsp->expedited_start);
84153 smp_mb(); /* ensure read is before try_stop_cpus(). */
84154 }
84155- atomic_long_inc(&rsp->expedited_stoppedcpus);
84156+ atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
84157
84158 /*
84159 * Everyone up to our most recent fetch is covered by our grace
84160@@ -2627,16 +2627,16 @@ void synchronize_sched_expedited(void)
84161 * than we did already did their update.
84162 */
84163 do {
84164- atomic_long_inc(&rsp->expedited_done_tries);
84165+ atomic_long_inc_unchecked(&rsp->expedited_done_tries);
84166 s = atomic_long_read(&rsp->expedited_done);
84167 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
84168 /* ensure test happens before caller kfree */
84169 smp_mb__before_atomic_inc(); /* ^^^ */
84170- atomic_long_inc(&rsp->expedited_done_lost);
84171+ atomic_long_inc_unchecked(&rsp->expedited_done_lost);
84172 break;
84173 }
84174 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
84175- atomic_long_inc(&rsp->expedited_done_exit);
84176+ atomic_long_inc_unchecked(&rsp->expedited_done_exit);
84177
84178 put_online_cpus();
84179 }
84180@@ -2829,7 +2829,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
84181 * ACCESS_ONCE() to prevent the compiler from speculating
84182 * the increment to precede the early-exit check.
84183 */
84184- ACCESS_ONCE(rsp->n_barrier_done)++;
84185+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
84186 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
84187 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
84188 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
84189@@ -2879,7 +2879,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
84190
84191 /* Increment ->n_barrier_done to prevent duplicate work. */
84192 smp_mb(); /* Keep increment after above mechanism. */
84193- ACCESS_ONCE(rsp->n_barrier_done)++;
84194+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
84195 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
84196 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
84197 smp_mb(); /* Keep increment before caller's subsequent code. */
84198@@ -2924,10 +2924,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
84199 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
84200 init_callback_list(rdp);
84201 rdp->qlen_lazy = 0;
84202- ACCESS_ONCE(rdp->qlen) = 0;
84203+ ACCESS_ONCE_RW(rdp->qlen) = 0;
84204 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
84205 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
84206- WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
84207+ WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
84208 rdp->cpu = cpu;
84209 rdp->rsp = rsp;
84210 rcu_boot_init_nocb_percpu_data(rdp);
84211@@ -2961,8 +2961,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
84212 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
84213 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
84214 rcu_sysidle_init_percpu_data(rdp->dynticks);
84215- atomic_set(&rdp->dynticks->dynticks,
84216- (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
84217+ atomic_set_unchecked(&rdp->dynticks->dynticks,
84218+ (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
84219 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
84220
84221 /* Add CPU to rcu_node bitmasks. */
84222diff --git a/kernel/rcutree.h b/kernel/rcutree.h
84223index 5f97eab..db8f687 100644
84224--- a/kernel/rcutree.h
84225+++ b/kernel/rcutree.h
84226@@ -87,11 +87,11 @@ struct rcu_dynticks {
84227 long long dynticks_nesting; /* Track irq/process nesting level. */
84228 /* Process level is worth LLONG_MAX/2. */
84229 int dynticks_nmi_nesting; /* Track NMI nesting level. */
84230- atomic_t dynticks; /* Even value for idle, else odd. */
84231+ atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
84232 #ifdef CONFIG_NO_HZ_FULL_SYSIDLE
84233 long long dynticks_idle_nesting;
84234 /* irq/process nesting level from idle. */
84235- atomic_t dynticks_idle; /* Even value for idle, else odd. */
84236+ atomic_unchecked_t dynticks_idle; /* Even value for idle, else odd. */
84237 /* "Idle" excludes userspace execution. */
84238 unsigned long dynticks_idle_jiffies;
84239 /* End of last non-NMI non-idle period. */
84240@@ -427,17 +427,17 @@ struct rcu_state {
84241 /* _rcu_barrier(). */
84242 /* End of fields guarded by barrier_mutex. */
84243
84244- atomic_long_t expedited_start; /* Starting ticket. */
84245- atomic_long_t expedited_done; /* Done ticket. */
84246- atomic_long_t expedited_wrap; /* # near-wrap incidents. */
84247- atomic_long_t expedited_tryfail; /* # acquisition failures. */
84248- atomic_long_t expedited_workdone1; /* # done by others #1. */
84249- atomic_long_t expedited_workdone2; /* # done by others #2. */
84250- atomic_long_t expedited_normal; /* # fallbacks to normal. */
84251- atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
84252- atomic_long_t expedited_done_tries; /* # tries to update _done. */
84253- atomic_long_t expedited_done_lost; /* # times beaten to _done. */
84254- atomic_long_t expedited_done_exit; /* # times exited _done loop. */
84255+ atomic_long_unchecked_t expedited_start; /* Starting ticket. */
84256+ atomic_long_t expedited_done; /* Done ticket. */
84257+ atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
84258+ atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
84259+ atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
84260+ atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
84261+ atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
84262+ atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
84263+ atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
84264+ atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
84265+ atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
84266
84267 unsigned long jiffies_force_qs; /* Time at which to invoke */
84268 /* force_quiescent_state(). */
84269diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
84270index 130c97b..da2e5fc 100644
84271--- a/kernel/rcutree_plugin.h
84272+++ b/kernel/rcutree_plugin.h
84273@@ -900,7 +900,7 @@ void synchronize_rcu_expedited(void)
84274
84275 /* Clean up and exit. */
84276 smp_mb(); /* ensure expedited GP seen before counter increment. */
84277- ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
84278+ ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
84279 unlock_mb_ret:
84280 mutex_unlock(&sync_rcu_preempt_exp_mutex);
84281 mb_ret:
84282@@ -1474,7 +1474,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
84283 free_cpumask_var(cm);
84284 }
84285
84286-static struct smp_hotplug_thread rcu_cpu_thread_spec = {
84287+static struct smp_hotplug_thread rcu_cpu_thread_spec __read_only = {
84288 .store = &rcu_cpu_kthread_task,
84289 .thread_should_run = rcu_cpu_kthread_should_run,
84290 .thread_fn = rcu_cpu_kthread,
84291@@ -1939,7 +1939,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
84292 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
84293 pr_err("\t%d: (%lu %s) idle=%03x/%llx/%d softirq=%u/%u %s\n",
84294 cpu, ticks_value, ticks_title,
84295- atomic_read(&rdtp->dynticks) & 0xfff,
84296+ atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
84297 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
84298 rdp->softirq_snap, kstat_softirqs_cpu(RCU_SOFTIRQ, cpu),
84299 fast_no_hz);
84300@@ -2102,7 +2102,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
84301
84302 /* Enqueue the callback on the nocb list and update counts. */
84303 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
84304- ACCESS_ONCE(*old_rhpp) = rhp;
84305+ ACCESS_ONCE_RW(*old_rhpp) = rhp;
84306 atomic_long_add(rhcount, &rdp->nocb_q_count);
84307 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
84308
84309@@ -2242,12 +2242,12 @@ static int rcu_nocb_kthread(void *arg)
84310 * Extract queued callbacks, update counts, and wait
84311 * for a grace period to elapse.
84312 */
84313- ACCESS_ONCE(rdp->nocb_head) = NULL;
84314+ ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
84315 tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
84316 c = atomic_long_xchg(&rdp->nocb_q_count, 0);
84317 cl = atomic_long_xchg(&rdp->nocb_q_count_lazy, 0);
84318- ACCESS_ONCE(rdp->nocb_p_count) += c;
84319- ACCESS_ONCE(rdp->nocb_p_count_lazy) += cl;
84320+ ACCESS_ONCE_RW(rdp->nocb_p_count) += c;
84321+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) += cl;
84322 rcu_nocb_wait_gp(rdp);
84323
84324 /* Each pass through the following loop invokes a callback. */
84325@@ -2269,8 +2269,8 @@ static int rcu_nocb_kthread(void *arg)
84326 list = next;
84327 }
84328 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
84329- ACCESS_ONCE(rdp->nocb_p_count) -= c;
84330- ACCESS_ONCE(rdp->nocb_p_count_lazy) -= cl;
84331+ ACCESS_ONCE_RW(rdp->nocb_p_count) -= c;
84332+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) -= cl;
84333 rdp->n_nocbs_invoked += c;
84334 }
84335 return 0;
84336@@ -2297,7 +2297,7 @@ static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp)
84337 t = kthread_run(rcu_nocb_kthread, rdp,
84338 "rcuo%c/%d", rsp->abbr, cpu);
84339 BUG_ON(IS_ERR(t));
84340- ACCESS_ONCE(rdp->nocb_kthread) = t;
84341+ ACCESS_ONCE_RW(rdp->nocb_kthread) = t;
84342 }
84343 }
84344
84345@@ -2425,9 +2425,9 @@ static void rcu_sysidle_enter(struct rcu_dynticks *rdtp, int irq)
84346 j = jiffies;
84347 ACCESS_ONCE(rdtp->dynticks_idle_jiffies) = j;
84348 smp_mb__before_atomic_inc();
84349- atomic_inc(&rdtp->dynticks_idle);
84350+ atomic_inc_unchecked(&rdtp->dynticks_idle);
84351 smp_mb__after_atomic_inc();
84352- WARN_ON_ONCE(atomic_read(&rdtp->dynticks_idle) & 0x1);
84353+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1);
84354 }
84355
84356 /*
84357@@ -2492,9 +2492,9 @@ static void rcu_sysidle_exit(struct rcu_dynticks *rdtp, int irq)
84358
84359 /* Record end of idle period. */
84360 smp_mb__before_atomic_inc();
84361- atomic_inc(&rdtp->dynticks_idle);
84362+ atomic_inc_unchecked(&rdtp->dynticks_idle);
84363 smp_mb__after_atomic_inc();
84364- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks_idle) & 0x1));
84365+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1));
84366
84367 /*
84368 * If we are the timekeeping CPU, we are permitted to be non-idle
84369@@ -2535,7 +2535,7 @@ static void rcu_sysidle_check_cpu(struct rcu_data *rdp, bool *isidle,
84370 WARN_ON_ONCE(smp_processor_id() != tick_do_timer_cpu);
84371
84372 /* Pick up current idle and NMI-nesting counter and check. */
84373- cur = atomic_read(&rdtp->dynticks_idle);
84374+ cur = atomic_read_unchecked(&rdtp->dynticks_idle);
84375 if (cur & 0x1) {
84376 *isidle = false; /* We are not idle! */
84377 return;
84378diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
84379index cf6c174..a8f4b50 100644
84380--- a/kernel/rcutree_trace.c
84381+++ b/kernel/rcutree_trace.c
84382@@ -121,7 +121,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
84383 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
84384 rdp->passed_quiesce, rdp->qs_pending);
84385 seq_printf(m, " dt=%d/%llx/%d df=%lu",
84386- atomic_read(&rdp->dynticks->dynticks),
84387+ atomic_read_unchecked(&rdp->dynticks->dynticks),
84388 rdp->dynticks->dynticks_nesting,
84389 rdp->dynticks->dynticks_nmi_nesting,
84390 rdp->dynticks_fqs);
84391@@ -182,17 +182,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
84392 struct rcu_state *rsp = (struct rcu_state *)m->private;
84393
84394 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",
84395- atomic_long_read(&rsp->expedited_start),
84396+ atomic_long_read_unchecked(&rsp->expedited_start),
84397 atomic_long_read(&rsp->expedited_done),
84398- atomic_long_read(&rsp->expedited_wrap),
84399- atomic_long_read(&rsp->expedited_tryfail),
84400- atomic_long_read(&rsp->expedited_workdone1),
84401- atomic_long_read(&rsp->expedited_workdone2),
84402- atomic_long_read(&rsp->expedited_normal),
84403- atomic_long_read(&rsp->expedited_stoppedcpus),
84404- atomic_long_read(&rsp->expedited_done_tries),
84405- atomic_long_read(&rsp->expedited_done_lost),
84406- atomic_long_read(&rsp->expedited_done_exit));
84407+ atomic_long_read_unchecked(&rsp->expedited_wrap),
84408+ atomic_long_read_unchecked(&rsp->expedited_tryfail),
84409+ atomic_long_read_unchecked(&rsp->expedited_workdone1),
84410+ atomic_long_read_unchecked(&rsp->expedited_workdone2),
84411+ atomic_long_read_unchecked(&rsp->expedited_normal),
84412+ atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
84413+ atomic_long_read_unchecked(&rsp->expedited_done_tries),
84414+ atomic_long_read_unchecked(&rsp->expedited_done_lost),
84415+ atomic_long_read_unchecked(&rsp->expedited_done_exit));
84416 return 0;
84417 }
84418
84419diff --git a/kernel/resource.c b/kernel/resource.c
84420index 3f285dc..5755f62 100644
84421--- a/kernel/resource.c
84422+++ b/kernel/resource.c
84423@@ -152,8 +152,18 @@ static const struct file_operations proc_iomem_operations = {
84424
84425 static int __init ioresources_init(void)
84426 {
84427+#ifdef CONFIG_GRKERNSEC_PROC_ADD
84428+#ifdef CONFIG_GRKERNSEC_PROC_USER
84429+ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
84430+ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
84431+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
84432+ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
84433+ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
84434+#endif
84435+#else
84436 proc_create("ioports", 0, NULL, &proc_ioports_operations);
84437 proc_create("iomem", 0, NULL, &proc_iomem_operations);
84438+#endif
84439 return 0;
84440 }
84441 __initcall(ioresources_init);
84442diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
84443index 1d96dd0..994ff19 100644
84444--- a/kernel/rtmutex-tester.c
84445+++ b/kernel/rtmutex-tester.c
84446@@ -22,7 +22,7 @@
84447 #define MAX_RT_TEST_MUTEXES 8
84448
84449 static spinlock_t rttest_lock;
84450-static atomic_t rttest_event;
84451+static atomic_unchecked_t rttest_event;
84452
84453 struct test_thread_data {
84454 int opcode;
84455@@ -63,7 +63,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
84456
84457 case RTTEST_LOCKCONT:
84458 td->mutexes[td->opdata] = 1;
84459- td->event = atomic_add_return(1, &rttest_event);
84460+ td->event = atomic_add_return_unchecked(1, &rttest_event);
84461 return 0;
84462
84463 case RTTEST_RESET:
84464@@ -76,7 +76,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
84465 return 0;
84466
84467 case RTTEST_RESETEVENT:
84468- atomic_set(&rttest_event, 0);
84469+ atomic_set_unchecked(&rttest_event, 0);
84470 return 0;
84471
84472 default:
84473@@ -93,9 +93,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
84474 return ret;
84475
84476 td->mutexes[id] = 1;
84477- td->event = atomic_add_return(1, &rttest_event);
84478+ td->event = atomic_add_return_unchecked(1, &rttest_event);
84479 rt_mutex_lock(&mutexes[id]);
84480- td->event = atomic_add_return(1, &rttest_event);
84481+ td->event = atomic_add_return_unchecked(1, &rttest_event);
84482 td->mutexes[id] = 4;
84483 return 0;
84484
84485@@ -106,9 +106,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
84486 return ret;
84487
84488 td->mutexes[id] = 1;
84489- td->event = atomic_add_return(1, &rttest_event);
84490+ td->event = atomic_add_return_unchecked(1, &rttest_event);
84491 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
84492- td->event = atomic_add_return(1, &rttest_event);
84493+ td->event = atomic_add_return_unchecked(1, &rttest_event);
84494 td->mutexes[id] = ret ? 0 : 4;
84495 return ret ? -EINTR : 0;
84496
84497@@ -117,9 +117,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
84498 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
84499 return ret;
84500
84501- td->event = atomic_add_return(1, &rttest_event);
84502+ td->event = atomic_add_return_unchecked(1, &rttest_event);
84503 rt_mutex_unlock(&mutexes[id]);
84504- td->event = atomic_add_return(1, &rttest_event);
84505+ td->event = atomic_add_return_unchecked(1, &rttest_event);
84506 td->mutexes[id] = 0;
84507 return 0;
84508
84509@@ -166,7 +166,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
84510 break;
84511
84512 td->mutexes[dat] = 2;
84513- td->event = atomic_add_return(1, &rttest_event);
84514+ td->event = atomic_add_return_unchecked(1, &rttest_event);
84515 break;
84516
84517 default:
84518@@ -186,7 +186,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
84519 return;
84520
84521 td->mutexes[dat] = 3;
84522- td->event = atomic_add_return(1, &rttest_event);
84523+ td->event = atomic_add_return_unchecked(1, &rttest_event);
84524 break;
84525
84526 case RTTEST_LOCKNOWAIT:
84527@@ -198,7 +198,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
84528 return;
84529
84530 td->mutexes[dat] = 1;
84531- td->event = atomic_add_return(1, &rttest_event);
84532+ td->event = atomic_add_return_unchecked(1, &rttest_event);
84533 return;
84534
84535 default:
84536diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
84537index 4a07353..66b5291 100644
84538--- a/kernel/sched/auto_group.c
84539+++ b/kernel/sched/auto_group.c
84540@@ -11,7 +11,7 @@
84541
84542 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
84543 static struct autogroup autogroup_default;
84544-static atomic_t autogroup_seq_nr;
84545+static atomic_unchecked_t autogroup_seq_nr;
84546
84547 void __init autogroup_init(struct task_struct *init_task)
84548 {
84549@@ -79,7 +79,7 @@ static inline struct autogroup *autogroup_create(void)
84550
84551 kref_init(&ag->kref);
84552 init_rwsem(&ag->lock);
84553- ag->id = atomic_inc_return(&autogroup_seq_nr);
84554+ ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
84555 ag->tg = tg;
84556 #ifdef CONFIG_RT_GROUP_SCHED
84557 /*
84558diff --git a/kernel/sched/core.c b/kernel/sched/core.c
84559index 5ac63c9..d912786 100644
84560--- a/kernel/sched/core.c
84561+++ b/kernel/sched/core.c
84562@@ -2868,7 +2868,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible);
84563 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
84564 * or number of jiffies left till timeout) if completed.
84565 */
84566-long __sched
84567+long __sched __intentional_overflow(-1)
84568 wait_for_completion_interruptible_timeout(struct completion *x,
84569 unsigned long timeout)
84570 {
84571@@ -2885,7 +2885,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible_timeout);
84572 *
84573 * Return: -ERESTARTSYS if interrupted, 0 if completed.
84574 */
84575-int __sched wait_for_completion_killable(struct completion *x)
84576+int __sched __intentional_overflow(-1) wait_for_completion_killable(struct completion *x)
84577 {
84578 long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE);
84579 if (t == -ERESTARTSYS)
84580@@ -2906,7 +2906,7 @@ EXPORT_SYMBOL(wait_for_completion_killable);
84581 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
84582 * or number of jiffies left till timeout) if completed.
84583 */
84584-long __sched
84585+long __sched __intentional_overflow(-1)
84586 wait_for_completion_killable_timeout(struct completion *x,
84587 unsigned long timeout)
84588 {
84589@@ -3132,6 +3132,8 @@ int can_nice(const struct task_struct *p, const int nice)
84590 /* convert nice value [19,-20] to rlimit style value [1,40] */
84591 int nice_rlim = 20 - nice;
84592
84593+ gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
84594+
84595 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
84596 capable(CAP_SYS_NICE));
84597 }
84598@@ -3165,7 +3167,8 @@ SYSCALL_DEFINE1(nice, int, increment)
84599 if (nice > 19)
84600 nice = 19;
84601
84602- if (increment < 0 && !can_nice(current, nice))
84603+ if (increment < 0 && (!can_nice(current, nice) ||
84604+ gr_handle_chroot_nice()))
84605 return -EPERM;
84606
84607 retval = security_task_setnice(current, nice);
84608@@ -3327,6 +3330,7 @@ recheck:
84609 unsigned long rlim_rtprio =
84610 task_rlimit(p, RLIMIT_RTPRIO);
84611
84612+ gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
84613 /* can't set/change the rt policy */
84614 if (policy != p->policy && !rlim_rtprio)
84615 return -EPERM;
84616@@ -4456,7 +4460,7 @@ static void migrate_tasks(unsigned int dead_cpu)
84617
84618 #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL)
84619
84620-static struct ctl_table sd_ctl_dir[] = {
84621+static ctl_table_no_const sd_ctl_dir[] __read_only = {
84622 {
84623 .procname = "sched_domain",
84624 .mode = 0555,
84625@@ -4473,17 +4477,17 @@ static struct ctl_table sd_ctl_root[] = {
84626 {}
84627 };
84628
84629-static struct ctl_table *sd_alloc_ctl_entry(int n)
84630+static ctl_table_no_const *sd_alloc_ctl_entry(int n)
84631 {
84632- struct ctl_table *entry =
84633+ ctl_table_no_const *entry =
84634 kcalloc(n, sizeof(struct ctl_table), GFP_KERNEL);
84635
84636 return entry;
84637 }
84638
84639-static void sd_free_ctl_entry(struct ctl_table **tablep)
84640+static void sd_free_ctl_entry(ctl_table_no_const *tablep)
84641 {
84642- struct ctl_table *entry;
84643+ ctl_table_no_const *entry;
84644
84645 /*
84646 * In the intermediate directories, both the child directory and
84647@@ -4491,22 +4495,25 @@ static void sd_free_ctl_entry(struct ctl_table **tablep)
84648 * will always be set. In the lowest directory the names are
84649 * static strings and all have proc handlers.
84650 */
84651- for (entry = *tablep; entry->mode; entry++) {
84652- if (entry->child)
84653- sd_free_ctl_entry(&entry->child);
84654+ for (entry = tablep; entry->mode; entry++) {
84655+ if (entry->child) {
84656+ sd_free_ctl_entry(entry->child);
84657+ pax_open_kernel();
84658+ entry->child = NULL;
84659+ pax_close_kernel();
84660+ }
84661 if (entry->proc_handler == NULL)
84662 kfree(entry->procname);
84663 }
84664
84665- kfree(*tablep);
84666- *tablep = NULL;
84667+ kfree(tablep);
84668 }
84669
84670 static int min_load_idx = 0;
84671 static int max_load_idx = CPU_LOAD_IDX_MAX-1;
84672
84673 static void
84674-set_table_entry(struct ctl_table *entry,
84675+set_table_entry(ctl_table_no_const *entry,
84676 const char *procname, void *data, int maxlen,
84677 umode_t mode, proc_handler *proc_handler,
84678 bool load_idx)
84679@@ -4526,7 +4533,7 @@ set_table_entry(struct ctl_table *entry,
84680 static struct ctl_table *
84681 sd_alloc_ctl_domain_table(struct sched_domain *sd)
84682 {
84683- struct ctl_table *table = sd_alloc_ctl_entry(13);
84684+ ctl_table_no_const *table = sd_alloc_ctl_entry(13);
84685
84686 if (table == NULL)
84687 return NULL;
84688@@ -4561,9 +4568,9 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
84689 return table;
84690 }
84691
84692-static struct ctl_table *sd_alloc_ctl_cpu_table(int cpu)
84693+static ctl_table_no_const *sd_alloc_ctl_cpu_table(int cpu)
84694 {
84695- struct ctl_table *entry, *table;
84696+ ctl_table_no_const *entry, *table;
84697 struct sched_domain *sd;
84698 int domain_num = 0, i;
84699 char buf[32];
84700@@ -4590,11 +4597,13 @@ static struct ctl_table_header *sd_sysctl_header;
84701 static void register_sched_domain_sysctl(void)
84702 {
84703 int i, cpu_num = num_possible_cpus();
84704- struct ctl_table *entry = sd_alloc_ctl_entry(cpu_num + 1);
84705+ ctl_table_no_const *entry = sd_alloc_ctl_entry(cpu_num + 1);
84706 char buf[32];
84707
84708 WARN_ON(sd_ctl_dir[0].child);
84709+ pax_open_kernel();
84710 sd_ctl_dir[0].child = entry;
84711+ pax_close_kernel();
84712
84713 if (entry == NULL)
84714 return;
84715@@ -4617,8 +4626,12 @@ static void unregister_sched_domain_sysctl(void)
84716 if (sd_sysctl_header)
84717 unregister_sysctl_table(sd_sysctl_header);
84718 sd_sysctl_header = NULL;
84719- if (sd_ctl_dir[0].child)
84720- sd_free_ctl_entry(&sd_ctl_dir[0].child);
84721+ if (sd_ctl_dir[0].child) {
84722+ sd_free_ctl_entry(sd_ctl_dir[0].child);
84723+ pax_open_kernel();
84724+ sd_ctl_dir[0].child = NULL;
84725+ pax_close_kernel();
84726+ }
84727 }
84728 #else
84729 static void register_sched_domain_sysctl(void)
84730diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
84731index 7c70201..23f52b6 100644
84732--- a/kernel/sched/fair.c
84733+++ b/kernel/sched/fair.c
84734@@ -869,7 +869,7 @@ void task_numa_fault(int node, int pages, bool migrated)
84735
84736 static void reset_ptenuma_scan(struct task_struct *p)
84737 {
84738- ACCESS_ONCE(p->mm->numa_scan_seq)++;
84739+ ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
84740 p->mm->numa_scan_offset = 0;
84741 }
84742
84743@@ -5838,7 +5838,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
84744 * run_rebalance_domains is triggered when needed from the scheduler tick.
84745 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
84746 */
84747-static void run_rebalance_domains(struct softirq_action *h)
84748+static __latent_entropy void run_rebalance_domains(void)
84749 {
84750 int this_cpu = smp_processor_id();
84751 struct rq *this_rq = cpu_rq(this_cpu);
84752diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
84753index b3c5653..a4d192a 100644
84754--- a/kernel/sched/sched.h
84755+++ b/kernel/sched/sched.h
84756@@ -1004,7 +1004,7 @@ struct sched_class {
84757 #ifdef CONFIG_FAIR_GROUP_SCHED
84758 void (*task_move_group) (struct task_struct *p, int on_rq);
84759 #endif
84760-};
84761+} __do_const;
84762
84763 #define sched_class_highest (&stop_sched_class)
84764 #define for_each_class(class) \
84765diff --git a/kernel/signal.c b/kernel/signal.c
84766index ded28b9..6886c08 100644
84767--- a/kernel/signal.c
84768+++ b/kernel/signal.c
84769@@ -51,12 +51,12 @@ static struct kmem_cache *sigqueue_cachep;
84770
84771 int print_fatal_signals __read_mostly;
84772
84773-static void __user *sig_handler(struct task_struct *t, int sig)
84774+static __sighandler_t sig_handler(struct task_struct *t, int sig)
84775 {
84776 return t->sighand->action[sig - 1].sa.sa_handler;
84777 }
84778
84779-static int sig_handler_ignored(void __user *handler, int sig)
84780+static int sig_handler_ignored(__sighandler_t handler, int sig)
84781 {
84782 /* Is it explicitly or implicitly ignored? */
84783 return handler == SIG_IGN ||
84784@@ -65,7 +65,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
84785
84786 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
84787 {
84788- void __user *handler;
84789+ __sighandler_t handler;
84790
84791 handler = sig_handler(t, sig);
84792
84793@@ -369,6 +369,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
84794 atomic_inc(&user->sigpending);
84795 rcu_read_unlock();
84796
84797+ if (!override_rlimit)
84798+ gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
84799+
84800 if (override_rlimit ||
84801 atomic_read(&user->sigpending) <=
84802 task_rlimit(t, RLIMIT_SIGPENDING)) {
84803@@ -496,7 +499,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
84804
84805 int unhandled_signal(struct task_struct *tsk, int sig)
84806 {
84807- void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
84808+ __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
84809 if (is_global_init(tsk))
84810 return 1;
84811 if (handler != SIG_IGN && handler != SIG_DFL)
84812@@ -816,6 +819,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
84813 }
84814 }
84815
84816+ /* allow glibc communication via tgkill to other threads in our
84817+ thread group */
84818+ if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
84819+ sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
84820+ && gr_handle_signal(t, sig))
84821+ return -EPERM;
84822+
84823 return security_task_kill(t, info, sig, 0);
84824 }
84825
84826@@ -1199,7 +1209,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
84827 return send_signal(sig, info, p, 1);
84828 }
84829
84830-static int
84831+int
84832 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
84833 {
84834 return send_signal(sig, info, t, 0);
84835@@ -1236,6 +1246,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
84836 unsigned long int flags;
84837 int ret, blocked, ignored;
84838 struct k_sigaction *action;
84839+ int is_unhandled = 0;
84840
84841 spin_lock_irqsave(&t->sighand->siglock, flags);
84842 action = &t->sighand->action[sig-1];
84843@@ -1250,9 +1261,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
84844 }
84845 if (action->sa.sa_handler == SIG_DFL)
84846 t->signal->flags &= ~SIGNAL_UNKILLABLE;
84847+ if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
84848+ is_unhandled = 1;
84849 ret = specific_send_sig_info(sig, info, t);
84850 spin_unlock_irqrestore(&t->sighand->siglock, flags);
84851
84852+ /* only deal with unhandled signals, java etc trigger SIGSEGV during
84853+ normal operation */
84854+ if (is_unhandled) {
84855+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
84856+ gr_handle_crash(t, sig);
84857+ }
84858+
84859 return ret;
84860 }
84861
84862@@ -1319,8 +1339,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
84863 ret = check_kill_permission(sig, info, p);
84864 rcu_read_unlock();
84865
84866- if (!ret && sig)
84867+ if (!ret && sig) {
84868 ret = do_send_sig_info(sig, info, p, true);
84869+ if (!ret)
84870+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
84871+ }
84872
84873 return ret;
84874 }
84875@@ -2926,7 +2949,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
84876 int error = -ESRCH;
84877
84878 rcu_read_lock();
84879- p = find_task_by_vpid(pid);
84880+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
84881+ /* allow glibc communication via tgkill to other threads in our
84882+ thread group */
84883+ if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
84884+ sig == (SIGRTMIN+1) && tgid == info->si_pid)
84885+ p = find_task_by_vpid_unrestricted(pid);
84886+ else
84887+#endif
84888+ p = find_task_by_vpid(pid);
84889 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
84890 error = check_kill_permission(sig, info, p);
84891 /*
84892@@ -3240,8 +3271,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
84893 }
84894 seg = get_fs();
84895 set_fs(KERNEL_DS);
84896- ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
84897- (stack_t __force __user *) &uoss,
84898+ ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
84899+ (stack_t __force_user *) &uoss,
84900 compat_user_stack_pointer());
84901 set_fs(seg);
84902 if (ret >= 0 && uoss_ptr) {
84903diff --git a/kernel/smpboot.c b/kernel/smpboot.c
84904index eb89e18..a4e6792 100644
84905--- a/kernel/smpboot.c
84906+++ b/kernel/smpboot.c
84907@@ -288,7 +288,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
84908 }
84909 smpboot_unpark_thread(plug_thread, cpu);
84910 }
84911- list_add(&plug_thread->list, &hotplug_threads);
84912+ pax_list_add(&plug_thread->list, &hotplug_threads);
84913 out:
84914 mutex_unlock(&smpboot_threads_lock);
84915 return ret;
84916@@ -305,7 +305,7 @@ void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread)
84917 {
84918 get_online_cpus();
84919 mutex_lock(&smpboot_threads_lock);
84920- list_del(&plug_thread->list);
84921+ pax_list_del(&plug_thread->list);
84922 smpboot_destroy_threads(plug_thread);
84923 mutex_unlock(&smpboot_threads_lock);
84924 put_online_cpus();
84925diff --git a/kernel/softirq.c b/kernel/softirq.c
84926index d7d498d..94fe0f7 100644
84927--- a/kernel/softirq.c
84928+++ b/kernel/softirq.c
84929@@ -53,11 +53,11 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
84930 EXPORT_SYMBOL(irq_stat);
84931 #endif
84932
84933-static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
84934+static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
84935
84936 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
84937
84938-char *softirq_to_name[NR_SOFTIRQS] = {
84939+const char * const softirq_to_name[NR_SOFTIRQS] = {
84940 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
84941 "TASKLET", "SCHED", "HRTIMER", "RCU"
84942 };
84943@@ -248,7 +248,7 @@ restart:
84944 kstat_incr_softirqs_this_cpu(vec_nr);
84945
84946 trace_softirq_entry(vec_nr);
84947- h->action(h);
84948+ h->action();
84949 trace_softirq_exit(vec_nr);
84950 if (unlikely(prev_count != preempt_count())) {
84951 printk(KERN_ERR "huh, entered softirq %u %s %p"
84952@@ -412,7 +412,7 @@ void __raise_softirq_irqoff(unsigned int nr)
84953 or_softirq_pending(1UL << nr);
84954 }
84955
84956-void open_softirq(int nr, void (*action)(struct softirq_action *))
84957+void __init open_softirq(int nr, void (*action)(void))
84958 {
84959 softirq_vec[nr].action = action;
84960 }
84961@@ -468,7 +468,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
84962
84963 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
84964
84965-static void tasklet_action(struct softirq_action *a)
84966+static __latent_entropy void tasklet_action(void)
84967 {
84968 struct tasklet_struct *list;
84969
84970@@ -503,7 +503,7 @@ static void tasklet_action(struct softirq_action *a)
84971 }
84972 }
84973
84974-static void tasklet_hi_action(struct softirq_action *a)
84975+static __latent_entropy void tasklet_hi_action(void)
84976 {
84977 struct tasklet_struct *list;
84978
84979@@ -858,7 +858,7 @@ static struct notifier_block cpu_nfb = {
84980 .notifier_call = cpu_callback
84981 };
84982
84983-static struct smp_hotplug_thread softirq_threads = {
84984+static struct smp_hotplug_thread softirq_threads __read_only = {
84985 .store = &ksoftirqd,
84986 .thread_should_run = ksoftirqd_should_run,
84987 .thread_fn = run_ksoftirqd,
84988diff --git a/kernel/srcu.c b/kernel/srcu.c
84989index 01d5ccb..cdcbee6 100644
84990--- a/kernel/srcu.c
84991+++ b/kernel/srcu.c
84992@@ -300,9 +300,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
84993
84994 idx = ACCESS_ONCE(sp->completed) & 0x1;
84995 preempt_disable();
84996- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
84997+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
84998 smp_mb(); /* B */ /* Avoid leaking the critical section. */
84999- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
85000+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
85001 preempt_enable();
85002 return idx;
85003 }
85004diff --git a/kernel/sys.c b/kernel/sys.c
85005index c18ecca..b3c2dd2 100644
85006--- a/kernel/sys.c
85007+++ b/kernel/sys.c
85008@@ -149,6 +149,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
85009 error = -EACCES;
85010 goto out;
85011 }
85012+
85013+ if (gr_handle_chroot_setpriority(p, niceval)) {
85014+ error = -EACCES;
85015+ goto out;
85016+ }
85017+
85018 no_nice = security_task_setnice(p, niceval);
85019 if (no_nice) {
85020 error = no_nice;
85021@@ -352,6 +358,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
85022 goto error;
85023 }
85024
85025+ if (gr_check_group_change(new->gid, new->egid, INVALID_GID))
85026+ goto error;
85027+
85028 if (rgid != (gid_t) -1 ||
85029 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
85030 new->sgid = new->egid;
85031@@ -387,6 +396,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
85032 old = current_cred();
85033
85034 retval = -EPERM;
85035+
85036+ if (gr_check_group_change(kgid, kgid, kgid))
85037+ goto error;
85038+
85039 if (ns_capable(old->user_ns, CAP_SETGID))
85040 new->gid = new->egid = new->sgid = new->fsgid = kgid;
85041 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
85042@@ -404,7 +417,7 @@ error:
85043 /*
85044 * change the user struct in a credentials set to match the new UID
85045 */
85046-static int set_user(struct cred *new)
85047+int set_user(struct cred *new)
85048 {
85049 struct user_struct *new_user;
85050
85051@@ -484,6 +497,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
85052 goto error;
85053 }
85054
85055+ if (gr_check_user_change(new->uid, new->euid, INVALID_UID))
85056+ goto error;
85057+
85058 if (!uid_eq(new->uid, old->uid)) {
85059 retval = set_user(new);
85060 if (retval < 0)
85061@@ -534,6 +550,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
85062 old = current_cred();
85063
85064 retval = -EPERM;
85065+
85066+ if (gr_check_crash_uid(kuid))
85067+ goto error;
85068+ if (gr_check_user_change(kuid, kuid, kuid))
85069+ goto error;
85070+
85071 if (ns_capable(old->user_ns, CAP_SETUID)) {
85072 new->suid = new->uid = kuid;
85073 if (!uid_eq(kuid, old->uid)) {
85074@@ -603,6 +625,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
85075 goto error;
85076 }
85077
85078+ if (gr_check_user_change(kruid, keuid, INVALID_UID))
85079+ goto error;
85080+
85081 if (ruid != (uid_t) -1) {
85082 new->uid = kruid;
85083 if (!uid_eq(kruid, old->uid)) {
85084@@ -685,6 +710,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
85085 goto error;
85086 }
85087
85088+ if (gr_check_group_change(krgid, kegid, INVALID_GID))
85089+ goto error;
85090+
85091 if (rgid != (gid_t) -1)
85092 new->gid = krgid;
85093 if (egid != (gid_t) -1)
85094@@ -746,12 +774,16 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
85095 uid_eq(kuid, old->suid) || uid_eq(kuid, old->fsuid) ||
85096 ns_capable(old->user_ns, CAP_SETUID)) {
85097 if (!uid_eq(kuid, old->fsuid)) {
85098+ if (gr_check_user_change(INVALID_UID, INVALID_UID, kuid))
85099+ goto error;
85100+
85101 new->fsuid = kuid;
85102 if (security_task_fix_setuid(new, old, LSM_SETID_FS) == 0)
85103 goto change_okay;
85104 }
85105 }
85106
85107+error:
85108 abort_creds(new);
85109 return old_fsuid;
85110
85111@@ -784,12 +816,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
85112 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
85113 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
85114 ns_capable(old->user_ns, CAP_SETGID)) {
85115+ if (gr_check_group_change(INVALID_GID, INVALID_GID, kgid))
85116+ goto error;
85117+
85118 if (!gid_eq(kgid, old->fsgid)) {
85119 new->fsgid = kgid;
85120 goto change_okay;
85121 }
85122 }
85123
85124+error:
85125 abort_creds(new);
85126 return old_fsgid;
85127
85128@@ -1169,19 +1205,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
85129 return -EFAULT;
85130
85131 down_read(&uts_sem);
85132- error = __copy_to_user(&name->sysname, &utsname()->sysname,
85133+ error = __copy_to_user(name->sysname, &utsname()->sysname,
85134 __OLD_UTS_LEN);
85135 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
85136- error |= __copy_to_user(&name->nodename, &utsname()->nodename,
85137+ error |= __copy_to_user(name->nodename, &utsname()->nodename,
85138 __OLD_UTS_LEN);
85139 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
85140- error |= __copy_to_user(&name->release, &utsname()->release,
85141+ error |= __copy_to_user(name->release, &utsname()->release,
85142 __OLD_UTS_LEN);
85143 error |= __put_user(0, name->release + __OLD_UTS_LEN);
85144- error |= __copy_to_user(&name->version, &utsname()->version,
85145+ error |= __copy_to_user(name->version, &utsname()->version,
85146 __OLD_UTS_LEN);
85147 error |= __put_user(0, name->version + __OLD_UTS_LEN);
85148- error |= __copy_to_user(&name->machine, &utsname()->machine,
85149+ error |= __copy_to_user(name->machine, &utsname()->machine,
85150 __OLD_UTS_LEN);
85151 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
85152 up_read(&uts_sem);
85153@@ -1383,6 +1419,13 @@ int do_prlimit(struct task_struct *tsk, unsigned int resource,
85154 */
85155 new_rlim->rlim_cur = 1;
85156 }
85157+ /* Handle the case where a fork and setuid occur and then RLIMIT_NPROC
85158+ is changed to a lower value. Since tasks can be created by the same
85159+ user in between this limit change and an execve by this task, force
85160+ a recheck only for this task by setting PF_NPROC_EXCEEDED
85161+ */
85162+ if (resource == RLIMIT_NPROC && tsk->real_cred->user != INIT_USER)
85163+ tsk->flags |= PF_NPROC_EXCEEDED;
85164 }
85165 if (!retval) {
85166 if (old_rlim)
85167diff --git a/kernel/sysctl.c b/kernel/sysctl.c
85168index b2f06f3..e6354ab 100644
85169--- a/kernel/sysctl.c
85170+++ b/kernel/sysctl.c
85171@@ -93,7 +93,6 @@
85172
85173
85174 #if defined(CONFIG_SYSCTL)
85175-
85176 /* External variables not in a header file. */
85177 extern int sysctl_overcommit_memory;
85178 extern int sysctl_overcommit_ratio;
85179@@ -119,17 +118,18 @@ extern int blk_iopoll_enabled;
85180
85181 /* Constants used for minimum and maximum */
85182 #ifdef CONFIG_LOCKUP_DETECTOR
85183-static int sixty = 60;
85184+static int sixty __read_only = 60;
85185 #endif
85186
85187-static int zero;
85188-static int __maybe_unused one = 1;
85189-static int __maybe_unused two = 2;
85190-static int __maybe_unused three = 3;
85191-static unsigned long one_ul = 1;
85192-static int one_hundred = 100;
85193+static int neg_one __read_only = -1;
85194+static int zero __read_only = 0;
85195+static int __maybe_unused one __read_only = 1;
85196+static int __maybe_unused two __read_only = 2;
85197+static int __maybe_unused three __read_only = 3;
85198+static unsigned long one_ul __read_only = 1;
85199+static int one_hundred __read_only = 100;
85200 #ifdef CONFIG_PRINTK
85201-static int ten_thousand = 10000;
85202+static int ten_thousand __read_only = 10000;
85203 #endif
85204
85205 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
85206@@ -176,10 +176,8 @@ static int proc_taint(struct ctl_table *table, int write,
85207 void __user *buffer, size_t *lenp, loff_t *ppos);
85208 #endif
85209
85210-#ifdef CONFIG_PRINTK
85211 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
85212 void __user *buffer, size_t *lenp, loff_t *ppos);
85213-#endif
85214
85215 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
85216 void __user *buffer, size_t *lenp, loff_t *ppos);
85217@@ -210,6 +208,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
85218
85219 #endif
85220
85221+extern struct ctl_table grsecurity_table[];
85222+
85223 static struct ctl_table kern_table[];
85224 static struct ctl_table vm_table[];
85225 static struct ctl_table fs_table[];
85226@@ -224,6 +224,20 @@ extern struct ctl_table epoll_table[];
85227 int sysctl_legacy_va_layout;
85228 #endif
85229
85230+#ifdef CONFIG_PAX_SOFTMODE
85231+static ctl_table pax_table[] = {
85232+ {
85233+ .procname = "softmode",
85234+ .data = &pax_softmode,
85235+ .maxlen = sizeof(unsigned int),
85236+ .mode = 0600,
85237+ .proc_handler = &proc_dointvec,
85238+ },
85239+
85240+ { }
85241+};
85242+#endif
85243+
85244 /* The default sysctl tables: */
85245
85246 static struct ctl_table sysctl_base_table[] = {
85247@@ -272,6 +286,22 @@ static int max_extfrag_threshold = 1000;
85248 #endif
85249
85250 static struct ctl_table kern_table[] = {
85251+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
85252+ {
85253+ .procname = "grsecurity",
85254+ .mode = 0500,
85255+ .child = grsecurity_table,
85256+ },
85257+#endif
85258+
85259+#ifdef CONFIG_PAX_SOFTMODE
85260+ {
85261+ .procname = "pax",
85262+ .mode = 0500,
85263+ .child = pax_table,
85264+ },
85265+#endif
85266+
85267 {
85268 .procname = "sched_child_runs_first",
85269 .data = &sysctl_sched_child_runs_first,
85270@@ -613,7 +643,7 @@ static struct ctl_table kern_table[] = {
85271 .data = &modprobe_path,
85272 .maxlen = KMOD_PATH_LEN,
85273 .mode = 0644,
85274- .proc_handler = proc_dostring,
85275+ .proc_handler = proc_dostring_modpriv,
85276 },
85277 {
85278 .procname = "modules_disabled",
85279@@ -780,16 +810,20 @@ static struct ctl_table kern_table[] = {
85280 .extra1 = &zero,
85281 .extra2 = &one,
85282 },
85283+#endif
85284 {
85285 .procname = "kptr_restrict",
85286 .data = &kptr_restrict,
85287 .maxlen = sizeof(int),
85288 .mode = 0644,
85289 .proc_handler = proc_dointvec_minmax_sysadmin,
85290+#ifdef CONFIG_GRKERNSEC_HIDESYM
85291+ .extra1 = &two,
85292+#else
85293 .extra1 = &zero,
85294+#endif
85295 .extra2 = &two,
85296 },
85297-#endif
85298 {
85299 .procname = "ngroups_max",
85300 .data = &ngroups_max,
85301@@ -1031,10 +1065,17 @@ static struct ctl_table kern_table[] = {
85302 */
85303 {
85304 .procname = "perf_event_paranoid",
85305- .data = &sysctl_perf_event_paranoid,
85306- .maxlen = sizeof(sysctl_perf_event_paranoid),
85307+ .data = &sysctl_perf_event_legitimately_concerned,
85308+ .maxlen = sizeof(sysctl_perf_event_legitimately_concerned),
85309 .mode = 0644,
85310- .proc_handler = proc_dointvec,
85311+ /* go ahead, be a hero */
85312+ .proc_handler = proc_dointvec_minmax_sysadmin,
85313+ .extra1 = &neg_one,
85314+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
85315+ .extra2 = &three,
85316+#else
85317+ .extra2 = &two,
85318+#endif
85319 },
85320 {
85321 .procname = "perf_event_mlock_kb",
85322@@ -1297,6 +1338,13 @@ static struct ctl_table vm_table[] = {
85323 .proc_handler = proc_dointvec_minmax,
85324 .extra1 = &zero,
85325 },
85326+ {
85327+ .procname = "heap_stack_gap",
85328+ .data = &sysctl_heap_stack_gap,
85329+ .maxlen = sizeof(sysctl_heap_stack_gap),
85330+ .mode = 0644,
85331+ .proc_handler = proc_doulongvec_minmax,
85332+ },
85333 #else
85334 {
85335 .procname = "nr_trim_pages",
85336@@ -1761,6 +1809,16 @@ int proc_dostring(struct ctl_table *table, int write,
85337 buffer, lenp, ppos);
85338 }
85339
85340+int proc_dostring_modpriv(struct ctl_table *table, int write,
85341+ void __user *buffer, size_t *lenp, loff_t *ppos)
85342+{
85343+ if (write && !capable(CAP_SYS_MODULE))
85344+ return -EPERM;
85345+
85346+ return _proc_do_string(table->data, table->maxlen, write,
85347+ buffer, lenp, ppos);
85348+}
85349+
85350 static size_t proc_skip_spaces(char **buf)
85351 {
85352 size_t ret;
85353@@ -1866,6 +1924,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
85354 len = strlen(tmp);
85355 if (len > *size)
85356 len = *size;
85357+ if (len > sizeof(tmp))
85358+ len = sizeof(tmp);
85359 if (copy_to_user(*buf, tmp, len))
85360 return -EFAULT;
85361 *size -= len;
85362@@ -2030,7 +2090,7 @@ int proc_dointvec(struct ctl_table *table, int write,
85363 static int proc_taint(struct ctl_table *table, int write,
85364 void __user *buffer, size_t *lenp, loff_t *ppos)
85365 {
85366- struct ctl_table t;
85367+ ctl_table_no_const t;
85368 unsigned long tmptaint = get_taint();
85369 int err;
85370
85371@@ -2058,7 +2118,6 @@ static int proc_taint(struct ctl_table *table, int write,
85372 return err;
85373 }
85374
85375-#ifdef CONFIG_PRINTK
85376 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
85377 void __user *buffer, size_t *lenp, loff_t *ppos)
85378 {
85379@@ -2067,7 +2126,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
85380
85381 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
85382 }
85383-#endif
85384
85385 struct do_proc_dointvec_minmax_conv_param {
85386 int *min;
85387@@ -2214,8 +2272,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
85388 *i = val;
85389 } else {
85390 val = convdiv * (*i) / convmul;
85391- if (!first)
85392+ if (!first) {
85393 err = proc_put_char(&buffer, &left, '\t');
85394+ if (err)
85395+ break;
85396+ }
85397 err = proc_put_long(&buffer, &left, val, false);
85398 if (err)
85399 break;
85400@@ -2611,6 +2672,12 @@ int proc_dostring(struct ctl_table *table, int write,
85401 return -ENOSYS;
85402 }
85403
85404+int proc_dostring_modpriv(struct ctl_table *table, int write,
85405+ void __user *buffer, size_t *lenp, loff_t *ppos)
85406+{
85407+ return -ENOSYS;
85408+}
85409+
85410 int proc_dointvec(struct ctl_table *table, int write,
85411 void __user *buffer, size_t *lenp, loff_t *ppos)
85412 {
85413@@ -2667,5 +2734,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
85414 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
85415 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
85416 EXPORT_SYMBOL(proc_dostring);
85417+EXPORT_SYMBOL(proc_dostring_modpriv);
85418 EXPORT_SYMBOL(proc_doulongvec_minmax);
85419 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
85420diff --git a/kernel/taskstats.c b/kernel/taskstats.c
85421index 145bb4d..b2aa969 100644
85422--- a/kernel/taskstats.c
85423+++ b/kernel/taskstats.c
85424@@ -28,9 +28,12 @@
85425 #include <linux/fs.h>
85426 #include <linux/file.h>
85427 #include <linux/pid_namespace.h>
85428+#include <linux/grsecurity.h>
85429 #include <net/genetlink.h>
85430 #include <linux/atomic.h>
85431
85432+extern int gr_is_taskstats_denied(int pid);
85433+
85434 /*
85435 * Maximum length of a cpumask that can be specified in
85436 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
85437@@ -570,6 +573,9 @@ err:
85438
85439 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
85440 {
85441+ if (gr_is_taskstats_denied(current->pid))
85442+ return -EACCES;
85443+
85444 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
85445 return cmd_attr_register_cpumask(info);
85446 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
85447diff --git a/kernel/time.c b/kernel/time.c
85448index 7c7964c..2a0d412 100644
85449--- a/kernel/time.c
85450+++ b/kernel/time.c
85451@@ -172,6 +172,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
85452 return error;
85453
85454 if (tz) {
85455+ /* we log in do_settimeofday called below, so don't log twice
85456+ */
85457+ if (!tv)
85458+ gr_log_timechange();
85459+
85460 sys_tz = *tz;
85461 update_vsyscall_tz();
85462 if (firsttime) {
85463diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
85464index eec50fc..65e5df6 100644
85465--- a/kernel/time/alarmtimer.c
85466+++ b/kernel/time/alarmtimer.c
85467@@ -795,7 +795,7 @@ static int __init alarmtimer_init(void)
85468 struct platform_device *pdev;
85469 int error = 0;
85470 int i;
85471- struct k_clock alarm_clock = {
85472+ static struct k_clock alarm_clock = {
85473 .clock_getres = alarm_clock_getres,
85474 .clock_get = alarm_clock_get,
85475 .timer_create = alarm_timer_create,
85476diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
85477index 947ba25..20cbade 100644
85478--- a/kernel/time/timekeeping.c
85479+++ b/kernel/time/timekeeping.c
85480@@ -15,6 +15,7 @@
85481 #include <linux/init.h>
85482 #include <linux/mm.h>
85483 #include <linux/sched.h>
85484+#include <linux/grsecurity.h>
85485 #include <linux/syscore_ops.h>
85486 #include <linux/clocksource.h>
85487 #include <linux/jiffies.h>
85488@@ -500,6 +501,8 @@ int do_settimeofday(const struct timespec *tv)
85489 if (!timespec_valid_strict(tv))
85490 return -EINVAL;
85491
85492+ gr_log_timechange();
85493+
85494 raw_spin_lock_irqsave(&timekeeper_lock, flags);
85495 write_seqcount_begin(&timekeeper_seq);
85496
85497diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
85498index 61ed862..3b52c65 100644
85499--- a/kernel/time/timer_list.c
85500+++ b/kernel/time/timer_list.c
85501@@ -45,12 +45,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
85502
85503 static void print_name_offset(struct seq_file *m, void *sym)
85504 {
85505+#ifdef CONFIG_GRKERNSEC_HIDESYM
85506+ SEQ_printf(m, "<%p>", NULL);
85507+#else
85508 char symname[KSYM_NAME_LEN];
85509
85510 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
85511 SEQ_printf(m, "<%pK>", sym);
85512 else
85513 SEQ_printf(m, "%s", symname);
85514+#endif
85515 }
85516
85517 static void
85518@@ -119,7 +123,11 @@ next_one:
85519 static void
85520 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
85521 {
85522+#ifdef CONFIG_GRKERNSEC_HIDESYM
85523+ SEQ_printf(m, " .base: %p\n", NULL);
85524+#else
85525 SEQ_printf(m, " .base: %pK\n", base);
85526+#endif
85527 SEQ_printf(m, " .index: %d\n",
85528 base->index);
85529 SEQ_printf(m, " .resolution: %Lu nsecs\n",
85530@@ -362,7 +370,11 @@ static int __init init_timer_list_procfs(void)
85531 {
85532 struct proc_dir_entry *pe;
85533
85534+#ifdef CONFIG_GRKERNSEC_PROC_ADD
85535+ pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
85536+#else
85537 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
85538+#endif
85539 if (!pe)
85540 return -ENOMEM;
85541 return 0;
85542diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
85543index 0b537f2..40d6c20 100644
85544--- a/kernel/time/timer_stats.c
85545+++ b/kernel/time/timer_stats.c
85546@@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
85547 static unsigned long nr_entries;
85548 static struct entry entries[MAX_ENTRIES];
85549
85550-static atomic_t overflow_count;
85551+static atomic_unchecked_t overflow_count;
85552
85553 /*
85554 * The entries are in a hash-table, for fast lookup:
85555@@ -140,7 +140,7 @@ static void reset_entries(void)
85556 nr_entries = 0;
85557 memset(entries, 0, sizeof(entries));
85558 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
85559- atomic_set(&overflow_count, 0);
85560+ atomic_set_unchecked(&overflow_count, 0);
85561 }
85562
85563 static struct entry *alloc_entry(void)
85564@@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
85565 if (likely(entry))
85566 entry->count++;
85567 else
85568- atomic_inc(&overflow_count);
85569+ atomic_inc_unchecked(&overflow_count);
85570
85571 out_unlock:
85572 raw_spin_unlock_irqrestore(lock, flags);
85573@@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
85574
85575 static void print_name_offset(struct seq_file *m, unsigned long addr)
85576 {
85577+#ifdef CONFIG_GRKERNSEC_HIDESYM
85578+ seq_printf(m, "<%p>", NULL);
85579+#else
85580 char symname[KSYM_NAME_LEN];
85581
85582 if (lookup_symbol_name(addr, symname) < 0)
85583- seq_printf(m, "<%p>", (void *)addr);
85584+ seq_printf(m, "<%pK>", (void *)addr);
85585 else
85586 seq_printf(m, "%s", symname);
85587+#endif
85588 }
85589
85590 static int tstats_show(struct seq_file *m, void *v)
85591@@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
85592
85593 seq_puts(m, "Timer Stats Version: v0.2\n");
85594 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
85595- if (atomic_read(&overflow_count))
85596+ if (atomic_read_unchecked(&overflow_count))
85597 seq_printf(m, "Overflow: %d entries\n",
85598- atomic_read(&overflow_count));
85599+ atomic_read_unchecked(&overflow_count));
85600
85601 for (i = 0; i < nr_entries; i++) {
85602 entry = entries + i;
85603@@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
85604 {
85605 struct proc_dir_entry *pe;
85606
85607+#ifdef CONFIG_GRKERNSEC_PROC_ADD
85608+ pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
85609+#else
85610 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
85611+#endif
85612 if (!pe)
85613 return -ENOMEM;
85614 return 0;
85615diff --git a/kernel/timer.c b/kernel/timer.c
85616index 4296d13..0164b04 100644
85617--- a/kernel/timer.c
85618+++ b/kernel/timer.c
85619@@ -1366,7 +1366,7 @@ void update_process_times(int user_tick)
85620 /*
85621 * This function runs timers and the timer-tq in bottom half context.
85622 */
85623-static void run_timer_softirq(struct softirq_action *h)
85624+static __latent_entropy void run_timer_softirq(void)
85625 {
85626 struct tvec_base *base = __this_cpu_read(tvec_bases);
85627
85628@@ -1429,7 +1429,7 @@ static void process_timeout(unsigned long __data)
85629 *
85630 * In all cases the return value is guaranteed to be non-negative.
85631 */
85632-signed long __sched schedule_timeout(signed long timeout)
85633+signed long __sched __intentional_overflow(-1) schedule_timeout(signed long timeout)
85634 {
85635 struct timer_list timer;
85636 unsigned long expire;
85637diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
85638index b8b8560..75b1a09 100644
85639--- a/kernel/trace/blktrace.c
85640+++ b/kernel/trace/blktrace.c
85641@@ -317,7 +317,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
85642 struct blk_trace *bt = filp->private_data;
85643 char buf[16];
85644
85645- snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
85646+ snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
85647
85648 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
85649 }
85650@@ -375,7 +375,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
85651 return 1;
85652
85653 bt = buf->chan->private_data;
85654- atomic_inc(&bt->dropped);
85655+ atomic_inc_unchecked(&bt->dropped);
85656 return 0;
85657 }
85658
85659@@ -476,7 +476,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
85660
85661 bt->dir = dir;
85662 bt->dev = dev;
85663- atomic_set(&bt->dropped, 0);
85664+ atomic_set_unchecked(&bt->dropped, 0);
85665
85666 ret = -EIO;
85667 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
85668diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
85669index 03cf44a..3051c64 100644
85670--- a/kernel/trace/ftrace.c
85671+++ b/kernel/trace/ftrace.c
85672@@ -1950,12 +1950,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
85673 if (unlikely(ftrace_disabled))
85674 return 0;
85675
85676+ ret = ftrace_arch_code_modify_prepare();
85677+ FTRACE_WARN_ON(ret);
85678+ if (ret)
85679+ return 0;
85680+
85681 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
85682+ FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
85683 if (ret) {
85684 ftrace_bug(ret, ip);
85685- return 0;
85686 }
85687- return 1;
85688+ return ret ? 0 : 1;
85689 }
85690
85691 /*
85692@@ -4043,8 +4048,10 @@ static int ftrace_process_locs(struct module *mod,
85693 if (!count)
85694 return 0;
85695
85696+ pax_open_kernel();
85697 sort(start, count, sizeof(*start),
85698 ftrace_cmp_ips, ftrace_swap_ips);
85699+ pax_close_kernel();
85700
85701 start_pg = ftrace_allocate_pages(count);
85702 if (!start_pg)
85703@@ -4767,8 +4774,6 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
85704 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
85705
85706 static int ftrace_graph_active;
85707-static struct notifier_block ftrace_suspend_notifier;
85708-
85709 int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
85710 {
85711 return 0;
85712@@ -4912,6 +4917,10 @@ ftrace_suspend_notifier_call(struct notifier_block *bl, unsigned long state,
85713 return NOTIFY_DONE;
85714 }
85715
85716+static struct notifier_block ftrace_suspend_notifier = {
85717+ .notifier_call = ftrace_suspend_notifier_call
85718+};
85719+
85720 int register_ftrace_graph(trace_func_graph_ret_t retfunc,
85721 trace_func_graph_ent_t entryfunc)
85722 {
85723@@ -4925,7 +4934,6 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc,
85724 goto out;
85725 }
85726
85727- ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call;
85728 register_pm_notifier(&ftrace_suspend_notifier);
85729
85730 ftrace_graph_active++;
85731diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
85732index cc2f66f..05edd54 100644
85733--- a/kernel/trace/ring_buffer.c
85734+++ b/kernel/trace/ring_buffer.c
85735@@ -352,9 +352,9 @@ struct buffer_data_page {
85736 */
85737 struct buffer_page {
85738 struct list_head list; /* list of buffer pages */
85739- local_t write; /* index for next write */
85740+ local_unchecked_t write; /* index for next write */
85741 unsigned read; /* index for next read */
85742- local_t entries; /* entries on this page */
85743+ local_unchecked_t entries; /* entries on this page */
85744 unsigned long real_end; /* real end of data */
85745 struct buffer_data_page *page; /* Actual data page */
85746 };
85747@@ -473,8 +473,8 @@ struct ring_buffer_per_cpu {
85748 unsigned long last_overrun;
85749 local_t entries_bytes;
85750 local_t entries;
85751- local_t overrun;
85752- local_t commit_overrun;
85753+ local_unchecked_t overrun;
85754+ local_unchecked_t commit_overrun;
85755 local_t dropped_events;
85756 local_t committing;
85757 local_t commits;
85758@@ -992,8 +992,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
85759 *
85760 * We add a counter to the write field to denote this.
85761 */
85762- old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
85763- old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
85764+ old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
85765+ old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
85766
85767 /*
85768 * Just make sure we have seen our old_write and synchronize
85769@@ -1021,8 +1021,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
85770 * cmpxchg to only update if an interrupt did not already
85771 * do it for us. If the cmpxchg fails, we don't care.
85772 */
85773- (void)local_cmpxchg(&next_page->write, old_write, val);
85774- (void)local_cmpxchg(&next_page->entries, old_entries, eval);
85775+ (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
85776+ (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
85777
85778 /*
85779 * No need to worry about races with clearing out the commit.
85780@@ -1386,12 +1386,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
85781
85782 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
85783 {
85784- return local_read(&bpage->entries) & RB_WRITE_MASK;
85785+ return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
85786 }
85787
85788 static inline unsigned long rb_page_write(struct buffer_page *bpage)
85789 {
85790- return local_read(&bpage->write) & RB_WRITE_MASK;
85791+ return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
85792 }
85793
85794 static int
85795@@ -1486,7 +1486,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
85796 * bytes consumed in ring buffer from here.
85797 * Increment overrun to account for the lost events.
85798 */
85799- local_add(page_entries, &cpu_buffer->overrun);
85800+ local_add_unchecked(page_entries, &cpu_buffer->overrun);
85801 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
85802 }
85803
85804@@ -2064,7 +2064,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
85805 * it is our responsibility to update
85806 * the counters.
85807 */
85808- local_add(entries, &cpu_buffer->overrun);
85809+ local_add_unchecked(entries, &cpu_buffer->overrun);
85810 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
85811
85812 /*
85813@@ -2214,7 +2214,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
85814 if (tail == BUF_PAGE_SIZE)
85815 tail_page->real_end = 0;
85816
85817- local_sub(length, &tail_page->write);
85818+ local_sub_unchecked(length, &tail_page->write);
85819 return;
85820 }
85821
85822@@ -2249,7 +2249,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
85823 rb_event_set_padding(event);
85824
85825 /* Set the write back to the previous setting */
85826- local_sub(length, &tail_page->write);
85827+ local_sub_unchecked(length, &tail_page->write);
85828 return;
85829 }
85830
85831@@ -2261,7 +2261,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
85832
85833 /* Set write to end of buffer */
85834 length = (tail + length) - BUF_PAGE_SIZE;
85835- local_sub(length, &tail_page->write);
85836+ local_sub_unchecked(length, &tail_page->write);
85837 }
85838
85839 /*
85840@@ -2287,7 +2287,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
85841 * about it.
85842 */
85843 if (unlikely(next_page == commit_page)) {
85844- local_inc(&cpu_buffer->commit_overrun);
85845+ local_inc_unchecked(&cpu_buffer->commit_overrun);
85846 goto out_reset;
85847 }
85848
85849@@ -2343,7 +2343,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
85850 cpu_buffer->tail_page) &&
85851 (cpu_buffer->commit_page ==
85852 cpu_buffer->reader_page))) {
85853- local_inc(&cpu_buffer->commit_overrun);
85854+ local_inc_unchecked(&cpu_buffer->commit_overrun);
85855 goto out_reset;
85856 }
85857 }
85858@@ -2391,7 +2391,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
85859 length += RB_LEN_TIME_EXTEND;
85860
85861 tail_page = cpu_buffer->tail_page;
85862- write = local_add_return(length, &tail_page->write);
85863+ write = local_add_return_unchecked(length, &tail_page->write);
85864
85865 /* set write to only the index of the write */
85866 write &= RB_WRITE_MASK;
85867@@ -2408,7 +2408,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
85868 kmemcheck_annotate_bitfield(event, bitfield);
85869 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
85870
85871- local_inc(&tail_page->entries);
85872+ local_inc_unchecked(&tail_page->entries);
85873
85874 /*
85875 * If this is the first commit on the page, then update
85876@@ -2441,7 +2441,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
85877
85878 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
85879 unsigned long write_mask =
85880- local_read(&bpage->write) & ~RB_WRITE_MASK;
85881+ local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
85882 unsigned long event_length = rb_event_length(event);
85883 /*
85884 * This is on the tail page. It is possible that
85885@@ -2451,7 +2451,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
85886 */
85887 old_index += write_mask;
85888 new_index += write_mask;
85889- index = local_cmpxchg(&bpage->write, old_index, new_index);
85890+ index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
85891 if (index == old_index) {
85892 /* update counters */
85893 local_sub(event_length, &cpu_buffer->entries_bytes);
85894@@ -2843,7 +2843,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
85895
85896 /* Do the likely case first */
85897 if (likely(bpage->page == (void *)addr)) {
85898- local_dec(&bpage->entries);
85899+ local_dec_unchecked(&bpage->entries);
85900 return;
85901 }
85902
85903@@ -2855,7 +2855,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
85904 start = bpage;
85905 do {
85906 if (bpage->page == (void *)addr) {
85907- local_dec(&bpage->entries);
85908+ local_dec_unchecked(&bpage->entries);
85909 return;
85910 }
85911 rb_inc_page(cpu_buffer, &bpage);
85912@@ -3139,7 +3139,7 @@ static inline unsigned long
85913 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
85914 {
85915 return local_read(&cpu_buffer->entries) -
85916- (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
85917+ (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
85918 }
85919
85920 /**
85921@@ -3228,7 +3228,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
85922 return 0;
85923
85924 cpu_buffer = buffer->buffers[cpu];
85925- ret = local_read(&cpu_buffer->overrun);
85926+ ret = local_read_unchecked(&cpu_buffer->overrun);
85927
85928 return ret;
85929 }
85930@@ -3251,7 +3251,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
85931 return 0;
85932
85933 cpu_buffer = buffer->buffers[cpu];
85934- ret = local_read(&cpu_buffer->commit_overrun);
85935+ ret = local_read_unchecked(&cpu_buffer->commit_overrun);
85936
85937 return ret;
85938 }
85939@@ -3336,7 +3336,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
85940 /* if you care about this being correct, lock the buffer */
85941 for_each_buffer_cpu(buffer, cpu) {
85942 cpu_buffer = buffer->buffers[cpu];
85943- overruns += local_read(&cpu_buffer->overrun);
85944+ overruns += local_read_unchecked(&cpu_buffer->overrun);
85945 }
85946
85947 return overruns;
85948@@ -3512,8 +3512,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
85949 /*
85950 * Reset the reader page to size zero.
85951 */
85952- local_set(&cpu_buffer->reader_page->write, 0);
85953- local_set(&cpu_buffer->reader_page->entries, 0);
85954+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
85955+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
85956 local_set(&cpu_buffer->reader_page->page->commit, 0);
85957 cpu_buffer->reader_page->real_end = 0;
85958
85959@@ -3547,7 +3547,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
85960 * want to compare with the last_overrun.
85961 */
85962 smp_mb();
85963- overwrite = local_read(&(cpu_buffer->overrun));
85964+ overwrite = local_read_unchecked(&(cpu_buffer->overrun));
85965
85966 /*
85967 * Here's the tricky part.
85968@@ -4117,8 +4117,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
85969
85970 cpu_buffer->head_page
85971 = list_entry(cpu_buffer->pages, struct buffer_page, list);
85972- local_set(&cpu_buffer->head_page->write, 0);
85973- local_set(&cpu_buffer->head_page->entries, 0);
85974+ local_set_unchecked(&cpu_buffer->head_page->write, 0);
85975+ local_set_unchecked(&cpu_buffer->head_page->entries, 0);
85976 local_set(&cpu_buffer->head_page->page->commit, 0);
85977
85978 cpu_buffer->head_page->read = 0;
85979@@ -4128,14 +4128,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
85980
85981 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
85982 INIT_LIST_HEAD(&cpu_buffer->new_pages);
85983- local_set(&cpu_buffer->reader_page->write, 0);
85984- local_set(&cpu_buffer->reader_page->entries, 0);
85985+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
85986+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
85987 local_set(&cpu_buffer->reader_page->page->commit, 0);
85988 cpu_buffer->reader_page->read = 0;
85989
85990 local_set(&cpu_buffer->entries_bytes, 0);
85991- local_set(&cpu_buffer->overrun, 0);
85992- local_set(&cpu_buffer->commit_overrun, 0);
85993+ local_set_unchecked(&cpu_buffer->overrun, 0);
85994+ local_set_unchecked(&cpu_buffer->commit_overrun, 0);
85995 local_set(&cpu_buffer->dropped_events, 0);
85996 local_set(&cpu_buffer->entries, 0);
85997 local_set(&cpu_buffer->committing, 0);
85998@@ -4540,8 +4540,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
85999 rb_init_page(bpage);
86000 bpage = reader->page;
86001 reader->page = *data_page;
86002- local_set(&reader->write, 0);
86003- local_set(&reader->entries, 0);
86004+ local_set_unchecked(&reader->write, 0);
86005+ local_set_unchecked(&reader->entries, 0);
86006 reader->read = 0;
86007 *data_page = bpage;
86008
86009diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
86010index b778e96..4e84621 100644
86011--- a/kernel/trace/trace.c
86012+++ b/kernel/trace/trace.c
86013@@ -3335,7 +3335,7 @@ int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set)
86014 return 0;
86015 }
86016
86017-int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled)
86018+int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled)
86019 {
86020 /* do nothing if flag is already set */
86021 if (!!(trace_flags & mask) == !!enabled)
86022diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
86023index 10c86fb..645ab0a 100644
86024--- a/kernel/trace/trace.h
86025+++ b/kernel/trace/trace.h
86026@@ -1029,7 +1029,7 @@ extern const char *__stop___tracepoint_str[];
86027 void trace_printk_init_buffers(void);
86028 void trace_printk_start_comm(void);
86029 int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set);
86030-int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled);
86031+int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled);
86032
86033 /*
86034 * Normal trace_printk() and friends allocates special buffers
86035diff --git a/kernel/trace/trace_clock.c b/kernel/trace/trace_clock.c
86036index 26dc348..8708ca7 100644
86037--- a/kernel/trace/trace_clock.c
86038+++ b/kernel/trace/trace_clock.c
86039@@ -123,7 +123,7 @@ u64 notrace trace_clock_global(void)
86040 return now;
86041 }
86042
86043-static atomic64_t trace_counter;
86044+static atomic64_unchecked_t trace_counter;
86045
86046 /*
86047 * trace_clock_counter(): simply an atomic counter.
86048@@ -132,5 +132,5 @@ static atomic64_t trace_counter;
86049 */
86050 u64 notrace trace_clock_counter(void)
86051 {
86052- return atomic64_add_return(1, &trace_counter);
86053+ return atomic64_inc_return_unchecked(&trace_counter);
86054 }
86055diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
86056index 368a4d5..7b6d1d5 100644
86057--- a/kernel/trace/trace_events.c
86058+++ b/kernel/trace/trace_events.c
86059@@ -1673,7 +1673,6 @@ __trace_early_add_new_event(struct ftrace_event_call *call,
86060 return 0;
86061 }
86062
86063-struct ftrace_module_file_ops;
86064 static void __add_event_to_tracers(struct ftrace_event_call *call);
86065
86066 /* Add an additional event_call dynamically */
86067diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
86068index b3dcfb2..ebee344 100644
86069--- a/kernel/trace/trace_mmiotrace.c
86070+++ b/kernel/trace/trace_mmiotrace.c
86071@@ -24,7 +24,7 @@ struct header_iter {
86072 static struct trace_array *mmio_trace_array;
86073 static bool overrun_detected;
86074 static unsigned long prev_overruns;
86075-static atomic_t dropped_count;
86076+static atomic_unchecked_t dropped_count;
86077
86078 static void mmio_reset_data(struct trace_array *tr)
86079 {
86080@@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
86081
86082 static unsigned long count_overruns(struct trace_iterator *iter)
86083 {
86084- unsigned long cnt = atomic_xchg(&dropped_count, 0);
86085+ unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
86086 unsigned long over = ring_buffer_overruns(iter->trace_buffer->buffer);
86087
86088 if (over > prev_overruns)
86089@@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
86090 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
86091 sizeof(*entry), 0, pc);
86092 if (!event) {
86093- atomic_inc(&dropped_count);
86094+ atomic_inc_unchecked(&dropped_count);
86095 return;
86096 }
86097 entry = ring_buffer_event_data(event);
86098@@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
86099 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
86100 sizeof(*entry), 0, pc);
86101 if (!event) {
86102- atomic_inc(&dropped_count);
86103+ atomic_inc_unchecked(&dropped_count);
86104 return;
86105 }
86106 entry = ring_buffer_event_data(event);
86107diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
86108index 34e7cba..6f9a729 100644
86109--- a/kernel/trace/trace_output.c
86110+++ b/kernel/trace/trace_output.c
86111@@ -294,7 +294,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
86112
86113 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
86114 if (!IS_ERR(p)) {
86115- p = mangle_path(s->buffer + s->len, p, "\n");
86116+ p = mangle_path(s->buffer + s->len, p, "\n\\");
86117 if (p) {
86118 s->len = p - s->buffer;
86119 return 1;
86120@@ -893,14 +893,16 @@ int register_ftrace_event(struct trace_event *event)
86121 goto out;
86122 }
86123
86124+ pax_open_kernel();
86125 if (event->funcs->trace == NULL)
86126- event->funcs->trace = trace_nop_print;
86127+ *(void **)&event->funcs->trace = trace_nop_print;
86128 if (event->funcs->raw == NULL)
86129- event->funcs->raw = trace_nop_print;
86130+ *(void **)&event->funcs->raw = trace_nop_print;
86131 if (event->funcs->hex == NULL)
86132- event->funcs->hex = trace_nop_print;
86133+ *(void **)&event->funcs->hex = trace_nop_print;
86134 if (event->funcs->binary == NULL)
86135- event->funcs->binary = trace_nop_print;
86136+ *(void **)&event->funcs->binary = trace_nop_print;
86137+ pax_close_kernel();
86138
86139 key = event->type & (EVENT_HASHSIZE - 1);
86140
86141diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
86142index b20428c..4845a10 100644
86143--- a/kernel/trace/trace_stack.c
86144+++ b/kernel/trace/trace_stack.c
86145@@ -68,7 +68,7 @@ check_stack(unsigned long ip, unsigned long *stack)
86146 return;
86147
86148 /* we do not handle interrupt stacks yet */
86149- if (!object_is_on_stack(stack))
86150+ if (!object_starts_on_stack(stack))
86151 return;
86152
86153 local_irq_save(flags);
86154diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
86155index 13fb113..a6ced3f 100644
86156--- a/kernel/user_namespace.c
86157+++ b/kernel/user_namespace.c
86158@@ -82,6 +82,21 @@ int create_user_ns(struct cred *new)
86159 !kgid_has_mapping(parent_ns, group))
86160 return -EPERM;
86161
86162+#ifdef CONFIG_GRKERNSEC
86163+ /*
86164+ * This doesn't really inspire confidence:
86165+ * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
86166+ * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
86167+ * Increases kernel attack surface in areas developers
86168+ * previously cared little about ("low importance due
86169+ * to requiring "root" capability")
86170+ * To be removed when this code receives *proper* review
86171+ */
86172+ if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
86173+ !capable(CAP_SETGID))
86174+ return -EPERM;
86175+#endif
86176+
86177 ns = kmem_cache_zalloc(user_ns_cachep, GFP_KERNEL);
86178 if (!ns)
86179 return -ENOMEM;
86180@@ -860,7 +875,7 @@ static int userns_install(struct nsproxy *nsproxy, void *ns)
86181 if (atomic_read(&current->mm->mm_users) > 1)
86182 return -EINVAL;
86183
86184- if (current->fs->users != 1)
86185+ if (atomic_read(&current->fs->users) != 1)
86186 return -EINVAL;
86187
86188 if (!ns_capable(user_ns, CAP_SYS_ADMIN))
86189diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
86190index 4f69f9a..7c6f8f8 100644
86191--- a/kernel/utsname_sysctl.c
86192+++ b/kernel/utsname_sysctl.c
86193@@ -47,7 +47,7 @@ static void put_uts(ctl_table *table, int write, void *which)
86194 static int proc_do_uts_string(ctl_table *table, int write,
86195 void __user *buffer, size_t *lenp, loff_t *ppos)
86196 {
86197- struct ctl_table uts_table;
86198+ ctl_table_no_const uts_table;
86199 int r;
86200 memcpy(&uts_table, table, sizeof(uts_table));
86201 uts_table.data = get_uts(table, write);
86202diff --git a/kernel/watchdog.c b/kernel/watchdog.c
86203index 4431610..4265616 100644
86204--- a/kernel/watchdog.c
86205+++ b/kernel/watchdog.c
86206@@ -475,7 +475,7 @@ static int watchdog_nmi_enable(unsigned int cpu) { return 0; }
86207 static void watchdog_nmi_disable(unsigned int cpu) { return; }
86208 #endif /* CONFIG_HARDLOCKUP_DETECTOR */
86209
86210-static struct smp_hotplug_thread watchdog_threads = {
86211+static struct smp_hotplug_thread watchdog_threads __read_only = {
86212 .store = &softlockup_watchdog,
86213 .thread_should_run = watchdog_should_run,
86214 .thread_fn = watchdog,
86215diff --git a/kernel/workqueue.c b/kernel/workqueue.c
86216index 987293d..60b3043 100644
86217--- a/kernel/workqueue.c
86218+++ b/kernel/workqueue.c
86219@@ -4658,7 +4658,7 @@ static void rebind_workers(struct worker_pool *pool)
86220 WARN_ON_ONCE(!(worker_flags & WORKER_UNBOUND));
86221 worker_flags |= WORKER_REBOUND;
86222 worker_flags &= ~WORKER_UNBOUND;
86223- ACCESS_ONCE(worker->flags) = worker_flags;
86224+ ACCESS_ONCE_RW(worker->flags) = worker_flags;
86225 }
86226
86227 spin_unlock_irq(&pool->lock);
86228diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
86229index 094f315..244a824 100644
86230--- a/lib/Kconfig.debug
86231+++ b/lib/Kconfig.debug
86232@@ -836,7 +836,7 @@ config DEBUG_MUTEXES
86233
86234 config DEBUG_WW_MUTEX_SLOWPATH
86235 bool "Wait/wound mutex debugging: Slowpath testing"
86236- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
86237+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
86238 select DEBUG_LOCK_ALLOC
86239 select DEBUG_SPINLOCK
86240 select DEBUG_MUTEXES
86241@@ -849,7 +849,7 @@ config DEBUG_WW_MUTEX_SLOWPATH
86242
86243 config DEBUG_LOCK_ALLOC
86244 bool "Lock debugging: detect incorrect freeing of live locks"
86245- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
86246+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
86247 select DEBUG_SPINLOCK
86248 select DEBUG_MUTEXES
86249 select LOCKDEP
86250@@ -863,7 +863,7 @@ config DEBUG_LOCK_ALLOC
86251
86252 config PROVE_LOCKING
86253 bool "Lock debugging: prove locking correctness"
86254- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
86255+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
86256 select LOCKDEP
86257 select DEBUG_SPINLOCK
86258 select DEBUG_MUTEXES
86259@@ -914,7 +914,7 @@ config LOCKDEP
86260
86261 config LOCK_STAT
86262 bool "Lock usage statistics"
86263- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
86264+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
86265 select LOCKDEP
86266 select DEBUG_SPINLOCK
86267 select DEBUG_MUTEXES
86268@@ -1376,6 +1376,7 @@ config LATENCYTOP
86269 depends on DEBUG_KERNEL
86270 depends on STACKTRACE_SUPPORT
86271 depends on PROC_FS
86272+ depends on !GRKERNSEC_HIDESYM
86273 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND && !ARC
86274 select KALLSYMS
86275 select KALLSYMS_ALL
86276@@ -1392,7 +1393,7 @@ config ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
86277 config DEBUG_STRICT_USER_COPY_CHECKS
86278 bool "Strict user copy size checks"
86279 depends on ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
86280- depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
86281+ depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
86282 help
86283 Enabling this option turns a certain set of sanity checks for user
86284 copy operations into compile time failures.
86285@@ -1502,7 +1503,7 @@ endmenu # runtime tests
86286
86287 config PROVIDE_OHCI1394_DMA_INIT
86288 bool "Remote debugging over FireWire early on boot"
86289- depends on PCI && X86
86290+ depends on PCI && X86 && !GRKERNSEC
86291 help
86292 If you want to debug problems which hang or crash the kernel early
86293 on boot and the crashing machine has a FireWire port, you can use
86294@@ -1531,7 +1532,7 @@ config PROVIDE_OHCI1394_DMA_INIT
86295
86296 config FIREWIRE_OHCI_REMOTE_DMA
86297 bool "Remote debugging over FireWire with firewire-ohci"
86298- depends on FIREWIRE_OHCI
86299+ depends on FIREWIRE_OHCI && !GRKERNSEC
86300 help
86301 This option lets you use the FireWire bus for remote debugging
86302 with help of the firewire-ohci driver. It enables unfiltered
86303diff --git a/lib/Makefile b/lib/Makefile
86304index f3bb2cb..b358ace 100644
86305--- a/lib/Makefile
86306+++ b/lib/Makefile
86307@@ -52,7 +52,7 @@ obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
86308
86309 obj-$(CONFIG_BTREE) += btree.o
86310 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
86311-obj-$(CONFIG_DEBUG_LIST) += list_debug.o
86312+obj-y += list_debug.o
86313 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
86314
86315 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
86316diff --git a/lib/bitmap.c b/lib/bitmap.c
86317index 06f7e4f..f3cf2b0 100644
86318--- a/lib/bitmap.c
86319+++ b/lib/bitmap.c
86320@@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
86321 {
86322 int c, old_c, totaldigits, ndigits, nchunks, nbits;
86323 u32 chunk;
86324- const char __user __force *ubuf = (const char __user __force *)buf;
86325+ const char __user *ubuf = (const char __force_user *)buf;
86326
86327 bitmap_zero(maskp, nmaskbits);
86328
86329@@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
86330 {
86331 if (!access_ok(VERIFY_READ, ubuf, ulen))
86332 return -EFAULT;
86333- return __bitmap_parse((const char __force *)ubuf,
86334+ return __bitmap_parse((const char __force_kernel *)ubuf,
86335 ulen, 1, maskp, nmaskbits);
86336
86337 }
86338@@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
86339 {
86340 unsigned a, b;
86341 int c, old_c, totaldigits;
86342- const char __user __force *ubuf = (const char __user __force *)buf;
86343+ const char __user *ubuf = (const char __force_user *)buf;
86344 int exp_digit, in_range;
86345
86346 totaldigits = c = 0;
86347@@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
86348 {
86349 if (!access_ok(VERIFY_READ, ubuf, ulen))
86350 return -EFAULT;
86351- return __bitmap_parselist((const char __force *)ubuf,
86352+ return __bitmap_parselist((const char __force_kernel *)ubuf,
86353 ulen, 1, maskp, nmaskbits);
86354 }
86355 EXPORT_SYMBOL(bitmap_parselist_user);
86356diff --git a/lib/bug.c b/lib/bug.c
86357index 1686034..a9c00c8 100644
86358--- a/lib/bug.c
86359+++ b/lib/bug.c
86360@@ -134,6 +134,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
86361 return BUG_TRAP_TYPE_NONE;
86362
86363 bug = find_bug(bugaddr);
86364+ if (!bug)
86365+ return BUG_TRAP_TYPE_NONE;
86366
86367 file = NULL;
86368 line = 0;
86369diff --git a/lib/debugobjects.c b/lib/debugobjects.c
86370index bf2c8b1..1d00ccf 100644
86371--- a/lib/debugobjects.c
86372+++ b/lib/debugobjects.c
86373@@ -286,7 +286,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
86374 if (limit > 4)
86375 return;
86376
86377- is_on_stack = object_is_on_stack(addr);
86378+ is_on_stack = object_starts_on_stack(addr);
86379 if (is_on_stack == onstack)
86380 return;
86381
86382diff --git a/lib/devres.c b/lib/devres.c
86383index 8235331..5881053 100644
86384--- a/lib/devres.c
86385+++ b/lib/devres.c
86386@@ -81,7 +81,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
86387 void devm_iounmap(struct device *dev, void __iomem *addr)
86388 {
86389 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
86390- (void *)addr));
86391+ (void __force *)addr));
86392 iounmap(addr);
86393 }
86394 EXPORT_SYMBOL(devm_iounmap);
86395@@ -224,7 +224,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
86396 {
86397 ioport_unmap(addr);
86398 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
86399- devm_ioport_map_match, (void *)addr));
86400+ devm_ioport_map_match, (void __force *)addr));
86401 }
86402 EXPORT_SYMBOL(devm_ioport_unmap);
86403 #endif /* CONFIG_HAS_IOPORT */
86404diff --git a/lib/div64.c b/lib/div64.c
86405index 4382ad7..08aa558 100644
86406--- a/lib/div64.c
86407+++ b/lib/div64.c
86408@@ -59,7 +59,7 @@ uint32_t __attribute__((weak)) __div64_32(uint64_t *n, uint32_t base)
86409 EXPORT_SYMBOL(__div64_32);
86410
86411 #ifndef div_s64_rem
86412-s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
86413+s64 __intentional_overflow(-1) div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
86414 {
86415 u64 quotient;
86416
86417@@ -130,7 +130,7 @@ EXPORT_SYMBOL(div64_u64_rem);
86418 * 'http://www.hackersdelight.org/HDcode/newCode/divDouble.c.txt'
86419 */
86420 #ifndef div64_u64
86421-u64 div64_u64(u64 dividend, u64 divisor)
86422+u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
86423 {
86424 u32 high = divisor >> 32;
86425 u64 quot;
86426diff --git a/lib/dma-debug.c b/lib/dma-debug.c
86427index d87a17a..ac0d79a 100644
86428--- a/lib/dma-debug.c
86429+++ b/lib/dma-debug.c
86430@@ -768,7 +768,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
86431
86432 void dma_debug_add_bus(struct bus_type *bus)
86433 {
86434- struct notifier_block *nb;
86435+ notifier_block_no_const *nb;
86436
86437 if (global_disable)
86438 return;
86439@@ -945,7 +945,7 @@ static void check_unmap(struct dma_debug_entry *ref)
86440
86441 static void check_for_stack(struct device *dev, void *addr)
86442 {
86443- if (object_is_on_stack(addr))
86444+ if (object_starts_on_stack(addr))
86445 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
86446 "stack [addr=%p]\n", addr);
86447 }
86448diff --git a/lib/inflate.c b/lib/inflate.c
86449index 013a761..c28f3fc 100644
86450--- a/lib/inflate.c
86451+++ b/lib/inflate.c
86452@@ -269,7 +269,7 @@ static void free(void *where)
86453 malloc_ptr = free_mem_ptr;
86454 }
86455 #else
86456-#define malloc(a) kmalloc(a, GFP_KERNEL)
86457+#define malloc(a) kmalloc((a), GFP_KERNEL)
86458 #define free(a) kfree(a)
86459 #endif
86460
86461diff --git a/lib/ioremap.c b/lib/ioremap.c
86462index 0c9216c..863bd89 100644
86463--- a/lib/ioremap.c
86464+++ b/lib/ioremap.c
86465@@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
86466 unsigned long next;
86467
86468 phys_addr -= addr;
86469- pmd = pmd_alloc(&init_mm, pud, addr);
86470+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
86471 if (!pmd)
86472 return -ENOMEM;
86473 do {
86474@@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
86475 unsigned long next;
86476
86477 phys_addr -= addr;
86478- pud = pud_alloc(&init_mm, pgd, addr);
86479+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
86480 if (!pud)
86481 return -ENOMEM;
86482 do {
86483diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
86484index bd2bea9..6b3c95e 100644
86485--- a/lib/is_single_threaded.c
86486+++ b/lib/is_single_threaded.c
86487@@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
86488 struct task_struct *p, *t;
86489 bool ret;
86490
86491+ if (!mm)
86492+ return true;
86493+
86494 if (atomic_read(&task->signal->live) != 1)
86495 return false;
86496
86497diff --git a/lib/kobject.c b/lib/kobject.c
86498index 084f7b1..d265b8a 100644
86499--- a/lib/kobject.c
86500+++ b/lib/kobject.c
86501@@ -875,9 +875,9 @@ EXPORT_SYMBOL_GPL(kset_create_and_add);
86502
86503
86504 static DEFINE_SPINLOCK(kobj_ns_type_lock);
86505-static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
86506+static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES] __read_only;
86507
86508-int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
86509+int __init kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
86510 {
86511 enum kobj_ns_type type = ops->type;
86512 int error;
86513diff --git a/lib/list_debug.c b/lib/list_debug.c
86514index c24c2f7..f0296f4 100644
86515--- a/lib/list_debug.c
86516+++ b/lib/list_debug.c
86517@@ -11,7 +11,9 @@
86518 #include <linux/bug.h>
86519 #include <linux/kernel.h>
86520 #include <linux/rculist.h>
86521+#include <linux/mm.h>
86522
86523+#ifdef CONFIG_DEBUG_LIST
86524 /*
86525 * Insert a new entry between two known consecutive entries.
86526 *
86527@@ -19,21 +21,40 @@
86528 * the prev/next entries already!
86529 */
86530
86531+static bool __list_add_debug(struct list_head *new,
86532+ struct list_head *prev,
86533+ struct list_head *next)
86534+{
86535+ if (unlikely(next->prev != prev)) {
86536+ printk(KERN_ERR "list_add corruption. next->prev should be "
86537+ "prev (%p), but was %p. (next=%p).\n",
86538+ prev, next->prev, next);
86539+ BUG();
86540+ return false;
86541+ }
86542+ if (unlikely(prev->next != next)) {
86543+ printk(KERN_ERR "list_add corruption. prev->next should be "
86544+ "next (%p), but was %p. (prev=%p).\n",
86545+ next, prev->next, prev);
86546+ BUG();
86547+ return false;
86548+ }
86549+ if (unlikely(new == prev || new == next)) {
86550+ printk(KERN_ERR "list_add double add: new=%p, prev=%p, next=%p.\n",
86551+ new, prev, next);
86552+ BUG();
86553+ return false;
86554+ }
86555+ return true;
86556+}
86557+
86558 void __list_add(struct list_head *new,
86559- struct list_head *prev,
86560- struct list_head *next)
86561+ struct list_head *prev,
86562+ struct list_head *next)
86563 {
86564- WARN(next->prev != prev,
86565- "list_add corruption. next->prev should be "
86566- "prev (%p), but was %p. (next=%p).\n",
86567- prev, next->prev, next);
86568- WARN(prev->next != next,
86569- "list_add corruption. prev->next should be "
86570- "next (%p), but was %p. (prev=%p).\n",
86571- next, prev->next, prev);
86572- WARN(new == prev || new == next,
86573- "list_add double add: new=%p, prev=%p, next=%p.\n",
86574- new, prev, next);
86575+ if (!__list_add_debug(new, prev, next))
86576+ return;
86577+
86578 next->prev = new;
86579 new->next = next;
86580 new->prev = prev;
86581@@ -41,28 +62,46 @@ void __list_add(struct list_head *new,
86582 }
86583 EXPORT_SYMBOL(__list_add);
86584
86585-void __list_del_entry(struct list_head *entry)
86586+static bool __list_del_entry_debug(struct list_head *entry)
86587 {
86588 struct list_head *prev, *next;
86589
86590 prev = entry->prev;
86591 next = entry->next;
86592
86593- if (WARN(next == LIST_POISON1,
86594- "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
86595- entry, LIST_POISON1) ||
86596- WARN(prev == LIST_POISON2,
86597- "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
86598- entry, LIST_POISON2) ||
86599- WARN(prev->next != entry,
86600- "list_del corruption. prev->next should be %p, "
86601- "but was %p\n", entry, prev->next) ||
86602- WARN(next->prev != entry,
86603- "list_del corruption. next->prev should be %p, "
86604- "but was %p\n", entry, next->prev))
86605+ if (unlikely(next == LIST_POISON1)) {
86606+ printk(KERN_ERR "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
86607+ entry, LIST_POISON1);
86608+ BUG();
86609+ return false;
86610+ }
86611+ if (unlikely(prev == LIST_POISON2)) {
86612+ printk(KERN_ERR "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
86613+ entry, LIST_POISON2);
86614+ BUG();
86615+ return false;
86616+ }
86617+ if (unlikely(entry->prev->next != entry)) {
86618+ printk(KERN_ERR "list_del corruption. prev->next should be %p, "
86619+ "but was %p\n", entry, prev->next);
86620+ BUG();
86621+ return false;
86622+ }
86623+ if (unlikely(entry->next->prev != entry)) {
86624+ printk(KERN_ERR "list_del corruption. next->prev should be %p, "
86625+ "but was %p\n", entry, next->prev);
86626+ BUG();
86627+ return false;
86628+ }
86629+ return true;
86630+}
86631+
86632+void __list_del_entry(struct list_head *entry)
86633+{
86634+ if (!__list_del_entry_debug(entry))
86635 return;
86636
86637- __list_del(prev, next);
86638+ __list_del(entry->prev, entry->next);
86639 }
86640 EXPORT_SYMBOL(__list_del_entry);
86641
86642@@ -86,15 +125,85 @@ EXPORT_SYMBOL(list_del);
86643 void __list_add_rcu(struct list_head *new,
86644 struct list_head *prev, struct list_head *next)
86645 {
86646- WARN(next->prev != prev,
86647- "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
86648- prev, next->prev, next);
86649- WARN(prev->next != next,
86650- "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
86651- next, prev->next, prev);
86652+ if (!__list_add_debug(new, prev, next))
86653+ return;
86654+
86655 new->next = next;
86656 new->prev = prev;
86657 rcu_assign_pointer(list_next_rcu(prev), new);
86658 next->prev = new;
86659 }
86660 EXPORT_SYMBOL(__list_add_rcu);
86661+#endif
86662+
86663+void __pax_list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
86664+{
86665+#ifdef CONFIG_DEBUG_LIST
86666+ if (!__list_add_debug(new, prev, next))
86667+ return;
86668+#endif
86669+
86670+ pax_open_kernel();
86671+ next->prev = new;
86672+ new->next = next;
86673+ new->prev = prev;
86674+ prev->next = new;
86675+ pax_close_kernel();
86676+}
86677+EXPORT_SYMBOL(__pax_list_add);
86678+
86679+void pax_list_del(struct list_head *entry)
86680+{
86681+#ifdef CONFIG_DEBUG_LIST
86682+ if (!__list_del_entry_debug(entry))
86683+ return;
86684+#endif
86685+
86686+ pax_open_kernel();
86687+ __list_del(entry->prev, entry->next);
86688+ entry->next = LIST_POISON1;
86689+ entry->prev = LIST_POISON2;
86690+ pax_close_kernel();
86691+}
86692+EXPORT_SYMBOL(pax_list_del);
86693+
86694+void pax_list_del_init(struct list_head *entry)
86695+{
86696+ pax_open_kernel();
86697+ __list_del(entry->prev, entry->next);
86698+ INIT_LIST_HEAD(entry);
86699+ pax_close_kernel();
86700+}
86701+EXPORT_SYMBOL(pax_list_del_init);
86702+
86703+void __pax_list_add_rcu(struct list_head *new,
86704+ struct list_head *prev, struct list_head *next)
86705+{
86706+#ifdef CONFIG_DEBUG_LIST
86707+ if (!__list_add_debug(new, prev, next))
86708+ return;
86709+#endif
86710+
86711+ pax_open_kernel();
86712+ new->next = next;
86713+ new->prev = prev;
86714+ rcu_assign_pointer(list_next_rcu(prev), new);
86715+ next->prev = new;
86716+ pax_close_kernel();
86717+}
86718+EXPORT_SYMBOL(__pax_list_add_rcu);
86719+
86720+void pax_list_del_rcu(struct list_head *entry)
86721+{
86722+#ifdef CONFIG_DEBUG_LIST
86723+ if (!__list_del_entry_debug(entry))
86724+ return;
86725+#endif
86726+
86727+ pax_open_kernel();
86728+ __list_del(entry->prev, entry->next);
86729+ entry->next = LIST_POISON1;
86730+ entry->prev = LIST_POISON2;
86731+ pax_close_kernel();
86732+}
86733+EXPORT_SYMBOL(pax_list_del_rcu);
86734diff --git a/lib/percpu-refcount.c b/lib/percpu-refcount.c
86735index 1a53d49..ace934c 100644
86736--- a/lib/percpu-refcount.c
86737+++ b/lib/percpu-refcount.c
86738@@ -29,7 +29,7 @@
86739 * can't hit 0 before we've added up all the percpu refs.
86740 */
86741
86742-#define PCPU_COUNT_BIAS (1U << 31)
86743+#define PCPU_COUNT_BIAS (1U << 30)
86744
86745 /**
86746 * percpu_ref_init - initialize a percpu refcount
86747diff --git a/lib/radix-tree.c b/lib/radix-tree.c
86748index 7811ed3..f80ca19 100644
86749--- a/lib/radix-tree.c
86750+++ b/lib/radix-tree.c
86751@@ -93,7 +93,7 @@ struct radix_tree_preload {
86752 int nr;
86753 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
86754 };
86755-static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
86756+static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
86757
86758 static inline void *ptr_to_indirect(void *ptr)
86759 {
86760diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
86761index bb2b201..46abaf9 100644
86762--- a/lib/strncpy_from_user.c
86763+++ b/lib/strncpy_from_user.c
86764@@ -21,7 +21,7 @@
86765 */
86766 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
86767 {
86768- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
86769+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
86770 long res = 0;
86771
86772 /*
86773diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
86774index a28df52..3d55877 100644
86775--- a/lib/strnlen_user.c
86776+++ b/lib/strnlen_user.c
86777@@ -26,7 +26,7 @@
86778 */
86779 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
86780 {
86781- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
86782+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
86783 long align, res = 0;
86784 unsigned long c;
86785
86786diff --git a/lib/swiotlb.c b/lib/swiotlb.c
86787index 4e8686c..3e8c92f 100644
86788--- a/lib/swiotlb.c
86789+++ b/lib/swiotlb.c
86790@@ -664,7 +664,7 @@ EXPORT_SYMBOL(swiotlb_alloc_coherent);
86791
86792 void
86793 swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
86794- dma_addr_t dev_addr)
86795+ dma_addr_t dev_addr, struct dma_attrs *attrs)
86796 {
86797 phys_addr_t paddr = dma_to_phys(hwdev, dev_addr);
86798
86799diff --git a/lib/usercopy.c b/lib/usercopy.c
86800index 4f5b1dd..7cab418 100644
86801--- a/lib/usercopy.c
86802+++ b/lib/usercopy.c
86803@@ -7,3 +7,9 @@ void copy_from_user_overflow(void)
86804 WARN(1, "Buffer overflow detected!\n");
86805 }
86806 EXPORT_SYMBOL(copy_from_user_overflow);
86807+
86808+void copy_to_user_overflow(void)
86809+{
86810+ WARN(1, "Buffer overflow detected!\n");
86811+}
86812+EXPORT_SYMBOL(copy_to_user_overflow);
86813diff --git a/lib/vsprintf.c b/lib/vsprintf.c
86814index 26559bd..ed614df 100644
86815--- a/lib/vsprintf.c
86816+++ b/lib/vsprintf.c
86817@@ -16,6 +16,9 @@
86818 * - scnprintf and vscnprintf
86819 */
86820
86821+#ifdef CONFIG_GRKERNSEC_HIDESYM
86822+#define __INCLUDED_BY_HIDESYM 1
86823+#endif
86824 #include <stdarg.h>
86825 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
86826 #include <linux/types.h>
86827@@ -1154,7 +1157,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
86828 return number(buf, end, *(const netdev_features_t *)addr, spec);
86829 }
86830
86831+#ifdef CONFIG_GRKERNSEC_HIDESYM
86832+int kptr_restrict __read_mostly = 2;
86833+#else
86834 int kptr_restrict __read_mostly;
86835+#endif
86836
86837 /*
86838 * Show a '%p' thing. A kernel extension is that the '%p' is followed
86839@@ -1167,6 +1174,7 @@ int kptr_restrict __read_mostly;
86840 * - 'f' For simple symbolic function names without offset
86841 * - 'S' For symbolic direct pointers with offset
86842 * - 's' For symbolic direct pointers without offset
86843+ * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
86844 * - '[FfSs]R' as above with __builtin_extract_return_addr() translation
86845 * - 'B' For backtraced symbolic direct pointers with offset
86846 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
86847@@ -1231,12 +1239,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
86848
86849 if (!ptr && *fmt != 'K') {
86850 /*
86851- * Print (null) with the same width as a pointer so it makes
86852+ * Print (nil) with the same width as a pointer so it makes
86853 * tabular output look nice.
86854 */
86855 if (spec.field_width == -1)
86856 spec.field_width = default_width;
86857- return string(buf, end, "(null)", spec);
86858+ return string(buf, end, "(nil)", spec);
86859 }
86860
86861 switch (*fmt) {
86862@@ -1246,6 +1254,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
86863 /* Fallthrough */
86864 case 'S':
86865 case 's':
86866+#ifdef CONFIG_GRKERNSEC_HIDESYM
86867+ break;
86868+#else
86869+ return symbol_string(buf, end, ptr, spec, fmt);
86870+#endif
86871+ case 'A':
86872 case 'B':
86873 return symbol_string(buf, end, ptr, spec, fmt);
86874 case 'R':
86875@@ -1301,6 +1315,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
86876 va_end(va);
86877 return buf;
86878 }
86879+ case 'P':
86880+ break;
86881 case 'K':
86882 /*
86883 * %pK cannot be used in IRQ context because its test
86884@@ -1336,6 +1352,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
86885 ((const struct file *)ptr)->f_path.dentry,
86886 spec, fmt);
86887 }
86888+
86889+#ifdef CONFIG_GRKERNSEC_HIDESYM
86890+ /* 'P' = approved pointers to copy to userland,
86891+ as in the /proc/kallsyms case, as we make it display nothing
86892+ for non-root users, and the real contents for root users
86893+ Also ignore 'K' pointers, since we force their NULLing for non-root users
86894+ above
86895+ */
86896+ if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
86897+ printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
86898+ dump_stack();
86899+ ptr = NULL;
86900+ }
86901+#endif
86902+
86903 spec.flags |= SMALL;
86904 if (spec.field_width == -1) {
86905 spec.field_width = default_width;
86906@@ -2059,11 +2090,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
86907 typeof(type) value; \
86908 if (sizeof(type) == 8) { \
86909 args = PTR_ALIGN(args, sizeof(u32)); \
86910- *(u32 *)&value = *(u32 *)args; \
86911- *((u32 *)&value + 1) = *(u32 *)(args + 4); \
86912+ *(u32 *)&value = *(const u32 *)args; \
86913+ *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
86914 } else { \
86915 args = PTR_ALIGN(args, sizeof(type)); \
86916- value = *(typeof(type) *)args; \
86917+ value = *(const typeof(type) *)args; \
86918 } \
86919 args += sizeof(type); \
86920 value; \
86921@@ -2126,7 +2157,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
86922 case FORMAT_TYPE_STR: {
86923 const char *str_arg = args;
86924 args += strlen(str_arg) + 1;
86925- str = string(str, end, (char *)str_arg, spec);
86926+ str = string(str, end, str_arg, spec);
86927 break;
86928 }
86929
86930diff --git a/localversion-grsec b/localversion-grsec
86931new file mode 100644
86932index 0000000..7cd6065
86933--- /dev/null
86934+++ b/localversion-grsec
86935@@ -0,0 +1 @@
86936+-grsec
86937diff --git a/mm/Kconfig b/mm/Kconfig
86938index 394838f..0e5f816 100644
86939--- a/mm/Kconfig
86940+++ b/mm/Kconfig
86941@@ -317,10 +317,11 @@ config KSM
86942 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
86943
86944 config DEFAULT_MMAP_MIN_ADDR
86945- int "Low address space to protect from user allocation"
86946+ int "Low address space to protect from user allocation"
86947 depends on MMU
86948- default 4096
86949- help
86950+ default 32768 if ALPHA || ARM || PARISC || SPARC32
86951+ default 65536
86952+ help
86953 This is the portion of low virtual memory which should be protected
86954 from userspace allocation. Keeping a user from writing to low pages
86955 can help reduce the impact of kernel NULL pointer bugs.
86956@@ -351,7 +352,7 @@ config MEMORY_FAILURE
86957
86958 config HWPOISON_INJECT
86959 tristate "HWPoison pages injector"
86960- depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
86961+ depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
86962 select PROC_PAGE_MONITOR
86963
86964 config NOMMU_INITIAL_TRIM_EXCESS
86965diff --git a/mm/backing-dev.c b/mm/backing-dev.c
86966index ce682f7..1fb54f9 100644
86967--- a/mm/backing-dev.c
86968+++ b/mm/backing-dev.c
86969@@ -12,7 +12,7 @@
86970 #include <linux/device.h>
86971 #include <trace/events/writeback.h>
86972
86973-static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
86974+static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
86975
86976 struct backing_dev_info default_backing_dev_info = {
86977 .name = "default",
86978@@ -525,7 +525,7 @@ int bdi_setup_and_register(struct backing_dev_info *bdi, char *name,
86979 return err;
86980
86981 err = bdi_register(bdi, NULL, "%.28s-%ld", name,
86982- atomic_long_inc_return(&bdi_seq));
86983+ atomic_long_inc_return_unchecked(&bdi_seq));
86984 if (err) {
86985 bdi_destroy(bdi);
86986 return err;
86987diff --git a/mm/filemap.c b/mm/filemap.c
86988index ae4846f..b0acebe 100644
86989--- a/mm/filemap.c
86990+++ b/mm/filemap.c
86991@@ -1768,7 +1768,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
86992 struct address_space *mapping = file->f_mapping;
86993
86994 if (!mapping->a_ops->readpage)
86995- return -ENOEXEC;
86996+ return -ENODEV;
86997 file_accessed(file);
86998 vma->vm_ops = &generic_file_vm_ops;
86999 return 0;
87000@@ -1950,7 +1950,7 @@ static size_t __iovec_copy_from_user_inatomic(char *vaddr,
87001
87002 while (bytes) {
87003 char __user *buf = iov->iov_base + base;
87004- int copy = min(bytes, iov->iov_len - base);
87005+ size_t copy = min(bytes, iov->iov_len - base);
87006
87007 base = 0;
87008 left = __copy_from_user_inatomic(vaddr, buf, copy);
87009@@ -1979,7 +1979,7 @@ size_t iov_iter_copy_from_user_atomic(struct page *page,
87010 BUG_ON(!in_atomic());
87011 kaddr = kmap_atomic(page);
87012 if (likely(i->nr_segs == 1)) {
87013- int left;
87014+ size_t left;
87015 char __user *buf = i->iov->iov_base + i->iov_offset;
87016 left = __copy_from_user_inatomic(kaddr + offset, buf, bytes);
87017 copied = bytes - left;
87018@@ -2007,7 +2007,7 @@ size_t iov_iter_copy_from_user(struct page *page,
87019
87020 kaddr = kmap(page);
87021 if (likely(i->nr_segs == 1)) {
87022- int left;
87023+ size_t left;
87024 char __user *buf = i->iov->iov_base + i->iov_offset;
87025 left = __copy_from_user(kaddr + offset, buf, bytes);
87026 copied = bytes - left;
87027@@ -2037,7 +2037,7 @@ void iov_iter_advance(struct iov_iter *i, size_t bytes)
87028 * zero-length segments (without overruning the iovec).
87029 */
87030 while (bytes || unlikely(i->count && !iov->iov_len)) {
87031- int copy;
87032+ size_t copy;
87033
87034 copy = min(bytes, iov->iov_len - base);
87035 BUG_ON(!i->count || i->count < copy);
87036@@ -2108,6 +2108,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
87037 *pos = i_size_read(inode);
87038
87039 if (limit != RLIM_INFINITY) {
87040+ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
87041 if (*pos >= limit) {
87042 send_sig(SIGXFSZ, current, 0);
87043 return -EFBIG;
87044diff --git a/mm/fremap.c b/mm/fremap.c
87045index 5bff081..d8189a9 100644
87046--- a/mm/fremap.c
87047+++ b/mm/fremap.c
87048@@ -163,6 +163,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
87049 retry:
87050 vma = find_vma(mm, start);
87051
87052+#ifdef CONFIG_PAX_SEGMEXEC
87053+ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
87054+ goto out;
87055+#endif
87056+
87057 /*
87058 * Make sure the vma is shared, that it supports prefaulting,
87059 * and that the remapped range is valid and fully within
87060diff --git a/mm/highmem.c b/mm/highmem.c
87061index b32b70c..e512eb0 100644
87062--- a/mm/highmem.c
87063+++ b/mm/highmem.c
87064@@ -138,8 +138,9 @@ static void flush_all_zero_pkmaps(void)
87065 * So no dangers, even with speculative execution.
87066 */
87067 page = pte_page(pkmap_page_table[i]);
87068+ pax_open_kernel();
87069 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
87070-
87071+ pax_close_kernel();
87072 set_page_address(page, NULL);
87073 need_flush = 1;
87074 }
87075@@ -198,9 +199,11 @@ start:
87076 }
87077 }
87078 vaddr = PKMAP_ADDR(last_pkmap_nr);
87079+
87080+ pax_open_kernel();
87081 set_pte_at(&init_mm, vaddr,
87082 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
87083-
87084+ pax_close_kernel();
87085 pkmap_count[last_pkmap_nr] = 1;
87086 set_page_address(page, (void *)vaddr);
87087
87088diff --git a/mm/hugetlb.c b/mm/hugetlb.c
87089index 0b7656e..d21cefc 100644
87090--- a/mm/hugetlb.c
87091+++ b/mm/hugetlb.c
87092@@ -2094,15 +2094,17 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
87093 struct hstate *h = &default_hstate;
87094 unsigned long tmp;
87095 int ret;
87096+ ctl_table_no_const hugetlb_table;
87097
87098 tmp = h->max_huge_pages;
87099
87100 if (write && h->order >= MAX_ORDER)
87101 return -EINVAL;
87102
87103- table->data = &tmp;
87104- table->maxlen = sizeof(unsigned long);
87105- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
87106+ hugetlb_table = *table;
87107+ hugetlb_table.data = &tmp;
87108+ hugetlb_table.maxlen = sizeof(unsigned long);
87109+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
87110 if (ret)
87111 goto out;
87112
87113@@ -2147,15 +2149,17 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
87114 struct hstate *h = &default_hstate;
87115 unsigned long tmp;
87116 int ret;
87117+ ctl_table_no_const hugetlb_table;
87118
87119 tmp = h->nr_overcommit_huge_pages;
87120
87121 if (write && h->order >= MAX_ORDER)
87122 return -EINVAL;
87123
87124- table->data = &tmp;
87125- table->maxlen = sizeof(unsigned long);
87126- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
87127+ hugetlb_table = *table;
87128+ hugetlb_table.data = &tmp;
87129+ hugetlb_table.maxlen = sizeof(unsigned long);
87130+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
87131 if (ret)
87132 goto out;
87133
87134@@ -2605,6 +2609,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
87135 return 1;
87136 }
87137
87138+#ifdef CONFIG_PAX_SEGMEXEC
87139+static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
87140+{
87141+ struct mm_struct *mm = vma->vm_mm;
87142+ struct vm_area_struct *vma_m;
87143+ unsigned long address_m;
87144+ pte_t *ptep_m;
87145+
87146+ vma_m = pax_find_mirror_vma(vma);
87147+ if (!vma_m)
87148+ return;
87149+
87150+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
87151+ address_m = address + SEGMEXEC_TASK_SIZE;
87152+ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
87153+ get_page(page_m);
87154+ hugepage_add_anon_rmap(page_m, vma_m, address_m);
87155+ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
87156+}
87157+#endif
87158+
87159 /*
87160 * Hugetlb_cow() should be called with page lock of the original hugepage held.
87161 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
87162@@ -2721,6 +2746,11 @@ retry_avoidcopy:
87163 make_huge_pte(vma, new_page, 1));
87164 page_remove_rmap(old_page);
87165 hugepage_add_new_anon_rmap(new_page, vma, address);
87166+
87167+#ifdef CONFIG_PAX_SEGMEXEC
87168+ pax_mirror_huge_pte(vma, address, new_page);
87169+#endif
87170+
87171 /* Make the old page be freed below */
87172 new_page = old_page;
87173 }
87174@@ -2883,6 +2913,10 @@ retry:
87175 && (vma->vm_flags & VM_SHARED)));
87176 set_huge_pte_at(mm, address, ptep, new_pte);
87177
87178+#ifdef CONFIG_PAX_SEGMEXEC
87179+ pax_mirror_huge_pte(vma, address, page);
87180+#endif
87181+
87182 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
87183 /* Optimization, do the COW without a second fault */
87184 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
87185@@ -2912,6 +2946,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
87186 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
87187 struct hstate *h = hstate_vma(vma);
87188
87189+#ifdef CONFIG_PAX_SEGMEXEC
87190+ struct vm_area_struct *vma_m;
87191+#endif
87192+
87193 address &= huge_page_mask(h);
87194
87195 ptep = huge_pte_offset(mm, address);
87196@@ -2925,6 +2963,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
87197 VM_FAULT_SET_HINDEX(hstate_index(h));
87198 }
87199
87200+#ifdef CONFIG_PAX_SEGMEXEC
87201+ vma_m = pax_find_mirror_vma(vma);
87202+ if (vma_m) {
87203+ unsigned long address_m;
87204+
87205+ if (vma->vm_start > vma_m->vm_start) {
87206+ address_m = address;
87207+ address -= SEGMEXEC_TASK_SIZE;
87208+ vma = vma_m;
87209+ h = hstate_vma(vma);
87210+ } else
87211+ address_m = address + SEGMEXEC_TASK_SIZE;
87212+
87213+ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
87214+ return VM_FAULT_OOM;
87215+ address_m &= HPAGE_MASK;
87216+ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
87217+ }
87218+#endif
87219+
87220 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
87221 if (!ptep)
87222 return VM_FAULT_OOM;
87223diff --git a/mm/internal.h b/mm/internal.h
87224index 684f7aa..9eb9edc 100644
87225--- a/mm/internal.h
87226+++ b/mm/internal.h
87227@@ -97,6 +97,7 @@ extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address);
87228 * in mm/page_alloc.c
87229 */
87230 extern void __free_pages_bootmem(struct page *page, unsigned int order);
87231+extern void free_compound_page(struct page *page);
87232 extern void prep_compound_page(struct page *page, unsigned long order);
87233 #ifdef CONFIG_MEMORY_FAILURE
87234 extern bool is_free_buddy_page(struct page *page);
87235@@ -352,7 +353,7 @@ extern u32 hwpoison_filter_enable;
87236
87237 extern unsigned long vm_mmap_pgoff(struct file *, unsigned long,
87238 unsigned long, unsigned long,
87239- unsigned long, unsigned long);
87240+ unsigned long, unsigned long) __intentional_overflow(-1);
87241
87242 extern void set_pageblock_order(void);
87243 unsigned long reclaim_clean_pages_from_list(struct zone *zone,
87244diff --git a/mm/kmemleak.c b/mm/kmemleak.c
87245index e126b0e..e986018 100644
87246--- a/mm/kmemleak.c
87247+++ b/mm/kmemleak.c
87248@@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
87249
87250 for (i = 0; i < object->trace_len; i++) {
87251 void *ptr = (void *)object->trace[i];
87252- seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
87253+ seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
87254 }
87255 }
87256
87257@@ -1851,7 +1851,7 @@ static int __init kmemleak_late_init(void)
87258 return -ENOMEM;
87259 }
87260
87261- dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
87262+ dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
87263 &kmemleak_fops);
87264 if (!dentry)
87265 pr_warning("Failed to create the debugfs kmemleak file\n");
87266diff --git a/mm/maccess.c b/mm/maccess.c
87267index d53adf9..03a24bf 100644
87268--- a/mm/maccess.c
87269+++ b/mm/maccess.c
87270@@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
87271 set_fs(KERNEL_DS);
87272 pagefault_disable();
87273 ret = __copy_from_user_inatomic(dst,
87274- (__force const void __user *)src, size);
87275+ (const void __force_user *)src, size);
87276 pagefault_enable();
87277 set_fs(old_fs);
87278
87279@@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
87280
87281 set_fs(KERNEL_DS);
87282 pagefault_disable();
87283- ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
87284+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
87285 pagefault_enable();
87286 set_fs(old_fs);
87287
87288diff --git a/mm/madvise.c b/mm/madvise.c
87289index 539eeb9..e24a987 100644
87290--- a/mm/madvise.c
87291+++ b/mm/madvise.c
87292@@ -51,6 +51,10 @@ static long madvise_behavior(struct vm_area_struct *vma,
87293 pgoff_t pgoff;
87294 unsigned long new_flags = vma->vm_flags;
87295
87296+#ifdef CONFIG_PAX_SEGMEXEC
87297+ struct vm_area_struct *vma_m;
87298+#endif
87299+
87300 switch (behavior) {
87301 case MADV_NORMAL:
87302 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
87303@@ -126,6 +130,13 @@ success:
87304 /*
87305 * vm_flags is protected by the mmap_sem held in write mode.
87306 */
87307+
87308+#ifdef CONFIG_PAX_SEGMEXEC
87309+ vma_m = pax_find_mirror_vma(vma);
87310+ if (vma_m)
87311+ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
87312+#endif
87313+
87314 vma->vm_flags = new_flags;
87315
87316 out:
87317@@ -274,6 +285,11 @@ static long madvise_dontneed(struct vm_area_struct *vma,
87318 struct vm_area_struct **prev,
87319 unsigned long start, unsigned long end)
87320 {
87321+
87322+#ifdef CONFIG_PAX_SEGMEXEC
87323+ struct vm_area_struct *vma_m;
87324+#endif
87325+
87326 *prev = vma;
87327 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
87328 return -EINVAL;
87329@@ -286,6 +302,21 @@ static long madvise_dontneed(struct vm_area_struct *vma,
87330 zap_page_range(vma, start, end - start, &details);
87331 } else
87332 zap_page_range(vma, start, end - start, NULL);
87333+
87334+#ifdef CONFIG_PAX_SEGMEXEC
87335+ vma_m = pax_find_mirror_vma(vma);
87336+ if (vma_m) {
87337+ if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
87338+ struct zap_details details = {
87339+ .nonlinear_vma = vma_m,
87340+ .last_index = ULONG_MAX,
87341+ };
87342+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
87343+ } else
87344+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
87345+ }
87346+#endif
87347+
87348 return 0;
87349 }
87350
87351@@ -491,6 +522,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
87352 if (end < start)
87353 return error;
87354
87355+#ifdef CONFIG_PAX_SEGMEXEC
87356+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
87357+ if (end > SEGMEXEC_TASK_SIZE)
87358+ return error;
87359+ } else
87360+#endif
87361+
87362+ if (end > TASK_SIZE)
87363+ return error;
87364+
87365 error = 0;
87366 if (end == start)
87367 return error;
87368diff --git a/mm/memory-failure.c b/mm/memory-failure.c
87369index bf3351b..aea800d 100644
87370--- a/mm/memory-failure.c
87371+++ b/mm/memory-failure.c
87372@@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
87373
87374 int sysctl_memory_failure_recovery __read_mostly = 1;
87375
87376-atomic_long_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
87377+atomic_long_unchecked_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
87378
87379 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
87380
87381@@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
87382 pfn, t->comm, t->pid);
87383 si.si_signo = SIGBUS;
87384 si.si_errno = 0;
87385- si.si_addr = (void *)addr;
87386+ si.si_addr = (void __user *)addr;
87387 #ifdef __ARCH_SI_TRAPNO
87388 si.si_trapno = trapno;
87389 #endif
87390@@ -762,7 +762,7 @@ static struct page_state {
87391 unsigned long res;
87392 char *msg;
87393 int (*action)(struct page *p, unsigned long pfn);
87394-} error_states[] = {
87395+} __do_const error_states[] = {
87396 { reserved, reserved, "reserved kernel", me_kernel },
87397 /*
87398 * free pages are specially detected outside this table:
87399@@ -1053,7 +1053,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
87400 nr_pages = 1 << compound_order(hpage);
87401 else /* normal page or thp */
87402 nr_pages = 1;
87403- atomic_long_add(nr_pages, &num_poisoned_pages);
87404+ atomic_long_add_unchecked(nr_pages, &num_poisoned_pages);
87405
87406 /*
87407 * We need/can do nothing about count=0 pages.
87408@@ -1083,7 +1083,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
87409 if (!PageHWPoison(hpage)
87410 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
87411 || (p != hpage && TestSetPageHWPoison(hpage))) {
87412- atomic_long_sub(nr_pages, &num_poisoned_pages);
87413+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
87414 return 0;
87415 }
87416 set_page_hwpoison_huge_page(hpage);
87417@@ -1152,7 +1152,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
87418 }
87419 if (hwpoison_filter(p)) {
87420 if (TestClearPageHWPoison(p))
87421- atomic_long_sub(nr_pages, &num_poisoned_pages);
87422+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
87423 unlock_page(hpage);
87424 put_page(hpage);
87425 return 0;
87426@@ -1370,7 +1370,7 @@ int unpoison_memory(unsigned long pfn)
87427 return 0;
87428 }
87429 if (TestClearPageHWPoison(p))
87430- atomic_long_dec(&num_poisoned_pages);
87431+ atomic_long_dec_unchecked(&num_poisoned_pages);
87432 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
87433 return 0;
87434 }
87435@@ -1384,7 +1384,7 @@ int unpoison_memory(unsigned long pfn)
87436 */
87437 if (TestClearPageHWPoison(page)) {
87438 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
87439- atomic_long_sub(nr_pages, &num_poisoned_pages);
87440+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
87441 freeit = 1;
87442 if (PageHuge(page))
87443 clear_page_hwpoison_huge_page(page);
87444@@ -1521,7 +1521,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
87445 } else {
87446 set_page_hwpoison_huge_page(hpage);
87447 dequeue_hwpoisoned_huge_page(hpage);
87448- atomic_long_add(1 << compound_order(hpage),
87449+ atomic_long_add_unchecked(1 << compound_order(hpage),
87450 &num_poisoned_pages);
87451 }
87452 return ret;
87453@@ -1560,7 +1560,7 @@ static int __soft_offline_page(struct page *page, int flags)
87454 put_page(page);
87455 pr_info("soft_offline: %#lx: invalidated\n", pfn);
87456 SetPageHWPoison(page);
87457- atomic_long_inc(&num_poisoned_pages);
87458+ atomic_long_inc_unchecked(&num_poisoned_pages);
87459 return 0;
87460 }
87461
87462@@ -1605,7 +1605,7 @@ static int __soft_offline_page(struct page *page, int flags)
87463 if (!is_free_buddy_page(page))
87464 pr_info("soft offline: %#lx: page leaked\n",
87465 pfn);
87466- atomic_long_inc(&num_poisoned_pages);
87467+ atomic_long_inc_unchecked(&num_poisoned_pages);
87468 }
87469 } else {
87470 pr_info("soft offline: %#lx: isolation failed: %d, page count %d, type %lx\n",
87471@@ -1666,11 +1666,11 @@ int soft_offline_page(struct page *page, int flags)
87472 if (PageHuge(page)) {
87473 set_page_hwpoison_huge_page(hpage);
87474 dequeue_hwpoisoned_huge_page(hpage);
87475- atomic_long_add(1 << compound_order(hpage),
87476+ atomic_long_add_unchecked(1 << compound_order(hpage),
87477 &num_poisoned_pages);
87478 } else {
87479 SetPageHWPoison(page);
87480- atomic_long_inc(&num_poisoned_pages);
87481+ atomic_long_inc_unchecked(&num_poisoned_pages);
87482 }
87483 }
87484 unset:
87485diff --git a/mm/memory.c b/mm/memory.c
87486index d176154..cd1b387 100644
87487--- a/mm/memory.c
87488+++ b/mm/memory.c
87489@@ -402,6 +402,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
87490 free_pte_range(tlb, pmd, addr);
87491 } while (pmd++, addr = next, addr != end);
87492
87493+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
87494 start &= PUD_MASK;
87495 if (start < floor)
87496 return;
87497@@ -416,6 +417,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
87498 pmd = pmd_offset(pud, start);
87499 pud_clear(pud);
87500 pmd_free_tlb(tlb, pmd, start);
87501+#endif
87502+
87503 }
87504
87505 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
87506@@ -435,6 +438,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
87507 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
87508 } while (pud++, addr = next, addr != end);
87509
87510+#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
87511 start &= PGDIR_MASK;
87512 if (start < floor)
87513 return;
87514@@ -449,6 +453,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
87515 pud = pud_offset(pgd, start);
87516 pgd_clear(pgd);
87517 pud_free_tlb(tlb, pud, start);
87518+#endif
87519+
87520 }
87521
87522 /*
87523@@ -1636,12 +1642,6 @@ no_page_table:
87524 return page;
87525 }
87526
87527-static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
87528-{
87529- return stack_guard_page_start(vma, addr) ||
87530- stack_guard_page_end(vma, addr+PAGE_SIZE);
87531-}
87532-
87533 /**
87534 * __get_user_pages() - pin user pages in memory
87535 * @tsk: task_struct of target task
87536@@ -1728,10 +1728,10 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
87537
87538 i = 0;
87539
87540- do {
87541+ while (nr_pages) {
87542 struct vm_area_struct *vma;
87543
87544- vma = find_extend_vma(mm, start);
87545+ vma = find_vma(mm, start);
87546 if (!vma && in_gate_area(mm, start)) {
87547 unsigned long pg = start & PAGE_MASK;
87548 pgd_t *pgd;
87549@@ -1780,7 +1780,7 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
87550 goto next_page;
87551 }
87552
87553- if (!vma ||
87554+ if (!vma || start < vma->vm_start ||
87555 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
87556 !(vm_flags & vma->vm_flags))
87557 return i ? : -EFAULT;
87558@@ -1809,11 +1809,6 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
87559 int ret;
87560 unsigned int fault_flags = 0;
87561
87562- /* For mlock, just skip the stack guard page. */
87563- if (foll_flags & FOLL_MLOCK) {
87564- if (stack_guard_page(vma, start))
87565- goto next_page;
87566- }
87567 if (foll_flags & FOLL_WRITE)
87568 fault_flags |= FAULT_FLAG_WRITE;
87569 if (nonblocking)
87570@@ -1893,7 +1888,7 @@ next_page:
87571 start += page_increm * PAGE_SIZE;
87572 nr_pages -= page_increm;
87573 } while (nr_pages && start < vma->vm_end);
87574- } while (nr_pages);
87575+ }
87576 return i;
87577 }
87578 EXPORT_SYMBOL(__get_user_pages);
87579@@ -2100,6 +2095,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
87580 page_add_file_rmap(page);
87581 set_pte_at(mm, addr, pte, mk_pte(page, prot));
87582
87583+#ifdef CONFIG_PAX_SEGMEXEC
87584+ pax_mirror_file_pte(vma, addr, page, ptl);
87585+#endif
87586+
87587 retval = 0;
87588 pte_unmap_unlock(pte, ptl);
87589 return retval;
87590@@ -2144,9 +2143,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
87591 if (!page_count(page))
87592 return -EINVAL;
87593 if (!(vma->vm_flags & VM_MIXEDMAP)) {
87594+
87595+#ifdef CONFIG_PAX_SEGMEXEC
87596+ struct vm_area_struct *vma_m;
87597+#endif
87598+
87599 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
87600 BUG_ON(vma->vm_flags & VM_PFNMAP);
87601 vma->vm_flags |= VM_MIXEDMAP;
87602+
87603+#ifdef CONFIG_PAX_SEGMEXEC
87604+ vma_m = pax_find_mirror_vma(vma);
87605+ if (vma_m)
87606+ vma_m->vm_flags |= VM_MIXEDMAP;
87607+#endif
87608+
87609 }
87610 return insert_page(vma, addr, page, vma->vm_page_prot);
87611 }
87612@@ -2229,6 +2240,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
87613 unsigned long pfn)
87614 {
87615 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
87616+ BUG_ON(vma->vm_mirror);
87617
87618 if (addr < vma->vm_start || addr >= vma->vm_end)
87619 return -EFAULT;
87620@@ -2476,7 +2488,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
87621
87622 BUG_ON(pud_huge(*pud));
87623
87624- pmd = pmd_alloc(mm, pud, addr);
87625+ pmd = (mm == &init_mm) ?
87626+ pmd_alloc_kernel(mm, pud, addr) :
87627+ pmd_alloc(mm, pud, addr);
87628 if (!pmd)
87629 return -ENOMEM;
87630 do {
87631@@ -2496,7 +2510,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
87632 unsigned long next;
87633 int err;
87634
87635- pud = pud_alloc(mm, pgd, addr);
87636+ pud = (mm == &init_mm) ?
87637+ pud_alloc_kernel(mm, pgd, addr) :
87638+ pud_alloc(mm, pgd, addr);
87639 if (!pud)
87640 return -ENOMEM;
87641 do {
87642@@ -2584,6 +2600,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
87643 copy_user_highpage(dst, src, va, vma);
87644 }
87645
87646+#ifdef CONFIG_PAX_SEGMEXEC
87647+static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
87648+{
87649+ struct mm_struct *mm = vma->vm_mm;
87650+ spinlock_t *ptl;
87651+ pte_t *pte, entry;
87652+
87653+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
87654+ entry = *pte;
87655+ if (!pte_present(entry)) {
87656+ if (!pte_none(entry)) {
87657+ BUG_ON(pte_file(entry));
87658+ free_swap_and_cache(pte_to_swp_entry(entry));
87659+ pte_clear_not_present_full(mm, address, pte, 0);
87660+ }
87661+ } else {
87662+ struct page *page;
87663+
87664+ flush_cache_page(vma, address, pte_pfn(entry));
87665+ entry = ptep_clear_flush(vma, address, pte);
87666+ BUG_ON(pte_dirty(entry));
87667+ page = vm_normal_page(vma, address, entry);
87668+ if (page) {
87669+ update_hiwater_rss(mm);
87670+ if (PageAnon(page))
87671+ dec_mm_counter_fast(mm, MM_ANONPAGES);
87672+ else
87673+ dec_mm_counter_fast(mm, MM_FILEPAGES);
87674+ page_remove_rmap(page);
87675+ page_cache_release(page);
87676+ }
87677+ }
87678+ pte_unmap_unlock(pte, ptl);
87679+}
87680+
87681+/* PaX: if vma is mirrored, synchronize the mirror's PTE
87682+ *
87683+ * the ptl of the lower mapped page is held on entry and is not released on exit
87684+ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
87685+ */
87686+static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
87687+{
87688+ struct mm_struct *mm = vma->vm_mm;
87689+ unsigned long address_m;
87690+ spinlock_t *ptl_m;
87691+ struct vm_area_struct *vma_m;
87692+ pmd_t *pmd_m;
87693+ pte_t *pte_m, entry_m;
87694+
87695+ BUG_ON(!page_m || !PageAnon(page_m));
87696+
87697+ vma_m = pax_find_mirror_vma(vma);
87698+ if (!vma_m)
87699+ return;
87700+
87701+ BUG_ON(!PageLocked(page_m));
87702+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
87703+ address_m = address + SEGMEXEC_TASK_SIZE;
87704+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
87705+ pte_m = pte_offset_map(pmd_m, address_m);
87706+ ptl_m = pte_lockptr(mm, pmd_m);
87707+ if (ptl != ptl_m) {
87708+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
87709+ if (!pte_none(*pte_m))
87710+ goto out;
87711+ }
87712+
87713+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
87714+ page_cache_get(page_m);
87715+ page_add_anon_rmap(page_m, vma_m, address_m);
87716+ inc_mm_counter_fast(mm, MM_ANONPAGES);
87717+ set_pte_at(mm, address_m, pte_m, entry_m);
87718+ update_mmu_cache(vma_m, address_m, pte_m);
87719+out:
87720+ if (ptl != ptl_m)
87721+ spin_unlock(ptl_m);
87722+ pte_unmap(pte_m);
87723+ unlock_page(page_m);
87724+}
87725+
87726+void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
87727+{
87728+ struct mm_struct *mm = vma->vm_mm;
87729+ unsigned long address_m;
87730+ spinlock_t *ptl_m;
87731+ struct vm_area_struct *vma_m;
87732+ pmd_t *pmd_m;
87733+ pte_t *pte_m, entry_m;
87734+
87735+ BUG_ON(!page_m || PageAnon(page_m));
87736+
87737+ vma_m = pax_find_mirror_vma(vma);
87738+ if (!vma_m)
87739+ return;
87740+
87741+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
87742+ address_m = address + SEGMEXEC_TASK_SIZE;
87743+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
87744+ pte_m = pte_offset_map(pmd_m, address_m);
87745+ ptl_m = pte_lockptr(mm, pmd_m);
87746+ if (ptl != ptl_m) {
87747+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
87748+ if (!pte_none(*pte_m))
87749+ goto out;
87750+ }
87751+
87752+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
87753+ page_cache_get(page_m);
87754+ page_add_file_rmap(page_m);
87755+ inc_mm_counter_fast(mm, MM_FILEPAGES);
87756+ set_pte_at(mm, address_m, pte_m, entry_m);
87757+ update_mmu_cache(vma_m, address_m, pte_m);
87758+out:
87759+ if (ptl != ptl_m)
87760+ spin_unlock(ptl_m);
87761+ pte_unmap(pte_m);
87762+}
87763+
87764+static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
87765+{
87766+ struct mm_struct *mm = vma->vm_mm;
87767+ unsigned long address_m;
87768+ spinlock_t *ptl_m;
87769+ struct vm_area_struct *vma_m;
87770+ pmd_t *pmd_m;
87771+ pte_t *pte_m, entry_m;
87772+
87773+ vma_m = pax_find_mirror_vma(vma);
87774+ if (!vma_m)
87775+ return;
87776+
87777+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
87778+ address_m = address + SEGMEXEC_TASK_SIZE;
87779+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
87780+ pte_m = pte_offset_map(pmd_m, address_m);
87781+ ptl_m = pte_lockptr(mm, pmd_m);
87782+ if (ptl != ptl_m) {
87783+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
87784+ if (!pte_none(*pte_m))
87785+ goto out;
87786+ }
87787+
87788+ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
87789+ set_pte_at(mm, address_m, pte_m, entry_m);
87790+out:
87791+ if (ptl != ptl_m)
87792+ spin_unlock(ptl_m);
87793+ pte_unmap(pte_m);
87794+}
87795+
87796+static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
87797+{
87798+ struct page *page_m;
87799+ pte_t entry;
87800+
87801+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
87802+ goto out;
87803+
87804+ entry = *pte;
87805+ page_m = vm_normal_page(vma, address, entry);
87806+ if (!page_m)
87807+ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
87808+ else if (PageAnon(page_m)) {
87809+ if (pax_find_mirror_vma(vma)) {
87810+ pte_unmap_unlock(pte, ptl);
87811+ lock_page(page_m);
87812+ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
87813+ if (pte_same(entry, *pte))
87814+ pax_mirror_anon_pte(vma, address, page_m, ptl);
87815+ else
87816+ unlock_page(page_m);
87817+ }
87818+ } else
87819+ pax_mirror_file_pte(vma, address, page_m, ptl);
87820+
87821+out:
87822+ pte_unmap_unlock(pte, ptl);
87823+}
87824+#endif
87825+
87826 /*
87827 * This routine handles present pages, when users try to write
87828 * to a shared page. It is done by copying the page to a new address
87829@@ -2800,6 +2996,12 @@ gotten:
87830 */
87831 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
87832 if (likely(pte_same(*page_table, orig_pte))) {
87833+
87834+#ifdef CONFIG_PAX_SEGMEXEC
87835+ if (pax_find_mirror_vma(vma))
87836+ BUG_ON(!trylock_page(new_page));
87837+#endif
87838+
87839 if (old_page) {
87840 if (!PageAnon(old_page)) {
87841 dec_mm_counter_fast(mm, MM_FILEPAGES);
87842@@ -2851,6 +3053,10 @@ gotten:
87843 page_remove_rmap(old_page);
87844 }
87845
87846+#ifdef CONFIG_PAX_SEGMEXEC
87847+ pax_mirror_anon_pte(vma, address, new_page, ptl);
87848+#endif
87849+
87850 /* Free the old page.. */
87851 new_page = old_page;
87852 ret |= VM_FAULT_WRITE;
87853@@ -3128,6 +3334,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
87854 swap_free(entry);
87855 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
87856 try_to_free_swap(page);
87857+
87858+#ifdef CONFIG_PAX_SEGMEXEC
87859+ if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
87860+#endif
87861+
87862 unlock_page(page);
87863 if (page != swapcache) {
87864 /*
87865@@ -3151,6 +3362,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
87866
87867 /* No need to invalidate - it was non-present before */
87868 update_mmu_cache(vma, address, page_table);
87869+
87870+#ifdef CONFIG_PAX_SEGMEXEC
87871+ pax_mirror_anon_pte(vma, address, page, ptl);
87872+#endif
87873+
87874 unlock:
87875 pte_unmap_unlock(page_table, ptl);
87876 out:
87877@@ -3170,40 +3386,6 @@ out_release:
87878 }
87879
87880 /*
87881- * This is like a special single-page "expand_{down|up}wards()",
87882- * except we must first make sure that 'address{-|+}PAGE_SIZE'
87883- * doesn't hit another vma.
87884- */
87885-static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
87886-{
87887- address &= PAGE_MASK;
87888- if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
87889- struct vm_area_struct *prev = vma->vm_prev;
87890-
87891- /*
87892- * Is there a mapping abutting this one below?
87893- *
87894- * That's only ok if it's the same stack mapping
87895- * that has gotten split..
87896- */
87897- if (prev && prev->vm_end == address)
87898- return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
87899-
87900- expand_downwards(vma, address - PAGE_SIZE);
87901- }
87902- if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
87903- struct vm_area_struct *next = vma->vm_next;
87904-
87905- /* As VM_GROWSDOWN but s/below/above/ */
87906- if (next && next->vm_start == address + PAGE_SIZE)
87907- return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
87908-
87909- expand_upwards(vma, address + PAGE_SIZE);
87910- }
87911- return 0;
87912-}
87913-
87914-/*
87915 * We enter with non-exclusive mmap_sem (to exclude vma changes,
87916 * but allow concurrent faults), and pte mapped but not yet locked.
87917 * We return with mmap_sem still held, but pte unmapped and unlocked.
87918@@ -3212,27 +3394,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
87919 unsigned long address, pte_t *page_table, pmd_t *pmd,
87920 unsigned int flags)
87921 {
87922- struct page *page;
87923+ struct page *page = NULL;
87924 spinlock_t *ptl;
87925 pte_t entry;
87926
87927- pte_unmap(page_table);
87928-
87929- /* Check if we need to add a guard page to the stack */
87930- if (check_stack_guard_page(vma, address) < 0)
87931- return VM_FAULT_SIGBUS;
87932-
87933- /* Use the zero-page for reads */
87934 if (!(flags & FAULT_FLAG_WRITE)) {
87935 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
87936 vma->vm_page_prot));
87937- page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
87938+ ptl = pte_lockptr(mm, pmd);
87939+ spin_lock(ptl);
87940 if (!pte_none(*page_table))
87941 goto unlock;
87942 goto setpte;
87943 }
87944
87945 /* Allocate our own private page. */
87946+ pte_unmap(page_table);
87947+
87948 if (unlikely(anon_vma_prepare(vma)))
87949 goto oom;
87950 page = alloc_zeroed_user_highpage_movable(vma, address);
87951@@ -3256,6 +3434,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
87952 if (!pte_none(*page_table))
87953 goto release;
87954
87955+#ifdef CONFIG_PAX_SEGMEXEC
87956+ if (pax_find_mirror_vma(vma))
87957+ BUG_ON(!trylock_page(page));
87958+#endif
87959+
87960 inc_mm_counter_fast(mm, MM_ANONPAGES);
87961 page_add_new_anon_rmap(page, vma, address);
87962 setpte:
87963@@ -3263,6 +3446,12 @@ setpte:
87964
87965 /* No need to invalidate - it was non-present before */
87966 update_mmu_cache(vma, address, page_table);
87967+
87968+#ifdef CONFIG_PAX_SEGMEXEC
87969+ if (page)
87970+ pax_mirror_anon_pte(vma, address, page, ptl);
87971+#endif
87972+
87973 unlock:
87974 pte_unmap_unlock(page_table, ptl);
87975 return 0;
87976@@ -3406,6 +3595,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
87977 */
87978 /* Only go through if we didn't race with anybody else... */
87979 if (likely(pte_same(*page_table, orig_pte))) {
87980+
87981+#ifdef CONFIG_PAX_SEGMEXEC
87982+ if (anon && pax_find_mirror_vma(vma))
87983+ BUG_ON(!trylock_page(page));
87984+#endif
87985+
87986 flush_icache_page(vma, page);
87987 entry = mk_pte(page, vma->vm_page_prot);
87988 if (flags & FAULT_FLAG_WRITE)
87989@@ -3427,6 +3622,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
87990
87991 /* no need to invalidate: a not-present page won't be cached */
87992 update_mmu_cache(vma, address, page_table);
87993+
87994+#ifdef CONFIG_PAX_SEGMEXEC
87995+ if (anon)
87996+ pax_mirror_anon_pte(vma, address, page, ptl);
87997+ else
87998+ pax_mirror_file_pte(vma, address, page, ptl);
87999+#endif
88000+
88001 } else {
88002 if (cow_page)
88003 mem_cgroup_uncharge_page(cow_page);
88004@@ -3737,6 +3940,12 @@ static int handle_pte_fault(struct mm_struct *mm,
88005 if (flags & FAULT_FLAG_WRITE)
88006 flush_tlb_fix_spurious_fault(vma, address);
88007 }
88008+
88009+#ifdef CONFIG_PAX_SEGMEXEC
88010+ pax_mirror_pte(vma, address, pte, pmd, ptl);
88011+ return 0;
88012+#endif
88013+
88014 unlock:
88015 pte_unmap_unlock(pte, ptl);
88016 return 0;
88017@@ -3753,9 +3962,41 @@ static int __handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
88018 pmd_t *pmd;
88019 pte_t *pte;
88020
88021+#ifdef CONFIG_PAX_SEGMEXEC
88022+ struct vm_area_struct *vma_m;
88023+#endif
88024+
88025 if (unlikely(is_vm_hugetlb_page(vma)))
88026 return hugetlb_fault(mm, vma, address, flags);
88027
88028+#ifdef CONFIG_PAX_SEGMEXEC
88029+ vma_m = pax_find_mirror_vma(vma);
88030+ if (vma_m) {
88031+ unsigned long address_m;
88032+ pgd_t *pgd_m;
88033+ pud_t *pud_m;
88034+ pmd_t *pmd_m;
88035+
88036+ if (vma->vm_start > vma_m->vm_start) {
88037+ address_m = address;
88038+ address -= SEGMEXEC_TASK_SIZE;
88039+ vma = vma_m;
88040+ } else
88041+ address_m = address + SEGMEXEC_TASK_SIZE;
88042+
88043+ pgd_m = pgd_offset(mm, address_m);
88044+ pud_m = pud_alloc(mm, pgd_m, address_m);
88045+ if (!pud_m)
88046+ return VM_FAULT_OOM;
88047+ pmd_m = pmd_alloc(mm, pud_m, address_m);
88048+ if (!pmd_m)
88049+ return VM_FAULT_OOM;
88050+ if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
88051+ return VM_FAULT_OOM;
88052+ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
88053+ }
88054+#endif
88055+
88056 retry:
88057 pgd = pgd_offset(mm, address);
88058 pud = pud_alloc(mm, pgd, address);
88059@@ -3894,6 +4135,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
88060 spin_unlock(&mm->page_table_lock);
88061 return 0;
88062 }
88063+
88064+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
88065+{
88066+ pud_t *new = pud_alloc_one(mm, address);
88067+ if (!new)
88068+ return -ENOMEM;
88069+
88070+ smp_wmb(); /* See comment in __pte_alloc */
88071+
88072+ spin_lock(&mm->page_table_lock);
88073+ if (pgd_present(*pgd)) /* Another has populated it */
88074+ pud_free(mm, new);
88075+ else
88076+ pgd_populate_kernel(mm, pgd, new);
88077+ spin_unlock(&mm->page_table_lock);
88078+ return 0;
88079+}
88080 #endif /* __PAGETABLE_PUD_FOLDED */
88081
88082 #ifndef __PAGETABLE_PMD_FOLDED
88083@@ -3924,6 +4182,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
88084 spin_unlock(&mm->page_table_lock);
88085 return 0;
88086 }
88087+
88088+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
88089+{
88090+ pmd_t *new = pmd_alloc_one(mm, address);
88091+ if (!new)
88092+ return -ENOMEM;
88093+
88094+ smp_wmb(); /* See comment in __pte_alloc */
88095+
88096+ spin_lock(&mm->page_table_lock);
88097+#ifndef __ARCH_HAS_4LEVEL_HACK
88098+ if (pud_present(*pud)) /* Another has populated it */
88099+ pmd_free(mm, new);
88100+ else
88101+ pud_populate_kernel(mm, pud, new);
88102+#else
88103+ if (pgd_present(*pud)) /* Another has populated it */
88104+ pmd_free(mm, new);
88105+ else
88106+ pgd_populate_kernel(mm, pud, new);
88107+#endif /* __ARCH_HAS_4LEVEL_HACK */
88108+ spin_unlock(&mm->page_table_lock);
88109+ return 0;
88110+}
88111 #endif /* __PAGETABLE_PMD_FOLDED */
88112
88113 #if !defined(__HAVE_ARCH_GATE_AREA)
88114@@ -3937,7 +4219,7 @@ static int __init gate_vma_init(void)
88115 gate_vma.vm_start = FIXADDR_USER_START;
88116 gate_vma.vm_end = FIXADDR_USER_END;
88117 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
88118- gate_vma.vm_page_prot = __P101;
88119+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
88120
88121 return 0;
88122 }
88123@@ -4071,8 +4353,8 @@ out:
88124 return ret;
88125 }
88126
88127-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
88128- void *buf, int len, int write)
88129+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
88130+ void *buf, size_t len, int write)
88131 {
88132 resource_size_t phys_addr;
88133 unsigned long prot = 0;
88134@@ -4098,8 +4380,8 @@ EXPORT_SYMBOL_GPL(generic_access_phys);
88135 * Access another process' address space as given in mm. If non-NULL, use the
88136 * given task for page fault accounting.
88137 */
88138-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
88139- unsigned long addr, void *buf, int len, int write)
88140+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
88141+ unsigned long addr, void *buf, size_t len, int write)
88142 {
88143 struct vm_area_struct *vma;
88144 void *old_buf = buf;
88145@@ -4107,7 +4389,7 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
88146 down_read(&mm->mmap_sem);
88147 /* ignore errors, just check how much was successfully transferred */
88148 while (len) {
88149- int bytes, ret, offset;
88150+ ssize_t bytes, ret, offset;
88151 void *maddr;
88152 struct page *page = NULL;
88153
88154@@ -4166,8 +4448,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
88155 *
88156 * The caller must hold a reference on @mm.
88157 */
88158-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
88159- void *buf, int len, int write)
88160+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
88161+ void *buf, size_t len, int write)
88162 {
88163 return __access_remote_vm(NULL, mm, addr, buf, len, write);
88164 }
88165@@ -4177,11 +4459,11 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
88166 * Source/target buffer must be kernel space,
88167 * Do not walk the page table directly, use get_user_pages
88168 */
88169-int access_process_vm(struct task_struct *tsk, unsigned long addr,
88170- void *buf, int len, int write)
88171+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr,
88172+ void *buf, size_t len, int write)
88173 {
88174 struct mm_struct *mm;
88175- int ret;
88176+ ssize_t ret;
88177
88178 mm = get_task_mm(tsk);
88179 if (!mm)
88180diff --git a/mm/mempolicy.c b/mm/mempolicy.c
88181index 0472964..7d5a0ea 100644
88182--- a/mm/mempolicy.c
88183+++ b/mm/mempolicy.c
88184@@ -746,6 +746,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
88185 unsigned long vmstart;
88186 unsigned long vmend;
88187
88188+#ifdef CONFIG_PAX_SEGMEXEC
88189+ struct vm_area_struct *vma_m;
88190+#endif
88191+
88192 vma = find_vma(mm, start);
88193 if (!vma || vma->vm_start > start)
88194 return -EFAULT;
88195@@ -789,6 +793,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
88196 err = vma_replace_policy(vma, new_pol);
88197 if (err)
88198 goto out;
88199+
88200+#ifdef CONFIG_PAX_SEGMEXEC
88201+ vma_m = pax_find_mirror_vma(vma);
88202+ if (vma_m) {
88203+ err = vma_replace_policy(vma_m, new_pol);
88204+ if (err)
88205+ goto out;
88206+ }
88207+#endif
88208+
88209 }
88210
88211 out:
88212@@ -1252,6 +1266,17 @@ static long do_mbind(unsigned long start, unsigned long len,
88213
88214 if (end < start)
88215 return -EINVAL;
88216+
88217+#ifdef CONFIG_PAX_SEGMEXEC
88218+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
88219+ if (end > SEGMEXEC_TASK_SIZE)
88220+ return -EINVAL;
88221+ } else
88222+#endif
88223+
88224+ if (end > TASK_SIZE)
88225+ return -EINVAL;
88226+
88227 if (end == start)
88228 return 0;
88229
88230@@ -1480,8 +1505,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
88231 */
88232 tcred = __task_cred(task);
88233 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
88234- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
88235- !capable(CAP_SYS_NICE)) {
88236+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
88237 rcu_read_unlock();
88238 err = -EPERM;
88239 goto out_put;
88240@@ -1512,6 +1536,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
88241 goto out;
88242 }
88243
88244+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
88245+ if (mm != current->mm &&
88246+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
88247+ mmput(mm);
88248+ err = -EPERM;
88249+ goto out;
88250+ }
88251+#endif
88252+
88253 err = do_migrate_pages(mm, old, new,
88254 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
88255
88256diff --git a/mm/migrate.c b/mm/migrate.c
88257index c046927..6996b40 100644
88258--- a/mm/migrate.c
88259+++ b/mm/migrate.c
88260@@ -1404,8 +1404,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
88261 */
88262 tcred = __task_cred(task);
88263 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
88264- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
88265- !capable(CAP_SYS_NICE)) {
88266+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
88267 rcu_read_unlock();
88268 err = -EPERM;
88269 goto out;
88270diff --git a/mm/mlock.c b/mm/mlock.c
88271index d480cd6..0f98458 100644
88272--- a/mm/mlock.c
88273+++ b/mm/mlock.c
88274@@ -14,6 +14,7 @@
88275 #include <linux/pagevec.h>
88276 #include <linux/mempolicy.h>
88277 #include <linux/syscalls.h>
88278+#include <linux/security.h>
88279 #include <linux/sched.h>
88280 #include <linux/export.h>
88281 #include <linux/rmap.h>
88282@@ -568,7 +569,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
88283 {
88284 unsigned long nstart, end, tmp;
88285 struct vm_area_struct * vma, * prev;
88286- int error;
88287+ int error = 0;
88288
88289 VM_BUG_ON(start & ~PAGE_MASK);
88290 VM_BUG_ON(len != PAGE_ALIGN(len));
88291@@ -577,6 +578,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
88292 return -EINVAL;
88293 if (end == start)
88294 return 0;
88295+ if (end > TASK_SIZE)
88296+ return -EINVAL;
88297+
88298 vma = find_vma(current->mm, start);
88299 if (!vma || vma->vm_start > start)
88300 return -ENOMEM;
88301@@ -588,6 +592,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
88302 for (nstart = start ; ; ) {
88303 vm_flags_t newflags;
88304
88305+#ifdef CONFIG_PAX_SEGMEXEC
88306+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
88307+ break;
88308+#endif
88309+
88310 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
88311
88312 newflags = vma->vm_flags & ~VM_LOCKED;
88313@@ -700,6 +709,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
88314 lock_limit >>= PAGE_SHIFT;
88315
88316 /* check against resource limits */
88317+ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
88318 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
88319 error = do_mlock(start, len, 1);
88320 up_write(&current->mm->mmap_sem);
88321@@ -734,6 +744,11 @@ static int do_mlockall(int flags)
88322 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
88323 vm_flags_t newflags;
88324
88325+#ifdef CONFIG_PAX_SEGMEXEC
88326+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
88327+ break;
88328+#endif
88329+
88330 newflags = vma->vm_flags & ~VM_LOCKED;
88331 if (flags & MCL_CURRENT)
88332 newflags |= VM_LOCKED;
88333@@ -767,6 +782,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
88334 lock_limit >>= PAGE_SHIFT;
88335
88336 ret = -ENOMEM;
88337+ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
88338 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
88339 capable(CAP_IPC_LOCK))
88340 ret = do_mlockall(flags);
88341diff --git a/mm/mmap.c b/mm/mmap.c
88342index 9d54851..e8c6035 100644
88343--- a/mm/mmap.c
88344+++ b/mm/mmap.c
88345@@ -36,6 +36,7 @@
88346 #include <linux/sched/sysctl.h>
88347 #include <linux/notifier.h>
88348 #include <linux/memory.h>
88349+#include <linux/random.h>
88350
88351 #include <asm/uaccess.h>
88352 #include <asm/cacheflush.h>
88353@@ -52,6 +53,16 @@
88354 #define arch_rebalance_pgtables(addr, len) (addr)
88355 #endif
88356
88357+static inline void verify_mm_writelocked(struct mm_struct *mm)
88358+{
88359+#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
88360+ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
88361+ up_read(&mm->mmap_sem);
88362+ BUG();
88363+ }
88364+#endif
88365+}
88366+
88367 static void unmap_region(struct mm_struct *mm,
88368 struct vm_area_struct *vma, struct vm_area_struct *prev,
88369 unsigned long start, unsigned long end);
88370@@ -71,16 +82,25 @@ static void unmap_region(struct mm_struct *mm,
88371 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
88372 *
88373 */
88374-pgprot_t protection_map[16] = {
88375+pgprot_t protection_map[16] __read_only = {
88376 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
88377 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
88378 };
88379
88380-pgprot_t vm_get_page_prot(unsigned long vm_flags)
88381+pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
88382 {
88383- return __pgprot(pgprot_val(protection_map[vm_flags &
88384+ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
88385 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
88386 pgprot_val(arch_vm_get_page_prot(vm_flags)));
88387+
88388+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
88389+ if (!(__supported_pte_mask & _PAGE_NX) &&
88390+ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
88391+ (vm_flags & (VM_READ | VM_WRITE)))
88392+ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
88393+#endif
88394+
88395+ return prot;
88396 }
88397 EXPORT_SYMBOL(vm_get_page_prot);
88398
88399@@ -89,6 +109,7 @@ int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
88400 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
88401 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
88402 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
88403+unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
88404 /*
88405 * Make sure vm_committed_as in one cacheline and not cacheline shared with
88406 * other variables. It can be updated by several CPUs frequently.
88407@@ -247,6 +268,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
88408 struct vm_area_struct *next = vma->vm_next;
88409
88410 might_sleep();
88411+ BUG_ON(vma->vm_mirror);
88412 if (vma->vm_ops && vma->vm_ops->close)
88413 vma->vm_ops->close(vma);
88414 if (vma->vm_file)
88415@@ -291,6 +313,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
88416 * not page aligned -Ram Gupta
88417 */
88418 rlim = rlimit(RLIMIT_DATA);
88419+ gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
88420 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
88421 (mm->end_data - mm->start_data) > rlim)
88422 goto out;
88423@@ -933,6 +956,12 @@ static int
88424 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
88425 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
88426 {
88427+
88428+#ifdef CONFIG_PAX_SEGMEXEC
88429+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
88430+ return 0;
88431+#endif
88432+
88433 if (is_mergeable_vma(vma, file, vm_flags) &&
88434 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
88435 if (vma->vm_pgoff == vm_pgoff)
88436@@ -952,6 +981,12 @@ static int
88437 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
88438 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
88439 {
88440+
88441+#ifdef CONFIG_PAX_SEGMEXEC
88442+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
88443+ return 0;
88444+#endif
88445+
88446 if (is_mergeable_vma(vma, file, vm_flags) &&
88447 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
88448 pgoff_t vm_pglen;
88449@@ -994,13 +1029,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
88450 struct vm_area_struct *vma_merge(struct mm_struct *mm,
88451 struct vm_area_struct *prev, unsigned long addr,
88452 unsigned long end, unsigned long vm_flags,
88453- struct anon_vma *anon_vma, struct file *file,
88454+ struct anon_vma *anon_vma, struct file *file,
88455 pgoff_t pgoff, struct mempolicy *policy)
88456 {
88457 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
88458 struct vm_area_struct *area, *next;
88459 int err;
88460
88461+#ifdef CONFIG_PAX_SEGMEXEC
88462+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
88463+ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
88464+
88465+ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
88466+#endif
88467+
88468 /*
88469 * We later require that vma->vm_flags == vm_flags,
88470 * so this tests vma->vm_flags & VM_SPECIAL, too.
88471@@ -1016,6 +1058,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
88472 if (next && next->vm_end == end) /* cases 6, 7, 8 */
88473 next = next->vm_next;
88474
88475+#ifdef CONFIG_PAX_SEGMEXEC
88476+ if (prev)
88477+ prev_m = pax_find_mirror_vma(prev);
88478+ if (area)
88479+ area_m = pax_find_mirror_vma(area);
88480+ if (next)
88481+ next_m = pax_find_mirror_vma(next);
88482+#endif
88483+
88484 /*
88485 * Can it merge with the predecessor?
88486 */
88487@@ -1035,9 +1086,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
88488 /* cases 1, 6 */
88489 err = vma_adjust(prev, prev->vm_start,
88490 next->vm_end, prev->vm_pgoff, NULL);
88491- } else /* cases 2, 5, 7 */
88492+
88493+#ifdef CONFIG_PAX_SEGMEXEC
88494+ if (!err && prev_m)
88495+ err = vma_adjust(prev_m, prev_m->vm_start,
88496+ next_m->vm_end, prev_m->vm_pgoff, NULL);
88497+#endif
88498+
88499+ } else { /* cases 2, 5, 7 */
88500 err = vma_adjust(prev, prev->vm_start,
88501 end, prev->vm_pgoff, NULL);
88502+
88503+#ifdef CONFIG_PAX_SEGMEXEC
88504+ if (!err && prev_m)
88505+ err = vma_adjust(prev_m, prev_m->vm_start,
88506+ end_m, prev_m->vm_pgoff, NULL);
88507+#endif
88508+
88509+ }
88510 if (err)
88511 return NULL;
88512 khugepaged_enter_vma_merge(prev);
88513@@ -1051,12 +1117,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
88514 mpol_equal(policy, vma_policy(next)) &&
88515 can_vma_merge_before(next, vm_flags,
88516 anon_vma, file, pgoff+pglen)) {
88517- if (prev && addr < prev->vm_end) /* case 4 */
88518+ if (prev && addr < prev->vm_end) { /* case 4 */
88519 err = vma_adjust(prev, prev->vm_start,
88520 addr, prev->vm_pgoff, NULL);
88521- else /* cases 3, 8 */
88522+
88523+#ifdef CONFIG_PAX_SEGMEXEC
88524+ if (!err && prev_m)
88525+ err = vma_adjust(prev_m, prev_m->vm_start,
88526+ addr_m, prev_m->vm_pgoff, NULL);
88527+#endif
88528+
88529+ } else { /* cases 3, 8 */
88530 err = vma_adjust(area, addr, next->vm_end,
88531 next->vm_pgoff - pglen, NULL);
88532+
88533+#ifdef CONFIG_PAX_SEGMEXEC
88534+ if (!err && area_m)
88535+ err = vma_adjust(area_m, addr_m, next_m->vm_end,
88536+ next_m->vm_pgoff - pglen, NULL);
88537+#endif
88538+
88539+ }
88540 if (err)
88541 return NULL;
88542 khugepaged_enter_vma_merge(area);
88543@@ -1165,8 +1246,10 @@ none:
88544 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
88545 struct file *file, long pages)
88546 {
88547- const unsigned long stack_flags
88548- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
88549+
88550+#ifdef CONFIG_PAX_RANDMMAP
88551+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
88552+#endif
88553
88554 mm->total_vm += pages;
88555
88556@@ -1174,7 +1257,7 @@ void vm_stat_account(struct mm_struct *mm, unsigned long flags,
88557 mm->shared_vm += pages;
88558 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
88559 mm->exec_vm += pages;
88560- } else if (flags & stack_flags)
88561+ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
88562 mm->stack_vm += pages;
88563 }
88564 #endif /* CONFIG_PROC_FS */
88565@@ -1212,7 +1295,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
88566 * (the exception is when the underlying filesystem is noexec
88567 * mounted, in which case we dont add PROT_EXEC.)
88568 */
88569- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
88570+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
88571 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
88572 prot |= PROT_EXEC;
88573
88574@@ -1238,7 +1321,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
88575 /* Obtain the address to map to. we verify (or select) it and ensure
88576 * that it represents a valid section of the address space.
88577 */
88578- addr = get_unmapped_area(file, addr, len, pgoff, flags);
88579+ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
88580 if (addr & ~PAGE_MASK)
88581 return addr;
88582
88583@@ -1249,6 +1332,43 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
88584 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
88585 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
88586
88587+#ifdef CONFIG_PAX_MPROTECT
88588+ if (mm->pax_flags & MF_PAX_MPROTECT) {
88589+
88590+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
88591+ if (file && !pgoff && (vm_flags & VM_EXEC) && mm->binfmt &&
88592+ mm->binfmt->handle_mmap)
88593+ mm->binfmt->handle_mmap(file);
88594+#endif
88595+
88596+#ifndef CONFIG_PAX_MPROTECT_COMPAT
88597+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
88598+ gr_log_rwxmmap(file);
88599+
88600+#ifdef CONFIG_PAX_EMUPLT
88601+ vm_flags &= ~VM_EXEC;
88602+#else
88603+ return -EPERM;
88604+#endif
88605+
88606+ }
88607+
88608+ if (!(vm_flags & VM_EXEC))
88609+ vm_flags &= ~VM_MAYEXEC;
88610+#else
88611+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
88612+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
88613+#endif
88614+ else
88615+ vm_flags &= ~VM_MAYWRITE;
88616+ }
88617+#endif
88618+
88619+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
88620+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
88621+ vm_flags &= ~VM_PAGEEXEC;
88622+#endif
88623+
88624 if (flags & MAP_LOCKED)
88625 if (!can_do_mlock())
88626 return -EPERM;
88627@@ -1260,6 +1380,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
88628 locked += mm->locked_vm;
88629 lock_limit = rlimit(RLIMIT_MEMLOCK);
88630 lock_limit >>= PAGE_SHIFT;
88631+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
88632 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
88633 return -EAGAIN;
88634 }
88635@@ -1344,6 +1465,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
88636 vm_flags |= VM_NORESERVE;
88637 }
88638
88639+ if (!gr_acl_handle_mmap(file, prot))
88640+ return -EACCES;
88641+
88642 addr = mmap_region(file, addr, len, vm_flags, pgoff);
88643 if (!IS_ERR_VALUE(addr) &&
88644 ((vm_flags & VM_LOCKED) ||
88645@@ -1437,7 +1561,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
88646 vm_flags_t vm_flags = vma->vm_flags;
88647
88648 /* If it was private or non-writable, the write bit is already clear */
88649- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
88650+ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
88651 return 0;
88652
88653 /* The backer wishes to know when pages are first written to? */
88654@@ -1483,7 +1607,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
88655 struct rb_node **rb_link, *rb_parent;
88656 unsigned long charged = 0;
88657
88658+#ifdef CONFIG_PAX_SEGMEXEC
88659+ struct vm_area_struct *vma_m = NULL;
88660+#endif
88661+
88662+ /*
88663+ * mm->mmap_sem is required to protect against another thread
88664+ * changing the mappings in case we sleep.
88665+ */
88666+ verify_mm_writelocked(mm);
88667+
88668 /* Check against address space limit. */
88669+
88670+#ifdef CONFIG_PAX_RANDMMAP
88671+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (vm_flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
88672+#endif
88673+
88674 if (!may_expand_vm(mm, len >> PAGE_SHIFT)) {
88675 unsigned long nr_pages;
88676
88677@@ -1502,11 +1641,10 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
88678
88679 /* Clear old maps */
88680 error = -ENOMEM;
88681-munmap_back:
88682 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
88683 if (do_munmap(mm, addr, len))
88684 return -ENOMEM;
88685- goto munmap_back;
88686+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
88687 }
88688
88689 /*
88690@@ -1537,6 +1675,16 @@ munmap_back:
88691 goto unacct_error;
88692 }
88693
88694+#ifdef CONFIG_PAX_SEGMEXEC
88695+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
88696+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
88697+ if (!vma_m) {
88698+ error = -ENOMEM;
88699+ goto free_vma;
88700+ }
88701+ }
88702+#endif
88703+
88704 vma->vm_mm = mm;
88705 vma->vm_start = addr;
88706 vma->vm_end = addr + len;
88707@@ -1556,6 +1704,13 @@ munmap_back:
88708 if (error)
88709 goto unmap_and_free_vma;
88710
88711+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
88712+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
88713+ vma->vm_flags |= VM_PAGEEXEC;
88714+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
88715+ }
88716+#endif
88717+
88718 /* Can addr have changed??
88719 *
88720 * Answer: Yes, several device drivers can do it in their
88721@@ -1589,6 +1744,12 @@ munmap_back:
88722 }
88723
88724 vma_link(mm, vma, prev, rb_link, rb_parent);
88725+
88726+#ifdef CONFIG_PAX_SEGMEXEC
88727+ if (vma_m)
88728+ BUG_ON(pax_mirror_vma(vma_m, vma));
88729+#endif
88730+
88731 /* Once vma denies write, undo our temporary denial count */
88732 if (vm_flags & VM_DENYWRITE)
88733 allow_write_access(file);
88734@@ -1597,6 +1758,7 @@ out:
88735 perf_event_mmap(vma);
88736
88737 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
88738+ track_exec_limit(mm, addr, addr + len, vm_flags);
88739 if (vm_flags & VM_LOCKED) {
88740 if (!((vm_flags & VM_SPECIAL) || is_vm_hugetlb_page(vma) ||
88741 vma == get_gate_vma(current->mm)))
88742@@ -1629,6 +1791,12 @@ unmap_and_free_vma:
88743 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
88744 charged = 0;
88745 free_vma:
88746+
88747+#ifdef CONFIG_PAX_SEGMEXEC
88748+ if (vma_m)
88749+ kmem_cache_free(vm_area_cachep, vma_m);
88750+#endif
88751+
88752 kmem_cache_free(vm_area_cachep, vma);
88753 unacct_error:
88754 if (charged)
88755@@ -1636,7 +1804,63 @@ unacct_error:
88756 return error;
88757 }
88758
88759-unsigned long unmapped_area(struct vm_unmapped_area_info *info)
88760+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
88761+unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
88762+{
88763+ if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
88764+ return ((prandom_u32() & 0xFF) + 1) << PAGE_SHIFT;
88765+
88766+ return 0;
88767+}
88768+#endif
88769+
88770+bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
88771+{
88772+ if (!vma) {
88773+#ifdef CONFIG_STACK_GROWSUP
88774+ if (addr > sysctl_heap_stack_gap)
88775+ vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
88776+ else
88777+ vma = find_vma(current->mm, 0);
88778+ if (vma && (vma->vm_flags & VM_GROWSUP))
88779+ return false;
88780+#endif
88781+ return true;
88782+ }
88783+
88784+ if (addr + len > vma->vm_start)
88785+ return false;
88786+
88787+ if (vma->vm_flags & VM_GROWSDOWN)
88788+ return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
88789+#ifdef CONFIG_STACK_GROWSUP
88790+ else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
88791+ return addr - vma->vm_prev->vm_end >= sysctl_heap_stack_gap;
88792+#endif
88793+ else if (offset)
88794+ return offset <= vma->vm_start - addr - len;
88795+
88796+ return true;
88797+}
88798+
88799+unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
88800+{
88801+ if (vma->vm_start < len)
88802+ return -ENOMEM;
88803+
88804+ if (!(vma->vm_flags & VM_GROWSDOWN)) {
88805+ if (offset <= vma->vm_start - len)
88806+ return vma->vm_start - len - offset;
88807+ else
88808+ return -ENOMEM;
88809+ }
88810+
88811+ if (sysctl_heap_stack_gap <= vma->vm_start - len)
88812+ return vma->vm_start - len - sysctl_heap_stack_gap;
88813+ return -ENOMEM;
88814+}
88815+
88816+unsigned long unmapped_area(const struct vm_unmapped_area_info *info)
88817 {
88818 /*
88819 * We implement the search by looking for an rbtree node that
88820@@ -1684,11 +1908,29 @@ unsigned long unmapped_area(struct vm_unmapped_area_info *info)
88821 }
88822 }
88823
88824- gap_start = vma->vm_prev ? vma->vm_prev->vm_end : 0;
88825+ gap_start = vma->vm_prev ? vma->vm_prev->vm_end: 0;
88826 check_current:
88827 /* Check if current node has a suitable gap */
88828 if (gap_start > high_limit)
88829 return -ENOMEM;
88830+
88831+ if (gap_end - gap_start > info->threadstack_offset)
88832+ gap_start += info->threadstack_offset;
88833+ else
88834+ gap_start = gap_end;
88835+
88836+ if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
88837+ if (gap_end - gap_start > sysctl_heap_stack_gap)
88838+ gap_start += sysctl_heap_stack_gap;
88839+ else
88840+ gap_start = gap_end;
88841+ }
88842+ if (vma->vm_flags & VM_GROWSDOWN) {
88843+ if (gap_end - gap_start > sysctl_heap_stack_gap)
88844+ gap_end -= sysctl_heap_stack_gap;
88845+ else
88846+ gap_end = gap_start;
88847+ }
88848 if (gap_end >= low_limit && gap_end - gap_start >= length)
88849 goto found;
88850
88851@@ -1738,7 +1980,7 @@ found:
88852 return gap_start;
88853 }
88854
88855-unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info)
88856+unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info)
88857 {
88858 struct mm_struct *mm = current->mm;
88859 struct vm_area_struct *vma;
88860@@ -1792,6 +2034,24 @@ check_current:
88861 gap_end = vma->vm_start;
88862 if (gap_end < low_limit)
88863 return -ENOMEM;
88864+
88865+ if (gap_end - gap_start > info->threadstack_offset)
88866+ gap_end -= info->threadstack_offset;
88867+ else
88868+ gap_end = gap_start;
88869+
88870+ if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
88871+ if (gap_end - gap_start > sysctl_heap_stack_gap)
88872+ gap_start += sysctl_heap_stack_gap;
88873+ else
88874+ gap_start = gap_end;
88875+ }
88876+ if (vma->vm_flags & VM_GROWSDOWN) {
88877+ if (gap_end - gap_start > sysctl_heap_stack_gap)
88878+ gap_end -= sysctl_heap_stack_gap;
88879+ else
88880+ gap_end = gap_start;
88881+ }
88882 if (gap_start <= high_limit && gap_end - gap_start >= length)
88883 goto found;
88884
88885@@ -1855,6 +2115,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
88886 struct mm_struct *mm = current->mm;
88887 struct vm_area_struct *vma;
88888 struct vm_unmapped_area_info info;
88889+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
88890
88891 if (len > TASK_SIZE)
88892 return -ENOMEM;
88893@@ -1862,19 +2123,29 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
88894 if (flags & MAP_FIXED)
88895 return addr;
88896
88897+#ifdef CONFIG_PAX_RANDMMAP
88898+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
88899+#endif
88900+
88901 if (addr) {
88902 addr = PAGE_ALIGN(addr);
88903 vma = find_vma(mm, addr);
88904- if (TASK_SIZE - len >= addr &&
88905- (!vma || addr + len <= vma->vm_start))
88906+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
88907 return addr;
88908 }
88909
88910 info.flags = 0;
88911 info.length = len;
88912 info.low_limit = TASK_UNMAPPED_BASE;
88913+
88914+#ifdef CONFIG_PAX_RANDMMAP
88915+ if (mm->pax_flags & MF_PAX_RANDMMAP)
88916+ info.low_limit += mm->delta_mmap;
88917+#endif
88918+
88919 info.high_limit = TASK_SIZE;
88920 info.align_mask = 0;
88921+ info.threadstack_offset = offset;
88922 return vm_unmapped_area(&info);
88923 }
88924 #endif
88925@@ -1893,6 +2164,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
88926 struct mm_struct *mm = current->mm;
88927 unsigned long addr = addr0;
88928 struct vm_unmapped_area_info info;
88929+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
88930
88931 /* requested length too big for entire address space */
88932 if (len > TASK_SIZE)
88933@@ -1901,12 +2173,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
88934 if (flags & MAP_FIXED)
88935 return addr;
88936
88937+#ifdef CONFIG_PAX_RANDMMAP
88938+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
88939+#endif
88940+
88941 /* requesting a specific address */
88942 if (addr) {
88943 addr = PAGE_ALIGN(addr);
88944 vma = find_vma(mm, addr);
88945- if (TASK_SIZE - len >= addr &&
88946- (!vma || addr + len <= vma->vm_start))
88947+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
88948 return addr;
88949 }
88950
88951@@ -1915,6 +2190,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
88952 info.low_limit = PAGE_SIZE;
88953 info.high_limit = mm->mmap_base;
88954 info.align_mask = 0;
88955+ info.threadstack_offset = offset;
88956 addr = vm_unmapped_area(&info);
88957
88958 /*
88959@@ -1927,6 +2203,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
88960 VM_BUG_ON(addr != -ENOMEM);
88961 info.flags = 0;
88962 info.low_limit = TASK_UNMAPPED_BASE;
88963+
88964+#ifdef CONFIG_PAX_RANDMMAP
88965+ if (mm->pax_flags & MF_PAX_RANDMMAP)
88966+ info.low_limit += mm->delta_mmap;
88967+#endif
88968+
88969 info.high_limit = TASK_SIZE;
88970 addr = vm_unmapped_area(&info);
88971 }
88972@@ -2028,6 +2310,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
88973 return vma;
88974 }
88975
88976+#ifdef CONFIG_PAX_SEGMEXEC
88977+struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
88978+{
88979+ struct vm_area_struct *vma_m;
88980+
88981+ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
88982+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
88983+ BUG_ON(vma->vm_mirror);
88984+ return NULL;
88985+ }
88986+ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
88987+ vma_m = vma->vm_mirror;
88988+ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
88989+ BUG_ON(vma->vm_file != vma_m->vm_file);
88990+ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
88991+ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
88992+ BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
88993+ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
88994+ return vma_m;
88995+}
88996+#endif
88997+
88998 /*
88999 * Verify that the stack growth is acceptable and
89000 * update accounting. This is shared with both the
89001@@ -2044,6 +2348,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
89002 return -ENOMEM;
89003
89004 /* Stack limit test */
89005+ gr_learn_resource(current, RLIMIT_STACK, size, 1);
89006 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
89007 return -ENOMEM;
89008
89009@@ -2054,6 +2359,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
89010 locked = mm->locked_vm + grow;
89011 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
89012 limit >>= PAGE_SHIFT;
89013+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
89014 if (locked > limit && !capable(CAP_IPC_LOCK))
89015 return -ENOMEM;
89016 }
89017@@ -2083,37 +2389,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
89018 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
89019 * vma is the last one with address > vma->vm_end. Have to extend vma.
89020 */
89021+#ifndef CONFIG_IA64
89022+static
89023+#endif
89024 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
89025 {
89026 int error;
89027+ bool locknext;
89028
89029 if (!(vma->vm_flags & VM_GROWSUP))
89030 return -EFAULT;
89031
89032+ /* Also guard against wrapping around to address 0. */
89033+ if (address < PAGE_ALIGN(address+1))
89034+ address = PAGE_ALIGN(address+1);
89035+ else
89036+ return -ENOMEM;
89037+
89038 /*
89039 * We must make sure the anon_vma is allocated
89040 * so that the anon_vma locking is not a noop.
89041 */
89042 if (unlikely(anon_vma_prepare(vma)))
89043 return -ENOMEM;
89044+ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
89045+ if (locknext && anon_vma_prepare(vma->vm_next))
89046+ return -ENOMEM;
89047 vma_lock_anon_vma(vma);
89048+ if (locknext)
89049+ vma_lock_anon_vma(vma->vm_next);
89050
89051 /*
89052 * vma->vm_start/vm_end cannot change under us because the caller
89053 * is required to hold the mmap_sem in read mode. We need the
89054- * anon_vma lock to serialize against concurrent expand_stacks.
89055- * Also guard against wrapping around to address 0.
89056+ * anon_vma locks to serialize against concurrent expand_stacks
89057+ * and expand_upwards.
89058 */
89059- if (address < PAGE_ALIGN(address+4))
89060- address = PAGE_ALIGN(address+4);
89061- else {
89062- vma_unlock_anon_vma(vma);
89063- return -ENOMEM;
89064- }
89065 error = 0;
89066
89067 /* Somebody else might have raced and expanded it already */
89068- if (address > vma->vm_end) {
89069+ 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)
89070+ error = -ENOMEM;
89071+ else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
89072 unsigned long size, grow;
89073
89074 size = address - vma->vm_start;
89075@@ -2148,6 +2465,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
89076 }
89077 }
89078 }
89079+ if (locknext)
89080+ vma_unlock_anon_vma(vma->vm_next);
89081 vma_unlock_anon_vma(vma);
89082 khugepaged_enter_vma_merge(vma);
89083 validate_mm(vma->vm_mm);
89084@@ -2162,6 +2481,8 @@ int expand_downwards(struct vm_area_struct *vma,
89085 unsigned long address)
89086 {
89087 int error;
89088+ bool lockprev = false;
89089+ struct vm_area_struct *prev;
89090
89091 /*
89092 * We must make sure the anon_vma is allocated
89093@@ -2175,6 +2496,15 @@ int expand_downwards(struct vm_area_struct *vma,
89094 if (error)
89095 return error;
89096
89097+ prev = vma->vm_prev;
89098+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
89099+ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
89100+#endif
89101+ if (lockprev && anon_vma_prepare(prev))
89102+ return -ENOMEM;
89103+ if (lockprev)
89104+ vma_lock_anon_vma(prev);
89105+
89106 vma_lock_anon_vma(vma);
89107
89108 /*
89109@@ -2184,9 +2514,17 @@ int expand_downwards(struct vm_area_struct *vma,
89110 */
89111
89112 /* Somebody else might have raced and expanded it already */
89113- if (address < vma->vm_start) {
89114+ if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
89115+ error = -ENOMEM;
89116+ else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
89117 unsigned long size, grow;
89118
89119+#ifdef CONFIG_PAX_SEGMEXEC
89120+ struct vm_area_struct *vma_m;
89121+
89122+ vma_m = pax_find_mirror_vma(vma);
89123+#endif
89124+
89125 size = vma->vm_end - address;
89126 grow = (vma->vm_start - address) >> PAGE_SHIFT;
89127
89128@@ -2211,13 +2549,27 @@ int expand_downwards(struct vm_area_struct *vma,
89129 vma->vm_pgoff -= grow;
89130 anon_vma_interval_tree_post_update_vma(vma);
89131 vma_gap_update(vma);
89132+
89133+#ifdef CONFIG_PAX_SEGMEXEC
89134+ if (vma_m) {
89135+ anon_vma_interval_tree_pre_update_vma(vma_m);
89136+ vma_m->vm_start -= grow << PAGE_SHIFT;
89137+ vma_m->vm_pgoff -= grow;
89138+ anon_vma_interval_tree_post_update_vma(vma_m);
89139+ vma_gap_update(vma_m);
89140+ }
89141+#endif
89142+
89143 spin_unlock(&vma->vm_mm->page_table_lock);
89144
89145+ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
89146 perf_event_mmap(vma);
89147 }
89148 }
89149 }
89150 vma_unlock_anon_vma(vma);
89151+ if (lockprev)
89152+ vma_unlock_anon_vma(prev);
89153 khugepaged_enter_vma_merge(vma);
89154 validate_mm(vma->vm_mm);
89155 return error;
89156@@ -2315,6 +2667,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
89157 do {
89158 long nrpages = vma_pages(vma);
89159
89160+#ifdef CONFIG_PAX_SEGMEXEC
89161+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
89162+ vma = remove_vma(vma);
89163+ continue;
89164+ }
89165+#endif
89166+
89167 if (vma->vm_flags & VM_ACCOUNT)
89168 nr_accounted += nrpages;
89169 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
89170@@ -2359,6 +2718,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
89171 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
89172 vma->vm_prev = NULL;
89173 do {
89174+
89175+#ifdef CONFIG_PAX_SEGMEXEC
89176+ if (vma->vm_mirror) {
89177+ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
89178+ vma->vm_mirror->vm_mirror = NULL;
89179+ vma->vm_mirror->vm_flags &= ~VM_EXEC;
89180+ vma->vm_mirror = NULL;
89181+ }
89182+#endif
89183+
89184 vma_rb_erase(vma, &mm->mm_rb);
89185 mm->map_count--;
89186 tail_vma = vma;
89187@@ -2384,14 +2753,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
89188 struct vm_area_struct *new;
89189 int err = -ENOMEM;
89190
89191+#ifdef CONFIG_PAX_SEGMEXEC
89192+ struct vm_area_struct *vma_m, *new_m = NULL;
89193+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
89194+#endif
89195+
89196 if (is_vm_hugetlb_page(vma) && (addr &
89197 ~(huge_page_mask(hstate_vma(vma)))))
89198 return -EINVAL;
89199
89200+#ifdef CONFIG_PAX_SEGMEXEC
89201+ vma_m = pax_find_mirror_vma(vma);
89202+#endif
89203+
89204 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
89205 if (!new)
89206 goto out_err;
89207
89208+#ifdef CONFIG_PAX_SEGMEXEC
89209+ if (vma_m) {
89210+ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
89211+ if (!new_m) {
89212+ kmem_cache_free(vm_area_cachep, new);
89213+ goto out_err;
89214+ }
89215+ }
89216+#endif
89217+
89218 /* most fields are the same, copy all, and then fixup */
89219 *new = *vma;
89220
89221@@ -2404,6 +2792,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
89222 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
89223 }
89224
89225+#ifdef CONFIG_PAX_SEGMEXEC
89226+ if (vma_m) {
89227+ *new_m = *vma_m;
89228+ INIT_LIST_HEAD(&new_m->anon_vma_chain);
89229+ new_m->vm_mirror = new;
89230+ new->vm_mirror = new_m;
89231+
89232+ if (new_below)
89233+ new_m->vm_end = addr_m;
89234+ else {
89235+ new_m->vm_start = addr_m;
89236+ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
89237+ }
89238+ }
89239+#endif
89240+
89241 err = vma_dup_policy(vma, new);
89242 if (err)
89243 goto out_free_vma;
89244@@ -2423,6 +2827,38 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
89245 else
89246 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
89247
89248+#ifdef CONFIG_PAX_SEGMEXEC
89249+ if (!err && vma_m) {
89250+ struct mempolicy *pol = vma_policy(new);
89251+
89252+ if (anon_vma_clone(new_m, vma_m))
89253+ goto out_free_mpol;
89254+
89255+ mpol_get(pol);
89256+ set_vma_policy(new_m, pol);
89257+
89258+ if (new_m->vm_file)
89259+ get_file(new_m->vm_file);
89260+
89261+ if (new_m->vm_ops && new_m->vm_ops->open)
89262+ new_m->vm_ops->open(new_m);
89263+
89264+ if (new_below)
89265+ err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
89266+ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
89267+ else
89268+ err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
89269+
89270+ if (err) {
89271+ if (new_m->vm_ops && new_m->vm_ops->close)
89272+ new_m->vm_ops->close(new_m);
89273+ if (new_m->vm_file)
89274+ fput(new_m->vm_file);
89275+ mpol_put(pol);
89276+ }
89277+ }
89278+#endif
89279+
89280 /* Success. */
89281 if (!err)
89282 return 0;
89283@@ -2432,10 +2868,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
89284 new->vm_ops->close(new);
89285 if (new->vm_file)
89286 fput(new->vm_file);
89287- unlink_anon_vmas(new);
89288 out_free_mpol:
89289 mpol_put(vma_policy(new));
89290 out_free_vma:
89291+
89292+#ifdef CONFIG_PAX_SEGMEXEC
89293+ if (new_m) {
89294+ unlink_anon_vmas(new_m);
89295+ kmem_cache_free(vm_area_cachep, new_m);
89296+ }
89297+#endif
89298+
89299+ unlink_anon_vmas(new);
89300 kmem_cache_free(vm_area_cachep, new);
89301 out_err:
89302 return err;
89303@@ -2448,6 +2892,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
89304 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
89305 unsigned long addr, int new_below)
89306 {
89307+
89308+#ifdef CONFIG_PAX_SEGMEXEC
89309+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
89310+ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
89311+ if (mm->map_count >= sysctl_max_map_count-1)
89312+ return -ENOMEM;
89313+ } else
89314+#endif
89315+
89316 if (mm->map_count >= sysctl_max_map_count)
89317 return -ENOMEM;
89318
89319@@ -2459,11 +2912,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
89320 * work. This now handles partial unmappings.
89321 * Jeremy Fitzhardinge <jeremy@goop.org>
89322 */
89323+#ifdef CONFIG_PAX_SEGMEXEC
89324 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
89325 {
89326+ int ret = __do_munmap(mm, start, len);
89327+ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
89328+ return ret;
89329+
89330+ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
89331+}
89332+
89333+int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
89334+#else
89335+int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
89336+#endif
89337+{
89338 unsigned long end;
89339 struct vm_area_struct *vma, *prev, *last;
89340
89341+ /*
89342+ * mm->mmap_sem is required to protect against another thread
89343+ * changing the mappings in case we sleep.
89344+ */
89345+ verify_mm_writelocked(mm);
89346+
89347 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
89348 return -EINVAL;
89349
89350@@ -2538,6 +3010,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
89351 /* Fix up all other VM information */
89352 remove_vma_list(mm, vma);
89353
89354+ track_exec_limit(mm, start, end, 0UL);
89355+
89356 return 0;
89357 }
89358
89359@@ -2546,6 +3020,13 @@ int vm_munmap(unsigned long start, size_t len)
89360 int ret;
89361 struct mm_struct *mm = current->mm;
89362
89363+
89364+#ifdef CONFIG_PAX_SEGMEXEC
89365+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
89366+ (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
89367+ return -EINVAL;
89368+#endif
89369+
89370 down_write(&mm->mmap_sem);
89371 ret = do_munmap(mm, start, len);
89372 up_write(&mm->mmap_sem);
89373@@ -2559,16 +3040,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
89374 return vm_munmap(addr, len);
89375 }
89376
89377-static inline void verify_mm_writelocked(struct mm_struct *mm)
89378-{
89379-#ifdef CONFIG_DEBUG_VM
89380- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
89381- WARN_ON(1);
89382- up_read(&mm->mmap_sem);
89383- }
89384-#endif
89385-}
89386-
89387 /*
89388 * this is really a simplified "do_mmap". it only handles
89389 * anonymous maps. eventually we may be able to do some
89390@@ -2582,6 +3053,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
89391 struct rb_node ** rb_link, * rb_parent;
89392 pgoff_t pgoff = addr >> PAGE_SHIFT;
89393 int error;
89394+ unsigned long charged;
89395
89396 len = PAGE_ALIGN(len);
89397 if (!len)
89398@@ -2589,16 +3061,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
89399
89400 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
89401
89402+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
89403+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
89404+ flags &= ~VM_EXEC;
89405+
89406+#ifdef CONFIG_PAX_MPROTECT
89407+ if (mm->pax_flags & MF_PAX_MPROTECT)
89408+ flags &= ~VM_MAYEXEC;
89409+#endif
89410+
89411+ }
89412+#endif
89413+
89414 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
89415 if (error & ~PAGE_MASK)
89416 return error;
89417
89418+ charged = len >> PAGE_SHIFT;
89419+
89420 /*
89421 * mlock MCL_FUTURE?
89422 */
89423 if (mm->def_flags & VM_LOCKED) {
89424 unsigned long locked, lock_limit;
89425- locked = len >> PAGE_SHIFT;
89426+ locked = charged;
89427 locked += mm->locked_vm;
89428 lock_limit = rlimit(RLIMIT_MEMLOCK);
89429 lock_limit >>= PAGE_SHIFT;
89430@@ -2615,21 +3101,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
89431 /*
89432 * Clear old maps. this also does some error checking for us
89433 */
89434- munmap_back:
89435 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
89436 if (do_munmap(mm, addr, len))
89437 return -ENOMEM;
89438- goto munmap_back;
89439+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
89440 }
89441
89442 /* Check against address space limits *after* clearing old maps... */
89443- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
89444+ if (!may_expand_vm(mm, charged))
89445 return -ENOMEM;
89446
89447 if (mm->map_count > sysctl_max_map_count)
89448 return -ENOMEM;
89449
89450- if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
89451+ if (security_vm_enough_memory_mm(mm, charged))
89452 return -ENOMEM;
89453
89454 /* Can we just expand an old private anonymous mapping? */
89455@@ -2643,7 +3128,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
89456 */
89457 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
89458 if (!vma) {
89459- vm_unacct_memory(len >> PAGE_SHIFT);
89460+ vm_unacct_memory(charged);
89461 return -ENOMEM;
89462 }
89463
89464@@ -2657,10 +3142,11 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
89465 vma_link(mm, vma, prev, rb_link, rb_parent);
89466 out:
89467 perf_event_mmap(vma);
89468- mm->total_vm += len >> PAGE_SHIFT;
89469+ mm->total_vm += charged;
89470 if (flags & VM_LOCKED)
89471- mm->locked_vm += (len >> PAGE_SHIFT);
89472+ mm->locked_vm += charged;
89473 vma->vm_flags |= VM_SOFTDIRTY;
89474+ track_exec_limit(mm, addr, addr + len, flags);
89475 return addr;
89476 }
89477
89478@@ -2722,6 +3208,7 @@ void exit_mmap(struct mm_struct *mm)
89479 while (vma) {
89480 if (vma->vm_flags & VM_ACCOUNT)
89481 nr_accounted += vma_pages(vma);
89482+ vma->vm_mirror = NULL;
89483 vma = remove_vma(vma);
89484 }
89485 vm_unacct_memory(nr_accounted);
89486@@ -2738,6 +3225,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
89487 struct vm_area_struct *prev;
89488 struct rb_node **rb_link, *rb_parent;
89489
89490+#ifdef CONFIG_PAX_SEGMEXEC
89491+ struct vm_area_struct *vma_m = NULL;
89492+#endif
89493+
89494+ if (security_mmap_addr(vma->vm_start))
89495+ return -EPERM;
89496+
89497 /*
89498 * The vm_pgoff of a purely anonymous vma should be irrelevant
89499 * until its first write fault, when page's anon_vma and index
89500@@ -2761,7 +3255,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
89501 security_vm_enough_memory_mm(mm, vma_pages(vma)))
89502 return -ENOMEM;
89503
89504+#ifdef CONFIG_PAX_SEGMEXEC
89505+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
89506+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
89507+ if (!vma_m)
89508+ return -ENOMEM;
89509+ }
89510+#endif
89511+
89512 vma_link(mm, vma, prev, rb_link, rb_parent);
89513+
89514+#ifdef CONFIG_PAX_SEGMEXEC
89515+ if (vma_m)
89516+ BUG_ON(pax_mirror_vma(vma_m, vma));
89517+#endif
89518+
89519 return 0;
89520 }
89521
89522@@ -2780,6 +3288,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
89523 struct rb_node **rb_link, *rb_parent;
89524 bool faulted_in_anon_vma = true;
89525
89526+ BUG_ON(vma->vm_mirror);
89527+
89528 /*
89529 * If anonymous vma has not yet been faulted, update new pgoff
89530 * to match new location, to increase its chance of merging.
89531@@ -2844,6 +3354,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
89532 return NULL;
89533 }
89534
89535+#ifdef CONFIG_PAX_SEGMEXEC
89536+long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
89537+{
89538+ struct vm_area_struct *prev_m;
89539+ struct rb_node **rb_link_m, *rb_parent_m;
89540+ struct mempolicy *pol_m;
89541+
89542+ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
89543+ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
89544+ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
89545+ *vma_m = *vma;
89546+ INIT_LIST_HEAD(&vma_m->anon_vma_chain);
89547+ if (anon_vma_clone(vma_m, vma))
89548+ return -ENOMEM;
89549+ pol_m = vma_policy(vma_m);
89550+ mpol_get(pol_m);
89551+ set_vma_policy(vma_m, pol_m);
89552+ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
89553+ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
89554+ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
89555+ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
89556+ if (vma_m->vm_file)
89557+ get_file(vma_m->vm_file);
89558+ if (vma_m->vm_ops && vma_m->vm_ops->open)
89559+ vma_m->vm_ops->open(vma_m);
89560+ BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
89561+ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
89562+ vma_m->vm_mirror = vma;
89563+ vma->vm_mirror = vma_m;
89564+ return 0;
89565+}
89566+#endif
89567+
89568 /*
89569 * Return true if the calling process may expand its vm space by the passed
89570 * number of pages
89571@@ -2855,6 +3398,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
89572
89573 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
89574
89575+ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
89576 if (cur + npages > lim)
89577 return 0;
89578 return 1;
89579@@ -2925,6 +3469,22 @@ int install_special_mapping(struct mm_struct *mm,
89580 vma->vm_start = addr;
89581 vma->vm_end = addr + len;
89582
89583+#ifdef CONFIG_PAX_MPROTECT
89584+ if (mm->pax_flags & MF_PAX_MPROTECT) {
89585+#ifndef CONFIG_PAX_MPROTECT_COMPAT
89586+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
89587+ return -EPERM;
89588+ if (!(vm_flags & VM_EXEC))
89589+ vm_flags &= ~VM_MAYEXEC;
89590+#else
89591+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
89592+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
89593+#endif
89594+ else
89595+ vm_flags &= ~VM_MAYWRITE;
89596+ }
89597+#endif
89598+
89599 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND | VM_SOFTDIRTY;
89600 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
89601
89602diff --git a/mm/mprotect.c b/mm/mprotect.c
89603index 412ba2b..cb41d42 100644
89604--- a/mm/mprotect.c
89605+++ b/mm/mprotect.c
89606@@ -23,10 +23,18 @@
89607 #include <linux/mmu_notifier.h>
89608 #include <linux/migrate.h>
89609 #include <linux/perf_event.h>
89610+#include <linux/sched/sysctl.h>
89611+
89612+#ifdef CONFIG_PAX_MPROTECT
89613+#include <linux/elf.h>
89614+#include <linux/binfmts.h>
89615+#endif
89616+
89617 #include <asm/uaccess.h>
89618 #include <asm/pgtable.h>
89619 #include <asm/cacheflush.h>
89620 #include <asm/tlbflush.h>
89621+#include <asm/mmu_context.h>
89622
89623 #ifndef pgprot_modify
89624 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
89625@@ -236,6 +244,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
89626 return pages;
89627 }
89628
89629+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
89630+/* called while holding the mmap semaphor for writing except stack expansion */
89631+void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
89632+{
89633+ unsigned long oldlimit, newlimit = 0UL;
89634+
89635+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
89636+ return;
89637+
89638+ spin_lock(&mm->page_table_lock);
89639+ oldlimit = mm->context.user_cs_limit;
89640+ if ((prot & VM_EXEC) && oldlimit < end)
89641+ /* USER_CS limit moved up */
89642+ newlimit = end;
89643+ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
89644+ /* USER_CS limit moved down */
89645+ newlimit = start;
89646+
89647+ if (newlimit) {
89648+ mm->context.user_cs_limit = newlimit;
89649+
89650+#ifdef CONFIG_SMP
89651+ wmb();
89652+ cpus_clear(mm->context.cpu_user_cs_mask);
89653+ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
89654+#endif
89655+
89656+ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
89657+ }
89658+ spin_unlock(&mm->page_table_lock);
89659+ if (newlimit == end) {
89660+ struct vm_area_struct *vma = find_vma(mm, oldlimit);
89661+
89662+ for (; vma && vma->vm_start < end; vma = vma->vm_next)
89663+ if (is_vm_hugetlb_page(vma))
89664+ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
89665+ else
89666+ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
89667+ }
89668+}
89669+#endif
89670+
89671 int
89672 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
89673 unsigned long start, unsigned long end, unsigned long newflags)
89674@@ -248,11 +298,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
89675 int error;
89676 int dirty_accountable = 0;
89677
89678+#ifdef CONFIG_PAX_SEGMEXEC
89679+ struct vm_area_struct *vma_m = NULL;
89680+ unsigned long start_m, end_m;
89681+
89682+ start_m = start + SEGMEXEC_TASK_SIZE;
89683+ end_m = end + SEGMEXEC_TASK_SIZE;
89684+#endif
89685+
89686 if (newflags == oldflags) {
89687 *pprev = vma;
89688 return 0;
89689 }
89690
89691+ if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
89692+ struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
89693+
89694+ if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
89695+ return -ENOMEM;
89696+
89697+ if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
89698+ return -ENOMEM;
89699+ }
89700+
89701 /*
89702 * If we make a private mapping writable we increase our commit;
89703 * but (without finer accounting) cannot reduce our commit if we
89704@@ -269,6 +337,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
89705 }
89706 }
89707
89708+#ifdef CONFIG_PAX_SEGMEXEC
89709+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
89710+ if (start != vma->vm_start) {
89711+ error = split_vma(mm, vma, start, 1);
89712+ if (error)
89713+ goto fail;
89714+ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
89715+ *pprev = (*pprev)->vm_next;
89716+ }
89717+
89718+ if (end != vma->vm_end) {
89719+ error = split_vma(mm, vma, end, 0);
89720+ if (error)
89721+ goto fail;
89722+ }
89723+
89724+ if (pax_find_mirror_vma(vma)) {
89725+ error = __do_munmap(mm, start_m, end_m - start_m);
89726+ if (error)
89727+ goto fail;
89728+ } else {
89729+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
89730+ if (!vma_m) {
89731+ error = -ENOMEM;
89732+ goto fail;
89733+ }
89734+ vma->vm_flags = newflags;
89735+ error = pax_mirror_vma(vma_m, vma);
89736+ if (error) {
89737+ vma->vm_flags = oldflags;
89738+ goto fail;
89739+ }
89740+ }
89741+ }
89742+#endif
89743+
89744 /*
89745 * First try to merge with previous and/or next vma.
89746 */
89747@@ -299,9 +403,21 @@ success:
89748 * vm_flags and vm_page_prot are protected by the mmap_sem
89749 * held in write mode.
89750 */
89751+
89752+#ifdef CONFIG_PAX_SEGMEXEC
89753+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
89754+ pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
89755+#endif
89756+
89757 vma->vm_flags = newflags;
89758+
89759+#ifdef CONFIG_PAX_MPROTECT
89760+ if (mm->binfmt && mm->binfmt->handle_mprotect)
89761+ mm->binfmt->handle_mprotect(vma, newflags);
89762+#endif
89763+
89764 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
89765- vm_get_page_prot(newflags));
89766+ vm_get_page_prot(vma->vm_flags));
89767
89768 if (vma_wants_writenotify(vma)) {
89769 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
89770@@ -340,6 +456,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
89771 end = start + len;
89772 if (end <= start)
89773 return -ENOMEM;
89774+
89775+#ifdef CONFIG_PAX_SEGMEXEC
89776+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
89777+ if (end > SEGMEXEC_TASK_SIZE)
89778+ return -EINVAL;
89779+ } else
89780+#endif
89781+
89782+ if (end > TASK_SIZE)
89783+ return -EINVAL;
89784+
89785 if (!arch_validate_prot(prot))
89786 return -EINVAL;
89787
89788@@ -347,7 +474,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
89789 /*
89790 * Does the application expect PROT_READ to imply PROT_EXEC:
89791 */
89792- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
89793+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
89794 prot |= PROT_EXEC;
89795
89796 vm_flags = calc_vm_prot_bits(prot);
89797@@ -379,6 +506,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
89798 if (start > vma->vm_start)
89799 prev = vma;
89800
89801+#ifdef CONFIG_PAX_MPROTECT
89802+ if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
89803+ current->mm->binfmt->handle_mprotect(vma, vm_flags);
89804+#endif
89805+
89806 for (nstart = start ; ; ) {
89807 unsigned long newflags;
89808
89809@@ -389,6 +521,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
89810
89811 /* newflags >> 4 shift VM_MAY% in place of VM_% */
89812 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
89813+ if (prot & (PROT_WRITE | PROT_EXEC))
89814+ gr_log_rwxmprotect(vma);
89815+
89816+ error = -EACCES;
89817+ goto out;
89818+ }
89819+
89820+ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
89821 error = -EACCES;
89822 goto out;
89823 }
89824@@ -403,6 +543,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
89825 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
89826 if (error)
89827 goto out;
89828+
89829+ track_exec_limit(current->mm, nstart, tmp, vm_flags);
89830+
89831 nstart = tmp;
89832
89833 if (nstart < prev->vm_end)
89834diff --git a/mm/mremap.c b/mm/mremap.c
89835index 0843feb..4f5b2e6 100644
89836--- a/mm/mremap.c
89837+++ b/mm/mremap.c
89838@@ -144,6 +144,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
89839 continue;
89840 pte = ptep_get_and_clear(mm, old_addr, old_pte);
89841 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
89842+
89843+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
89844+ if (!(__supported_pte_mask & _PAGE_NX) && pte_present(pte) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
89845+ pte = pte_exprotect(pte);
89846+#endif
89847+
89848 pte = move_soft_dirty_pte(pte);
89849 set_pte_at(mm, new_addr, new_pte, pte);
89850 }
89851@@ -337,6 +343,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
89852 if (is_vm_hugetlb_page(vma))
89853 goto Einval;
89854
89855+#ifdef CONFIG_PAX_SEGMEXEC
89856+ if (pax_find_mirror_vma(vma))
89857+ goto Einval;
89858+#endif
89859+
89860 /* We can't remap across vm area boundaries */
89861 if (old_len > vma->vm_end - addr)
89862 goto Efault;
89863@@ -392,20 +403,25 @@ static unsigned long mremap_to(unsigned long addr, unsigned long old_len,
89864 unsigned long ret = -EINVAL;
89865 unsigned long charged = 0;
89866 unsigned long map_flags;
89867+ unsigned long pax_task_size = TASK_SIZE;
89868
89869 if (new_addr & ~PAGE_MASK)
89870 goto out;
89871
89872- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
89873+#ifdef CONFIG_PAX_SEGMEXEC
89874+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
89875+ pax_task_size = SEGMEXEC_TASK_SIZE;
89876+#endif
89877+
89878+ pax_task_size -= PAGE_SIZE;
89879+
89880+ if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
89881 goto out;
89882
89883 /* Check if the location we're moving into overlaps the
89884 * old location at all, and fail if it does.
89885 */
89886- if ((new_addr <= addr) && (new_addr+new_len) > addr)
89887- goto out;
89888-
89889- if ((addr <= new_addr) && (addr+old_len) > new_addr)
89890+ if (addr + old_len > new_addr && new_addr + new_len > addr)
89891 goto out;
89892
89893 ret = do_munmap(mm, new_addr, new_len);
89894@@ -474,6 +490,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
89895 unsigned long ret = -EINVAL;
89896 unsigned long charged = 0;
89897 bool locked = false;
89898+ unsigned long pax_task_size = TASK_SIZE;
89899
89900 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
89901 return ret;
89902@@ -495,6 +512,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
89903 if (!new_len)
89904 return ret;
89905
89906+#ifdef CONFIG_PAX_SEGMEXEC
89907+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
89908+ pax_task_size = SEGMEXEC_TASK_SIZE;
89909+#endif
89910+
89911+ pax_task_size -= PAGE_SIZE;
89912+
89913+ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
89914+ old_len > pax_task_size || addr > pax_task_size-old_len)
89915+ return ret;
89916+
89917 down_write(&current->mm->mmap_sem);
89918
89919 if (flags & MREMAP_FIXED) {
89920@@ -545,6 +573,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
89921 new_addr = addr;
89922 }
89923 ret = addr;
89924+ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
89925 goto out;
89926 }
89927 }
89928@@ -568,7 +597,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
89929 goto out;
89930 }
89931
89932+ map_flags = vma->vm_flags;
89933 ret = move_vma(vma, addr, old_len, new_len, new_addr, &locked);
89934+ if (!(ret & ~PAGE_MASK)) {
89935+ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
89936+ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
89937+ }
89938 }
89939 out:
89940 if (ret & ~PAGE_MASK)
89941diff --git a/mm/nommu.c b/mm/nommu.c
89942index ecd1f15..77039bd 100644
89943--- a/mm/nommu.c
89944+++ b/mm/nommu.c
89945@@ -64,7 +64,6 @@ int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
89946 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
89947 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
89948 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
89949-int heap_stack_gap = 0;
89950
89951 atomic_long_t mmap_pages_allocated;
89952
89953@@ -844,15 +843,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
89954 EXPORT_SYMBOL(find_vma);
89955
89956 /*
89957- * find a VMA
89958- * - we don't extend stack VMAs under NOMMU conditions
89959- */
89960-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
89961-{
89962- return find_vma(mm, addr);
89963-}
89964-
89965-/*
89966 * expand a stack to a given address
89967 * - not supported under NOMMU conditions
89968 */
89969@@ -1563,6 +1553,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
89970
89971 /* most fields are the same, copy all, and then fixup */
89972 *new = *vma;
89973+ INIT_LIST_HEAD(&new->anon_vma_chain);
89974 *region = *vma->vm_region;
89975 new->vm_region = region;
89976
89977@@ -1993,8 +1984,8 @@ int generic_file_remap_pages(struct vm_area_struct *vma, unsigned long addr,
89978 }
89979 EXPORT_SYMBOL(generic_file_remap_pages);
89980
89981-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
89982- unsigned long addr, void *buf, int len, int write)
89983+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
89984+ unsigned long addr, void *buf, size_t len, int write)
89985 {
89986 struct vm_area_struct *vma;
89987
89988@@ -2035,8 +2026,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
89989 *
89990 * The caller must hold a reference on @mm.
89991 */
89992-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
89993- void *buf, int len, int write)
89994+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
89995+ void *buf, size_t len, int write)
89996 {
89997 return __access_remote_vm(NULL, mm, addr, buf, len, write);
89998 }
89999@@ -2045,7 +2036,7 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
90000 * Access another process' address space.
90001 * - source/target buffer must be kernel space
90002 */
90003-int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write)
90004+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write)
90005 {
90006 struct mm_struct *mm;
90007
90008diff --git a/mm/page-writeback.c b/mm/page-writeback.c
90009index 6380758..4064aec 100644
90010--- a/mm/page-writeback.c
90011+++ b/mm/page-writeback.c
90012@@ -690,7 +690,7 @@ static inline long long pos_ratio_polynom(unsigned long setpoint,
90013 * card's bdi_dirty may rush to many times higher than bdi_setpoint.
90014 * - the bdi dirty thresh drops quickly due to change of JBOD workload
90015 */
90016-static unsigned long bdi_position_ratio(struct backing_dev_info *bdi,
90017+static unsigned long __intentional_overflow(-1) bdi_position_ratio(struct backing_dev_info *bdi,
90018 unsigned long thresh,
90019 unsigned long bg_thresh,
90020 unsigned long dirty,
90021diff --git a/mm/page_alloc.c b/mm/page_alloc.c
90022index dd886fa..7686339 100644
90023--- a/mm/page_alloc.c
90024+++ b/mm/page_alloc.c
90025@@ -61,6 +61,7 @@
90026 #include <linux/page-debug-flags.h>
90027 #include <linux/hugetlb.h>
90028 #include <linux/sched/rt.h>
90029+#include <linux/random.h>
90030
90031 #include <asm/sections.h>
90032 #include <asm/tlbflush.h>
90033@@ -354,7 +355,7 @@ out:
90034 * This usage means that zero-order pages may not be compound.
90035 */
90036
90037-static void free_compound_page(struct page *page)
90038+void free_compound_page(struct page *page)
90039 {
90040 __free_pages_ok(page, compound_order(page));
90041 }
90042@@ -712,6 +713,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
90043 int i;
90044 int bad = 0;
90045
90046+#ifdef CONFIG_PAX_MEMORY_SANITIZE
90047+ unsigned long index = 1UL << order;
90048+#endif
90049+
90050 trace_mm_page_free(page, order);
90051 kmemcheck_free_shadow(page, order);
90052
90053@@ -728,6 +733,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
90054 debug_check_no_obj_freed(page_address(page),
90055 PAGE_SIZE << order);
90056 }
90057+
90058+#ifdef CONFIG_PAX_MEMORY_SANITIZE
90059+ for (; index; --index)
90060+ sanitize_highpage(page + index - 1);
90061+#endif
90062+
90063 arch_free_page(page, order);
90064 kernel_map_pages(page, 1 << order, 0);
90065
90066@@ -750,6 +761,20 @@ static void __free_pages_ok(struct page *page, unsigned int order)
90067 local_irq_restore(flags);
90068 }
90069
90070+#ifdef CONFIG_PAX_LATENT_ENTROPY
90071+bool __meminitdata extra_latent_entropy;
90072+
90073+static int __init setup_pax_extra_latent_entropy(char *str)
90074+{
90075+ extra_latent_entropy = true;
90076+ return 0;
90077+}
90078+early_param("pax_extra_latent_entropy", setup_pax_extra_latent_entropy);
90079+
90080+volatile u64 latent_entropy __latent_entropy;
90081+EXPORT_SYMBOL(latent_entropy);
90082+#endif
90083+
90084 void __init __free_pages_bootmem(struct page *page, unsigned int order)
90085 {
90086 unsigned int nr_pages = 1 << order;
90087@@ -765,6 +790,19 @@ void __init __free_pages_bootmem(struct page *page, unsigned int order)
90088 __ClearPageReserved(p);
90089 set_page_count(p, 0);
90090
90091+#ifdef CONFIG_PAX_LATENT_ENTROPY
90092+ if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) {
90093+ u64 hash = 0;
90094+ size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
90095+ const u64 *data = lowmem_page_address(page);
90096+
90097+ for (index = 0; index < end; index++)
90098+ hash ^= hash + data[index];
90099+ latent_entropy ^= hash;
90100+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
90101+ }
90102+#endif
90103+
90104 page_zone(page)->managed_pages += nr_pages;
90105 set_page_refcounted(page);
90106 __free_pages(page, order);
90107@@ -870,8 +908,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
90108 arch_alloc_page(page, order);
90109 kernel_map_pages(page, 1 << order, 1);
90110
90111+#ifndef CONFIG_PAX_MEMORY_SANITIZE
90112 if (gfp_flags & __GFP_ZERO)
90113 prep_zero_page(page, order, gfp_flags);
90114+#endif
90115
90116 if (order && (gfp_flags & __GFP_COMP))
90117 prep_compound_page(page, order);
90118diff --git a/mm/page_io.c b/mm/page_io.c
90119index 8c79a47..a689e0d 100644
90120--- a/mm/page_io.c
90121+++ b/mm/page_io.c
90122@@ -260,7 +260,7 @@ int __swap_writepage(struct page *page, struct writeback_control *wbc,
90123 struct file *swap_file = sis->swap_file;
90124 struct address_space *mapping = swap_file->f_mapping;
90125 struct iovec iov = {
90126- .iov_base = kmap(page),
90127+ .iov_base = (void __force_user *)kmap(page),
90128 .iov_len = PAGE_SIZE,
90129 };
90130
90131diff --git a/mm/percpu.c b/mm/percpu.c
90132index 8c8e08f..73a5cda 100644
90133--- a/mm/percpu.c
90134+++ b/mm/percpu.c
90135@@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
90136 static unsigned int pcpu_high_unit_cpu __read_mostly;
90137
90138 /* the address of the first chunk which starts with the kernel static area */
90139-void *pcpu_base_addr __read_mostly;
90140+void *pcpu_base_addr __read_only;
90141 EXPORT_SYMBOL_GPL(pcpu_base_addr);
90142
90143 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
90144diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
90145index fd26d04..0cea1b0 100644
90146--- a/mm/process_vm_access.c
90147+++ b/mm/process_vm_access.c
90148@@ -13,6 +13,7 @@
90149 #include <linux/uio.h>
90150 #include <linux/sched.h>
90151 #include <linux/highmem.h>
90152+#include <linux/security.h>
90153 #include <linux/ptrace.h>
90154 #include <linux/slab.h>
90155 #include <linux/syscalls.h>
90156@@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
90157 size_t iov_l_curr_offset = 0;
90158 ssize_t iov_len;
90159
90160+ return -ENOSYS; // PaX: until properly audited
90161+
90162 /*
90163 * Work out how many pages of struct pages we're going to need
90164 * when eventually calling get_user_pages
90165 */
90166 for (i = 0; i < riovcnt; i++) {
90167 iov_len = rvec[i].iov_len;
90168- if (iov_len > 0) {
90169- nr_pages_iov = ((unsigned long)rvec[i].iov_base
90170- + iov_len)
90171- / PAGE_SIZE - (unsigned long)rvec[i].iov_base
90172- / PAGE_SIZE + 1;
90173- nr_pages = max(nr_pages, nr_pages_iov);
90174- }
90175+ if (iov_len <= 0)
90176+ continue;
90177+ nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
90178+ (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
90179+ nr_pages = max(nr_pages, nr_pages_iov);
90180 }
90181
90182 if (nr_pages == 0)
90183@@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
90184 goto free_proc_pages;
90185 }
90186
90187+ if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
90188+ rc = -EPERM;
90189+ goto put_task_struct;
90190+ }
90191+
90192 mm = mm_access(task, PTRACE_MODE_ATTACH);
90193 if (!mm || IS_ERR(mm)) {
90194 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
90195diff --git a/mm/rmap.c b/mm/rmap.c
90196index fd3ee7a..3613079 100644
90197--- a/mm/rmap.c
90198+++ b/mm/rmap.c
90199@@ -163,6 +163,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
90200 struct anon_vma *anon_vma = vma->anon_vma;
90201 struct anon_vma_chain *avc;
90202
90203+#ifdef CONFIG_PAX_SEGMEXEC
90204+ struct anon_vma_chain *avc_m = NULL;
90205+#endif
90206+
90207 might_sleep();
90208 if (unlikely(!anon_vma)) {
90209 struct mm_struct *mm = vma->vm_mm;
90210@@ -172,6 +176,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
90211 if (!avc)
90212 goto out_enomem;
90213
90214+#ifdef CONFIG_PAX_SEGMEXEC
90215+ avc_m = anon_vma_chain_alloc(GFP_KERNEL);
90216+ if (!avc_m)
90217+ goto out_enomem_free_avc;
90218+#endif
90219+
90220 anon_vma = find_mergeable_anon_vma(vma);
90221 allocated = NULL;
90222 if (!anon_vma) {
90223@@ -185,6 +195,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
90224 /* page_table_lock to protect against threads */
90225 spin_lock(&mm->page_table_lock);
90226 if (likely(!vma->anon_vma)) {
90227+
90228+#ifdef CONFIG_PAX_SEGMEXEC
90229+ struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
90230+
90231+ if (vma_m) {
90232+ BUG_ON(vma_m->anon_vma);
90233+ vma_m->anon_vma = anon_vma;
90234+ anon_vma_chain_link(vma_m, avc_m, anon_vma);
90235+ avc_m = NULL;
90236+ }
90237+#endif
90238+
90239 vma->anon_vma = anon_vma;
90240 anon_vma_chain_link(vma, avc, anon_vma);
90241 allocated = NULL;
90242@@ -195,12 +217,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
90243
90244 if (unlikely(allocated))
90245 put_anon_vma(allocated);
90246+
90247+#ifdef CONFIG_PAX_SEGMEXEC
90248+ if (unlikely(avc_m))
90249+ anon_vma_chain_free(avc_m);
90250+#endif
90251+
90252 if (unlikely(avc))
90253 anon_vma_chain_free(avc);
90254 }
90255 return 0;
90256
90257 out_enomem_free_avc:
90258+
90259+#ifdef CONFIG_PAX_SEGMEXEC
90260+ if (avc_m)
90261+ anon_vma_chain_free(avc_m);
90262+#endif
90263+
90264 anon_vma_chain_free(avc);
90265 out_enomem:
90266 return -ENOMEM;
90267@@ -236,7 +270,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
90268 * Attach the anon_vmas from src to dst.
90269 * Returns 0 on success, -ENOMEM on failure.
90270 */
90271-int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
90272+int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
90273 {
90274 struct anon_vma_chain *avc, *pavc;
90275 struct anon_vma *root = NULL;
90276@@ -269,7 +303,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
90277 * the corresponding VMA in the parent process is attached to.
90278 * Returns 0 on success, non-zero on failure.
90279 */
90280-int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
90281+int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
90282 {
90283 struct anon_vma_chain *avc;
90284 struct anon_vma *anon_vma;
90285@@ -373,8 +407,10 @@ static void anon_vma_ctor(void *data)
90286 void __init anon_vma_init(void)
90287 {
90288 anon_vma_cachep = kmem_cache_create("anon_vma", sizeof(struct anon_vma),
90289- 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC, anon_vma_ctor);
90290- anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain, SLAB_PANIC);
90291+ 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC|SLAB_NO_SANITIZE,
90292+ anon_vma_ctor);
90293+ anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain,
90294+ SLAB_PANIC|SLAB_NO_SANITIZE);
90295 }
90296
90297 /*
90298diff --git a/mm/shmem.c b/mm/shmem.c
90299index 8297623..6b9dfe9 100644
90300--- a/mm/shmem.c
90301+++ b/mm/shmem.c
90302@@ -33,7 +33,7 @@
90303 #include <linux/swap.h>
90304 #include <linux/aio.h>
90305
90306-static struct vfsmount *shm_mnt;
90307+struct vfsmount *shm_mnt;
90308
90309 #ifdef CONFIG_SHMEM
90310 /*
90311@@ -77,7 +77,7 @@ static struct vfsmount *shm_mnt;
90312 #define BOGO_DIRENT_SIZE 20
90313
90314 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
90315-#define SHORT_SYMLINK_LEN 128
90316+#define SHORT_SYMLINK_LEN 64
90317
90318 /*
90319 * shmem_fallocate and shmem_writepage communicate via inode->i_private
90320@@ -2232,6 +2232,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
90321 static int shmem_xattr_validate(const char *name)
90322 {
90323 struct { const char *prefix; size_t len; } arr[] = {
90324+
90325+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
90326+ { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
90327+#endif
90328+
90329 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
90330 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
90331 };
90332@@ -2287,6 +2292,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
90333 if (err)
90334 return err;
90335
90336+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
90337+ if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
90338+ if (strcmp(name, XATTR_NAME_PAX_FLAGS))
90339+ return -EOPNOTSUPP;
90340+ if (size > 8)
90341+ return -EINVAL;
90342+ }
90343+#endif
90344+
90345 return simple_xattr_set(&info->xattrs, name, value, size, flags);
90346 }
90347
90348@@ -2599,8 +2613,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
90349 int err = -ENOMEM;
90350
90351 /* Round up to L1_CACHE_BYTES to resist false sharing */
90352- sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
90353- L1_CACHE_BYTES), GFP_KERNEL);
90354+ sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
90355 if (!sbinfo)
90356 return -ENOMEM;
90357
90358diff --git a/mm/slab.c b/mm/slab.c
90359index 2580db0..0523956 100644
90360--- a/mm/slab.c
90361+++ b/mm/slab.c
90362@@ -366,10 +366,12 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
90363 if ((x)->max_freeable < i) \
90364 (x)->max_freeable = i; \
90365 } while (0)
90366-#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
90367-#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
90368-#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
90369-#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
90370+#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
90371+#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
90372+#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
90373+#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
90374+#define STATS_INC_SANITIZED(x) atomic_inc_unchecked(&(x)->sanitized)
90375+#define STATS_INC_NOT_SANITIZED(x) atomic_inc_unchecked(&(x)->not_sanitized)
90376 #else
90377 #define STATS_INC_ACTIVE(x) do { } while (0)
90378 #define STATS_DEC_ACTIVE(x) do { } while (0)
90379@@ -386,6 +388,8 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
90380 #define STATS_INC_ALLOCMISS(x) do { } while (0)
90381 #define STATS_INC_FREEHIT(x) do { } while (0)
90382 #define STATS_INC_FREEMISS(x) do { } while (0)
90383+#define STATS_INC_SANITIZED(x) do { } while (0)
90384+#define STATS_INC_NOT_SANITIZED(x) do { } while (0)
90385 #endif
90386
90387 #if DEBUG
90388@@ -477,7 +481,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
90389 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
90390 */
90391 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
90392- const struct slab *slab, void *obj)
90393+ const struct slab *slab, const void *obj)
90394 {
90395 u32 offset = (obj - slab->s_mem);
90396 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
90397@@ -1571,12 +1575,12 @@ void __init kmem_cache_init(void)
90398 */
90399
90400 kmalloc_caches[INDEX_AC] = create_kmalloc_cache("kmalloc-ac",
90401- kmalloc_size(INDEX_AC), ARCH_KMALLOC_FLAGS);
90402+ kmalloc_size(INDEX_AC), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
90403
90404 if (INDEX_AC != INDEX_NODE)
90405 kmalloc_caches[INDEX_NODE] =
90406 create_kmalloc_cache("kmalloc-node",
90407- kmalloc_size(INDEX_NODE), ARCH_KMALLOC_FLAGS);
90408+ kmalloc_size(INDEX_NODE), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
90409
90410 slab_early_init = 0;
90411
90412@@ -3577,6 +3581,21 @@ static inline void __cache_free(struct kmem_cache *cachep, void *objp,
90413 struct array_cache *ac = cpu_cache_get(cachep);
90414
90415 check_irq_off();
90416+
90417+#ifdef CONFIG_PAX_MEMORY_SANITIZE
90418+ if (pax_sanitize_slab) {
90419+ if (!(cachep->flags & (SLAB_POISON | SLAB_NO_SANITIZE))) {
90420+ memset(objp, PAX_MEMORY_SANITIZE_VALUE, cachep->object_size);
90421+
90422+ if (cachep->ctor)
90423+ cachep->ctor(objp);
90424+
90425+ STATS_INC_SANITIZED(cachep);
90426+ } else
90427+ STATS_INC_NOT_SANITIZED(cachep);
90428+ }
90429+#endif
90430+
90431 kmemleak_free_recursive(objp, cachep->flags);
90432 objp = cache_free_debugcheck(cachep, objp, caller);
90433
90434@@ -3805,6 +3824,7 @@ void kfree(const void *objp)
90435
90436 if (unlikely(ZERO_OR_NULL_PTR(objp)))
90437 return;
90438+ VM_BUG_ON(!virt_addr_valid(objp));
90439 local_irq_save(flags);
90440 kfree_debugcheck(objp);
90441 c = virt_to_cache(objp);
90442@@ -4246,14 +4266,22 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
90443 }
90444 /* cpu stats */
90445 {
90446- unsigned long allochit = atomic_read(&cachep->allochit);
90447- unsigned long allocmiss = atomic_read(&cachep->allocmiss);
90448- unsigned long freehit = atomic_read(&cachep->freehit);
90449- unsigned long freemiss = atomic_read(&cachep->freemiss);
90450+ unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
90451+ unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
90452+ unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
90453+ unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
90454
90455 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
90456 allochit, allocmiss, freehit, freemiss);
90457 }
90458+#ifdef CONFIG_PAX_MEMORY_SANITIZE
90459+ {
90460+ unsigned long sanitized = atomic_read_unchecked(&cachep->sanitized);
90461+ unsigned long not_sanitized = atomic_read_unchecked(&cachep->not_sanitized);
90462+
90463+ seq_printf(m, " : pax %6lu %6lu", sanitized, not_sanitized);
90464+ }
90465+#endif
90466 #endif
90467 }
90468
90469@@ -4471,13 +4499,71 @@ static const struct file_operations proc_slabstats_operations = {
90470 static int __init slab_proc_init(void)
90471 {
90472 #ifdef CONFIG_DEBUG_SLAB_LEAK
90473- proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
90474+ proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
90475 #endif
90476 return 0;
90477 }
90478 module_init(slab_proc_init);
90479 #endif
90480
90481+bool is_usercopy_object(const void *ptr)
90482+{
90483+ struct page *page;
90484+ struct kmem_cache *cachep;
90485+
90486+ if (ZERO_OR_NULL_PTR(ptr))
90487+ return false;
90488+
90489+ if (!slab_is_available())
90490+ return false;
90491+
90492+ if (!virt_addr_valid(ptr))
90493+ return false;
90494+
90495+ page = virt_to_head_page(ptr);
90496+
90497+ if (!PageSlab(page))
90498+ return false;
90499+
90500+ cachep = page->slab_cache;
90501+ return cachep->flags & SLAB_USERCOPY;
90502+}
90503+
90504+#ifdef CONFIG_PAX_USERCOPY
90505+const char *check_heap_object(const void *ptr, unsigned long n)
90506+{
90507+ struct page *page;
90508+ struct kmem_cache *cachep;
90509+ struct slab *slabp;
90510+ unsigned int objnr;
90511+ unsigned long offset;
90512+
90513+ if (ZERO_OR_NULL_PTR(ptr))
90514+ return "<null>";
90515+
90516+ if (!virt_addr_valid(ptr))
90517+ return NULL;
90518+
90519+ page = virt_to_head_page(ptr);
90520+
90521+ if (!PageSlab(page))
90522+ return NULL;
90523+
90524+ cachep = page->slab_cache;
90525+ if (!(cachep->flags & SLAB_USERCOPY))
90526+ return cachep->name;
90527+
90528+ slabp = page->slab_page;
90529+ objnr = obj_to_index(cachep, slabp, ptr);
90530+ BUG_ON(objnr >= cachep->num);
90531+ offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
90532+ if (offset <= cachep->object_size && n <= cachep->object_size - offset)
90533+ return NULL;
90534+
90535+ return cachep->name;
90536+}
90537+#endif
90538+
90539 /**
90540 * ksize - get the actual amount of memory allocated for a given object
90541 * @objp: Pointer to the object
90542diff --git a/mm/slab.h b/mm/slab.h
90543index a535033..2f98fe5 100644
90544--- a/mm/slab.h
90545+++ b/mm/slab.h
90546@@ -32,6 +32,15 @@ extern struct list_head slab_caches;
90547 /* The slab cache that manages slab cache information */
90548 extern struct kmem_cache *kmem_cache;
90549
90550+#ifdef CONFIG_PAX_MEMORY_SANITIZE
90551+#ifdef CONFIG_X86_64
90552+#define PAX_MEMORY_SANITIZE_VALUE '\xfe'
90553+#else
90554+#define PAX_MEMORY_SANITIZE_VALUE '\xff'
90555+#endif
90556+extern bool pax_sanitize_slab;
90557+#endif
90558+
90559 unsigned long calculate_alignment(unsigned long flags,
90560 unsigned long align, unsigned long size);
90561
90562@@ -67,7 +76,8 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
90563
90564 /* Legal flag mask for kmem_cache_create(), for various configurations */
90565 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
90566- SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
90567+ SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | \
90568+ SLAB_USERCOPY | SLAB_NO_SANITIZE)
90569
90570 #if defined(CONFIG_DEBUG_SLAB)
90571 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
90572@@ -231,6 +241,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
90573 return s;
90574
90575 page = virt_to_head_page(x);
90576+
90577+ BUG_ON(!PageSlab(page));
90578+
90579 cachep = page->slab_cache;
90580 if (slab_equal_or_root(cachep, s))
90581 return cachep;
90582diff --git a/mm/slab_common.c b/mm/slab_common.c
90583index e2e98af..3b1a163 100644
90584--- a/mm/slab_common.c
90585+++ b/mm/slab_common.c
90586@@ -23,11 +23,22 @@
90587
90588 #include "slab.h"
90589
90590-enum slab_state slab_state;
90591+enum slab_state slab_state __read_only;
90592 LIST_HEAD(slab_caches);
90593 DEFINE_MUTEX(slab_mutex);
90594 struct kmem_cache *kmem_cache;
90595
90596+#ifdef CONFIG_PAX_MEMORY_SANITIZE
90597+bool pax_sanitize_slab __read_only = true;
90598+static int __init pax_sanitize_slab_setup(char *str)
90599+{
90600+ pax_sanitize_slab = !!simple_strtol(str, NULL, 0);
90601+ printk("%sabled PaX slab sanitization\n", pax_sanitize_slab ? "En" : "Dis");
90602+ return 1;
90603+}
90604+__setup("pax_sanitize_slab=", pax_sanitize_slab_setup);
90605+#endif
90606+
90607 #ifdef CONFIG_DEBUG_VM
90608 static int kmem_cache_sanity_check(struct mem_cgroup *memcg, const char *name,
90609 size_t size)
90610@@ -212,7 +223,7 @@ kmem_cache_create_memcg(struct mem_cgroup *memcg, const char *name, size_t size,
90611
90612 err = __kmem_cache_create(s, flags);
90613 if (!err) {
90614- s->refcount = 1;
90615+ atomic_set(&s->refcount, 1);
90616 list_add(&s->list, &slab_caches);
90617 memcg_cache_list_add(memcg, s);
90618 } else {
90619@@ -258,8 +269,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
90620
90621 get_online_cpus();
90622 mutex_lock(&slab_mutex);
90623- s->refcount--;
90624- if (!s->refcount) {
90625+ if (atomic_dec_and_test(&s->refcount)) {
90626 list_del(&s->list);
90627
90628 if (!__kmem_cache_shutdown(s)) {
90629@@ -305,7 +315,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
90630 panic("Creation of kmalloc slab %s size=%zu failed. Reason %d\n",
90631 name, size, err);
90632
90633- s->refcount = -1; /* Exempt from merging for now */
90634+ atomic_set(&s->refcount, -1); /* Exempt from merging for now */
90635 }
90636
90637 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
90638@@ -318,7 +328,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
90639
90640 create_boot_cache(s, name, size, flags);
90641 list_add(&s->list, &slab_caches);
90642- s->refcount = 1;
90643+ atomic_set(&s->refcount, 1);
90644 return s;
90645 }
90646
90647@@ -330,6 +340,11 @@ struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
90648 EXPORT_SYMBOL(kmalloc_dma_caches);
90649 #endif
90650
90651+#ifdef CONFIG_PAX_USERCOPY_SLABS
90652+struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
90653+EXPORT_SYMBOL(kmalloc_usercopy_caches);
90654+#endif
90655+
90656 /*
90657 * Conversion table for small slabs sizes / 8 to the index in the
90658 * kmalloc array. This is necessary for slabs < 192 since we have non power
90659@@ -394,6 +409,13 @@ struct kmem_cache *kmalloc_slab(size_t size, gfp_t flags)
90660 return kmalloc_dma_caches[index];
90661
90662 #endif
90663+
90664+#ifdef CONFIG_PAX_USERCOPY_SLABS
90665+ if (unlikely((flags & GFP_USERCOPY)))
90666+ return kmalloc_usercopy_caches[index];
90667+
90668+#endif
90669+
90670 return kmalloc_caches[index];
90671 }
90672
90673@@ -450,7 +472,7 @@ void __init create_kmalloc_caches(unsigned long flags)
90674 for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) {
90675 if (!kmalloc_caches[i]) {
90676 kmalloc_caches[i] = create_kmalloc_cache(NULL,
90677- 1 << i, flags);
90678+ 1 << i, SLAB_USERCOPY | flags);
90679 }
90680
90681 /*
90682@@ -459,10 +481,10 @@ void __init create_kmalloc_caches(unsigned long flags)
90683 * earlier power of two caches
90684 */
90685 if (KMALLOC_MIN_SIZE <= 32 && !kmalloc_caches[1] && i == 6)
90686- kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, flags);
90687+ kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, SLAB_USERCOPY | flags);
90688
90689 if (KMALLOC_MIN_SIZE <= 64 && !kmalloc_caches[2] && i == 7)
90690- kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, flags);
90691+ kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, SLAB_USERCOPY | flags);
90692 }
90693
90694 /* Kmalloc array is now usable */
90695@@ -495,6 +517,23 @@ void __init create_kmalloc_caches(unsigned long flags)
90696 }
90697 }
90698 #endif
90699+
90700+#ifdef CONFIG_PAX_USERCOPY_SLABS
90701+ for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) {
90702+ struct kmem_cache *s = kmalloc_caches[i];
90703+
90704+ if (s) {
90705+ int size = kmalloc_size(i);
90706+ char *n = kasprintf(GFP_NOWAIT,
90707+ "usercopy-kmalloc-%d", size);
90708+
90709+ BUG_ON(!n);
90710+ kmalloc_usercopy_caches[i] = create_kmalloc_cache(n,
90711+ size, SLAB_USERCOPY | flags);
90712+ }
90713+ }
90714+#endif
90715+
90716 }
90717 #endif /* !CONFIG_SLOB */
90718
90719@@ -535,6 +574,9 @@ void print_slabinfo_header(struct seq_file *m)
90720 seq_puts(m, " : globalstat <listallocs> <maxobjs> <grown> <reaped> "
90721 "<error> <maxfreeable> <nodeallocs> <remotefrees> <alienoverflow>");
90722 seq_puts(m, " : cpustat <allochit> <allocmiss> <freehit> <freemiss>");
90723+#ifdef CONFIG_PAX_MEMORY_SANITIZE
90724+ seq_puts(m, " : pax <sanitized> <not_sanitized>");
90725+#endif
90726 #endif
90727 seq_putc(m, '\n');
90728 }
90729diff --git a/mm/slob.c b/mm/slob.c
90730index 4bf8809..98a6914 100644
90731--- a/mm/slob.c
90732+++ b/mm/slob.c
90733@@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
90734 /*
90735 * Return the size of a slob block.
90736 */
90737-static slobidx_t slob_units(slob_t *s)
90738+static slobidx_t slob_units(const slob_t *s)
90739 {
90740 if (s->units > 0)
90741 return s->units;
90742@@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
90743 /*
90744 * Return the next free slob block pointer after this one.
90745 */
90746-static slob_t *slob_next(slob_t *s)
90747+static slob_t *slob_next(const slob_t *s)
90748 {
90749 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
90750 slobidx_t next;
90751@@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
90752 /*
90753 * Returns true if s is the last free block in its page.
90754 */
90755-static int slob_last(slob_t *s)
90756+static int slob_last(const slob_t *s)
90757 {
90758 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
90759 }
90760
90761-static void *slob_new_pages(gfp_t gfp, int order, int node)
90762+static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
90763 {
90764- void *page;
90765+ struct page *page;
90766
90767 #ifdef CONFIG_NUMA
90768 if (node != NUMA_NO_NODE)
90769@@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
90770 if (!page)
90771 return NULL;
90772
90773- return page_address(page);
90774+ __SetPageSlab(page);
90775+ return page;
90776 }
90777
90778-static void slob_free_pages(void *b, int order)
90779+static void slob_free_pages(struct page *sp, int order)
90780 {
90781 if (current->reclaim_state)
90782 current->reclaim_state->reclaimed_slab += 1 << order;
90783- free_pages((unsigned long)b, order);
90784+ __ClearPageSlab(sp);
90785+ page_mapcount_reset(sp);
90786+ sp->private = 0;
90787+ __free_pages(sp, order);
90788 }
90789
90790 /*
90791@@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
90792
90793 /* Not enough space: must allocate a new page */
90794 if (!b) {
90795- b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
90796- if (!b)
90797+ sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
90798+ if (!sp)
90799 return NULL;
90800- sp = virt_to_page(b);
90801- __SetPageSlab(sp);
90802+ b = page_address(sp);
90803
90804 spin_lock_irqsave(&slob_lock, flags);
90805 sp->units = SLOB_UNITS(PAGE_SIZE);
90806 sp->freelist = b;
90807+ sp->private = 0;
90808 INIT_LIST_HEAD(&sp->list);
90809 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
90810 set_slob_page_free(sp, slob_list);
90811@@ -359,12 +363,15 @@ static void slob_free(void *block, int size)
90812 if (slob_page_free(sp))
90813 clear_slob_page_free(sp);
90814 spin_unlock_irqrestore(&slob_lock, flags);
90815- __ClearPageSlab(sp);
90816- page_mapcount_reset(sp);
90817- slob_free_pages(b, 0);
90818+ slob_free_pages(sp, 0);
90819 return;
90820 }
90821
90822+#ifdef CONFIG_PAX_MEMORY_SANITIZE
90823+ if (pax_sanitize_slab)
90824+ memset(block, PAX_MEMORY_SANITIZE_VALUE, size);
90825+#endif
90826+
90827 if (!slob_page_free(sp)) {
90828 /* This slob page is about to become partially free. Easy! */
90829 sp->units = units;
90830@@ -424,11 +431,10 @@ out:
90831 */
90832
90833 static __always_inline void *
90834-__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
90835+__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
90836 {
90837- unsigned int *m;
90838- int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
90839- void *ret;
90840+ slob_t *m;
90841+ void *ret = NULL;
90842
90843 gfp &= gfp_allowed_mask;
90844
90845@@ -442,23 +448,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
90846
90847 if (!m)
90848 return NULL;
90849- *m = size;
90850+ BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
90851+ BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
90852+ m[0].units = size;
90853+ m[1].units = align;
90854 ret = (void *)m + align;
90855
90856 trace_kmalloc_node(caller, ret,
90857 size, size + align, gfp, node);
90858 } else {
90859 unsigned int order = get_order(size);
90860+ struct page *page;
90861
90862 if (likely(order))
90863 gfp |= __GFP_COMP;
90864- ret = slob_new_pages(gfp, order, node);
90865+ page = slob_new_pages(gfp, order, node);
90866+ if (page) {
90867+ ret = page_address(page);
90868+ page->private = size;
90869+ }
90870
90871 trace_kmalloc_node(caller, ret,
90872 size, PAGE_SIZE << order, gfp, node);
90873 }
90874
90875- kmemleak_alloc(ret, size, 1, gfp);
90876+ return ret;
90877+}
90878+
90879+static __always_inline void *
90880+__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
90881+{
90882+ int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
90883+ void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
90884+
90885+ if (!ZERO_OR_NULL_PTR(ret))
90886+ kmemleak_alloc(ret, size, 1, gfp);
90887 return ret;
90888 }
90889
90890@@ -493,34 +517,112 @@ void kfree(const void *block)
90891 return;
90892 kmemleak_free(block);
90893
90894+ VM_BUG_ON(!virt_addr_valid(block));
90895 sp = virt_to_page(block);
90896- if (PageSlab(sp)) {
90897+ VM_BUG_ON(!PageSlab(sp));
90898+ if (!sp->private) {
90899 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
90900- unsigned int *m = (unsigned int *)(block - align);
90901- slob_free(m, *m + align);
90902- } else
90903+ slob_t *m = (slob_t *)(block - align);
90904+ slob_free(m, m[0].units + align);
90905+ } else {
90906+ __ClearPageSlab(sp);
90907+ page_mapcount_reset(sp);
90908+ sp->private = 0;
90909 __free_pages(sp, compound_order(sp));
90910+ }
90911 }
90912 EXPORT_SYMBOL(kfree);
90913
90914+bool is_usercopy_object(const void *ptr)
90915+{
90916+ if (!slab_is_available())
90917+ return false;
90918+
90919+ // PAX: TODO
90920+
90921+ return false;
90922+}
90923+
90924+#ifdef CONFIG_PAX_USERCOPY
90925+const char *check_heap_object(const void *ptr, unsigned long n)
90926+{
90927+ struct page *page;
90928+ const slob_t *free;
90929+ const void *base;
90930+ unsigned long flags;
90931+
90932+ if (ZERO_OR_NULL_PTR(ptr))
90933+ return "<null>";
90934+
90935+ if (!virt_addr_valid(ptr))
90936+ return NULL;
90937+
90938+ page = virt_to_head_page(ptr);
90939+ if (!PageSlab(page))
90940+ return NULL;
90941+
90942+ if (page->private) {
90943+ base = page;
90944+ if (base <= ptr && n <= page->private - (ptr - base))
90945+ return NULL;
90946+ return "<slob>";
90947+ }
90948+
90949+ /* some tricky double walking to find the chunk */
90950+ spin_lock_irqsave(&slob_lock, flags);
90951+ base = (void *)((unsigned long)ptr & PAGE_MASK);
90952+ free = page->freelist;
90953+
90954+ while (!slob_last(free) && (void *)free <= ptr) {
90955+ base = free + slob_units(free);
90956+ free = slob_next(free);
90957+ }
90958+
90959+ while (base < (void *)free) {
90960+ slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
90961+ int size = SLOB_UNIT * SLOB_UNITS(m + align);
90962+ int offset;
90963+
90964+ if (ptr < base + align)
90965+ break;
90966+
90967+ offset = ptr - base - align;
90968+ if (offset >= m) {
90969+ base += size;
90970+ continue;
90971+ }
90972+
90973+ if (n > m - offset)
90974+ break;
90975+
90976+ spin_unlock_irqrestore(&slob_lock, flags);
90977+ return NULL;
90978+ }
90979+
90980+ spin_unlock_irqrestore(&slob_lock, flags);
90981+ return "<slob>";
90982+}
90983+#endif
90984+
90985 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
90986 size_t ksize(const void *block)
90987 {
90988 struct page *sp;
90989 int align;
90990- unsigned int *m;
90991+ slob_t *m;
90992
90993 BUG_ON(!block);
90994 if (unlikely(block == ZERO_SIZE_PTR))
90995 return 0;
90996
90997 sp = virt_to_page(block);
90998- if (unlikely(!PageSlab(sp)))
90999- return PAGE_SIZE << compound_order(sp);
91000+ VM_BUG_ON(!PageSlab(sp));
91001+ if (sp->private)
91002+ return sp->private;
91003
91004 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
91005- m = (unsigned int *)(block - align);
91006- return SLOB_UNITS(*m) * SLOB_UNIT;
91007+ m = (slob_t *)(block - align);
91008+ return SLOB_UNITS(m[0].units) * SLOB_UNIT;
91009 }
91010 EXPORT_SYMBOL(ksize);
91011
91012@@ -536,23 +638,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
91013
91014 void *slob_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
91015 {
91016- void *b;
91017+ void *b = NULL;
91018
91019 flags &= gfp_allowed_mask;
91020
91021 lockdep_trace_alloc(flags);
91022
91023+#ifdef CONFIG_PAX_USERCOPY_SLABS
91024+ b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
91025+#else
91026 if (c->size < PAGE_SIZE) {
91027 b = slob_alloc(c->size, flags, c->align, node);
91028 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
91029 SLOB_UNITS(c->size) * SLOB_UNIT,
91030 flags, node);
91031 } else {
91032- b = slob_new_pages(flags, get_order(c->size), node);
91033+ struct page *sp;
91034+
91035+ sp = slob_new_pages(flags, get_order(c->size), node);
91036+ if (sp) {
91037+ b = page_address(sp);
91038+ sp->private = c->size;
91039+ }
91040 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
91041 PAGE_SIZE << get_order(c->size),
91042 flags, node);
91043 }
91044+#endif
91045
91046 if (b && c->ctor)
91047 c->ctor(b);
91048@@ -584,10 +696,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
91049
91050 static void __kmem_cache_free(void *b, int size)
91051 {
91052- if (size < PAGE_SIZE)
91053+ struct page *sp;
91054+
91055+ sp = virt_to_page(b);
91056+ BUG_ON(!PageSlab(sp));
91057+ if (!sp->private)
91058 slob_free(b, size);
91059 else
91060- slob_free_pages(b, get_order(size));
91061+ slob_free_pages(sp, get_order(size));
91062 }
91063
91064 static void kmem_rcu_free(struct rcu_head *head)
91065@@ -600,17 +716,31 @@ static void kmem_rcu_free(struct rcu_head *head)
91066
91067 void kmem_cache_free(struct kmem_cache *c, void *b)
91068 {
91069+ int size = c->size;
91070+
91071+#ifdef CONFIG_PAX_USERCOPY_SLABS
91072+ if (size + c->align < PAGE_SIZE) {
91073+ size += c->align;
91074+ b -= c->align;
91075+ }
91076+#endif
91077+
91078 kmemleak_free_recursive(b, c->flags);
91079 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
91080 struct slob_rcu *slob_rcu;
91081- slob_rcu = b + (c->size - sizeof(struct slob_rcu));
91082- slob_rcu->size = c->size;
91083+ slob_rcu = b + (size - sizeof(struct slob_rcu));
91084+ slob_rcu->size = size;
91085 call_rcu(&slob_rcu->head, kmem_rcu_free);
91086 } else {
91087- __kmem_cache_free(b, c->size);
91088+ __kmem_cache_free(b, size);
91089 }
91090
91091+#ifdef CONFIG_PAX_USERCOPY_SLABS
91092+ trace_kfree(_RET_IP_, b);
91093+#else
91094 trace_kmem_cache_free(_RET_IP_, b);
91095+#endif
91096+
91097 }
91098 EXPORT_SYMBOL(kmem_cache_free);
91099
91100diff --git a/mm/slub.c b/mm/slub.c
91101index c3eb3d3..022c9fa 100644
91102--- a/mm/slub.c
91103+++ b/mm/slub.c
91104@@ -207,7 +207,7 @@ struct track {
91105
91106 enum track_item { TRACK_ALLOC, TRACK_FREE };
91107
91108-#ifdef CONFIG_SYSFS
91109+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
91110 static int sysfs_slab_add(struct kmem_cache *);
91111 static int sysfs_slab_alias(struct kmem_cache *, const char *);
91112 static void sysfs_slab_remove(struct kmem_cache *);
91113@@ -530,7 +530,7 @@ static void print_track(const char *s, struct track *t)
91114 if (!t->addr)
91115 return;
91116
91117- printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
91118+ printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
91119 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
91120 #ifdef CONFIG_STACKTRACE
91121 {
91122@@ -2616,6 +2616,14 @@ static __always_inline void slab_free(struct kmem_cache *s,
91123
91124 slab_free_hook(s, x);
91125
91126+#ifdef CONFIG_PAX_MEMORY_SANITIZE
91127+ if (pax_sanitize_slab && !(s->flags & SLAB_NO_SANITIZE)) {
91128+ memset(x, PAX_MEMORY_SANITIZE_VALUE, s->object_size);
91129+ if (s->ctor)
91130+ s->ctor(x);
91131+ }
91132+#endif
91133+
91134 redo:
91135 /*
91136 * Determine the currently cpus per cpu slab.
91137@@ -2683,7 +2691,7 @@ static int slub_min_objects;
91138 * Merge control. If this is set then no merging of slab caches will occur.
91139 * (Could be removed. This was introduced to pacify the merge skeptics.)
91140 */
91141-static int slub_nomerge;
91142+static int slub_nomerge = 1;
91143
91144 /*
91145 * Calculate the order of allocation given an slab object size.
91146@@ -2960,6 +2968,9 @@ static int calculate_sizes(struct kmem_cache *s, int forced_order)
91147 s->inuse = size;
91148
91149 if (((flags & (SLAB_DESTROY_BY_RCU | SLAB_POISON)) ||
91150+#ifdef CONFIG_PAX_MEMORY_SANITIZE
91151+ (pax_sanitize_slab && !(flags & SLAB_NO_SANITIZE)) ||
91152+#endif
91153 s->ctor)) {
91154 /*
91155 * Relocate free pointer after the object if it is not
91156@@ -3305,6 +3316,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
91157 EXPORT_SYMBOL(__kmalloc_node);
91158 #endif
91159
91160+bool is_usercopy_object(const void *ptr)
91161+{
91162+ struct page *page;
91163+ struct kmem_cache *s;
91164+
91165+ if (ZERO_OR_NULL_PTR(ptr))
91166+ return false;
91167+
91168+ if (!slab_is_available())
91169+ return false;
91170+
91171+ if (!virt_addr_valid(ptr))
91172+ return false;
91173+
91174+ page = virt_to_head_page(ptr);
91175+
91176+ if (!PageSlab(page))
91177+ return false;
91178+
91179+ s = page->slab_cache;
91180+ return s->flags & SLAB_USERCOPY;
91181+}
91182+
91183+#ifdef CONFIG_PAX_USERCOPY
91184+const char *check_heap_object(const void *ptr, unsigned long n)
91185+{
91186+ struct page *page;
91187+ struct kmem_cache *s;
91188+ unsigned long offset;
91189+
91190+ if (ZERO_OR_NULL_PTR(ptr))
91191+ return "<null>";
91192+
91193+ if (!virt_addr_valid(ptr))
91194+ return NULL;
91195+
91196+ page = virt_to_head_page(ptr);
91197+
91198+ if (!PageSlab(page))
91199+ return NULL;
91200+
91201+ s = page->slab_cache;
91202+ if (!(s->flags & SLAB_USERCOPY))
91203+ return s->name;
91204+
91205+ offset = (ptr - page_address(page)) % s->size;
91206+ if (offset <= s->object_size && n <= s->object_size - offset)
91207+ return NULL;
91208+
91209+ return s->name;
91210+}
91211+#endif
91212+
91213 size_t ksize(const void *object)
91214 {
91215 struct page *page;
91216@@ -3333,6 +3397,7 @@ void kfree(const void *x)
91217 if (unlikely(ZERO_OR_NULL_PTR(x)))
91218 return;
91219
91220+ VM_BUG_ON(!virt_addr_valid(x));
91221 page = virt_to_head_page(x);
91222 if (unlikely(!PageSlab(page))) {
91223 BUG_ON(!PageCompound(page));
91224@@ -3638,7 +3703,7 @@ static int slab_unmergeable(struct kmem_cache *s)
91225 /*
91226 * We may have set a slab to be unmergeable during bootstrap.
91227 */
91228- if (s->refcount < 0)
91229+ if (atomic_read(&s->refcount) < 0)
91230 return 1;
91231
91232 return 0;
91233@@ -3696,7 +3761,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
91234
91235 s = find_mergeable(memcg, size, align, flags, name, ctor);
91236 if (s) {
91237- s->refcount++;
91238+ atomic_inc(&s->refcount);
91239 /*
91240 * Adjust the object sizes so that we clear
91241 * the complete object on kzalloc.
91242@@ -3705,7 +3770,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
91243 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
91244
91245 if (sysfs_slab_alias(s, name)) {
91246- s->refcount--;
91247+ atomic_dec(&s->refcount);
91248 s = NULL;
91249 }
91250 }
91251@@ -3825,7 +3890,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
91252 }
91253 #endif
91254
91255-#ifdef CONFIG_SYSFS
91256+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
91257 static int count_inuse(struct page *page)
91258 {
91259 return page->inuse;
91260@@ -4214,12 +4279,12 @@ static void resiliency_test(void)
91261 validate_slab_cache(kmalloc_caches[9]);
91262 }
91263 #else
91264-#ifdef CONFIG_SYSFS
91265+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
91266 static void resiliency_test(void) {};
91267 #endif
91268 #endif
91269
91270-#ifdef CONFIG_SYSFS
91271+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
91272 enum slab_stat_type {
91273 SL_ALL, /* All slabs */
91274 SL_PARTIAL, /* Only partially allocated slabs */
91275@@ -4459,7 +4524,7 @@ SLAB_ATTR_RO(ctor);
91276
91277 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
91278 {
91279- return sprintf(buf, "%d\n", s->refcount - 1);
91280+ return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
91281 }
91282 SLAB_ATTR_RO(aliases);
91283
91284@@ -4547,6 +4612,14 @@ static ssize_t cache_dma_show(struct kmem_cache *s, char *buf)
91285 SLAB_ATTR_RO(cache_dma);
91286 #endif
91287
91288+#ifdef CONFIG_PAX_USERCOPY_SLABS
91289+static ssize_t usercopy_show(struct kmem_cache *s, char *buf)
91290+{
91291+ return sprintf(buf, "%d\n", !!(s->flags & SLAB_USERCOPY));
91292+}
91293+SLAB_ATTR_RO(usercopy);
91294+#endif
91295+
91296 static ssize_t destroy_by_rcu_show(struct kmem_cache *s, char *buf)
91297 {
91298 return sprintf(buf, "%d\n", !!(s->flags & SLAB_DESTROY_BY_RCU));
91299@@ -4881,6 +4954,9 @@ static struct attribute *slab_attrs[] = {
91300 #ifdef CONFIG_ZONE_DMA
91301 &cache_dma_attr.attr,
91302 #endif
91303+#ifdef CONFIG_PAX_USERCOPY_SLABS
91304+ &usercopy_attr.attr,
91305+#endif
91306 #ifdef CONFIG_NUMA
91307 &remote_node_defrag_ratio_attr.attr,
91308 #endif
91309@@ -5113,6 +5189,7 @@ static char *create_unique_id(struct kmem_cache *s)
91310 return name;
91311 }
91312
91313+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
91314 static int sysfs_slab_add(struct kmem_cache *s)
91315 {
91316 int err;
91317@@ -5136,7 +5213,7 @@ static int sysfs_slab_add(struct kmem_cache *s)
91318 }
91319
91320 s->kobj.kset = slab_kset;
91321- err = kobject_init_and_add(&s->kobj, &slab_ktype, NULL, name);
91322+ err = kobject_init_and_add(&s->kobj, &slab_ktype, NULL, "%s", name);
91323 if (err) {
91324 kobject_put(&s->kobj);
91325 return err;
91326@@ -5170,6 +5247,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
91327 kobject_del(&s->kobj);
91328 kobject_put(&s->kobj);
91329 }
91330+#endif
91331
91332 /*
91333 * Need to buffer aliases during bootup until sysfs becomes
91334@@ -5183,6 +5261,7 @@ struct saved_alias {
91335
91336 static struct saved_alias *alias_list;
91337
91338+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
91339 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
91340 {
91341 struct saved_alias *al;
91342@@ -5205,6 +5284,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
91343 alias_list = al;
91344 return 0;
91345 }
91346+#endif
91347
91348 static int __init slab_sysfs_init(void)
91349 {
91350diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
91351index 27eeab3..7c3f7f2 100644
91352--- a/mm/sparse-vmemmap.c
91353+++ b/mm/sparse-vmemmap.c
91354@@ -130,7 +130,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
91355 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
91356 if (!p)
91357 return NULL;
91358- pud_populate(&init_mm, pud, p);
91359+ pud_populate_kernel(&init_mm, pud, p);
91360 }
91361 return pud;
91362 }
91363@@ -142,7 +142,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
91364 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
91365 if (!p)
91366 return NULL;
91367- pgd_populate(&init_mm, pgd, p);
91368+ pgd_populate_kernel(&init_mm, pgd, p);
91369 }
91370 return pgd;
91371 }
91372diff --git a/mm/sparse.c b/mm/sparse.c
91373index 4ac1d7e..bbfcb1f 100644
91374--- a/mm/sparse.c
91375+++ b/mm/sparse.c
91376@@ -745,7 +745,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
91377
91378 for (i = 0; i < PAGES_PER_SECTION; i++) {
91379 if (PageHWPoison(&memmap[i])) {
91380- atomic_long_sub(1, &num_poisoned_pages);
91381+ atomic_long_sub_unchecked(1, &num_poisoned_pages);
91382 ClearPageHWPoison(&memmap[i]);
91383 }
91384 }
91385diff --git a/mm/swap.c b/mm/swap.c
91386index 759c3ca..7c1a5b4 100644
91387--- a/mm/swap.c
91388+++ b/mm/swap.c
91389@@ -77,6 +77,8 @@ static void __put_compound_page(struct page *page)
91390
91391 __page_cache_release(page);
91392 dtor = get_compound_page_dtor(page);
91393+ if (!PageHuge(page))
91394+ BUG_ON(dtor != free_compound_page);
91395 (*dtor)(page);
91396 }
91397
91398diff --git a/mm/swapfile.c b/mm/swapfile.c
91399index de7c904..c84bf11 100644
91400--- a/mm/swapfile.c
91401+++ b/mm/swapfile.c
91402@@ -66,7 +66,7 @@ static DEFINE_MUTEX(swapon_mutex);
91403
91404 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
91405 /* Activity counter to indicate that a swapon or swapoff has occurred */
91406-static atomic_t proc_poll_event = ATOMIC_INIT(0);
91407+static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
91408
91409 static inline unsigned char swap_count(unsigned char ent)
91410 {
91411@@ -1949,7 +1949,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
91412 }
91413 filp_close(swap_file, NULL);
91414 err = 0;
91415- atomic_inc(&proc_poll_event);
91416+ atomic_inc_unchecked(&proc_poll_event);
91417 wake_up_interruptible(&proc_poll_wait);
91418
91419 out_dput:
91420@@ -1966,8 +1966,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
91421
91422 poll_wait(file, &proc_poll_wait, wait);
91423
91424- if (seq->poll_event != atomic_read(&proc_poll_event)) {
91425- seq->poll_event = atomic_read(&proc_poll_event);
91426+ if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
91427+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
91428 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
91429 }
91430
91431@@ -2065,7 +2065,7 @@ static int swaps_open(struct inode *inode, struct file *file)
91432 return ret;
91433
91434 seq = file->private_data;
91435- seq->poll_event = atomic_read(&proc_poll_event);
91436+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
91437 return 0;
91438 }
91439
91440@@ -2524,7 +2524,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
91441 (frontswap_map) ? "FS" : "");
91442
91443 mutex_unlock(&swapon_mutex);
91444- atomic_inc(&proc_poll_event);
91445+ atomic_inc_unchecked(&proc_poll_event);
91446 wake_up_interruptible(&proc_poll_wait);
91447
91448 if (S_ISREG(inode->i_mode))
91449diff --git a/mm/util.c b/mm/util.c
91450index eaf63fc2..32b2629 100644
91451--- a/mm/util.c
91452+++ b/mm/util.c
91453@@ -294,6 +294,12 @@ done:
91454 void arch_pick_mmap_layout(struct mm_struct *mm)
91455 {
91456 mm->mmap_base = TASK_UNMAPPED_BASE;
91457+
91458+#ifdef CONFIG_PAX_RANDMMAP
91459+ if (mm->pax_flags & MF_PAX_RANDMMAP)
91460+ mm->mmap_base += mm->delta_mmap;
91461+#endif
91462+
91463 mm->get_unmapped_area = arch_get_unmapped_area;
91464 }
91465 #endif
91466diff --git a/mm/vmalloc.c b/mm/vmalloc.c
91467index 1074543..136dbe0 100644
91468--- a/mm/vmalloc.c
91469+++ b/mm/vmalloc.c
91470@@ -59,8 +59,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
91471
91472 pte = pte_offset_kernel(pmd, addr);
91473 do {
91474- pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
91475- WARN_ON(!pte_none(ptent) && !pte_present(ptent));
91476+
91477+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
91478+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
91479+ BUG_ON(!pte_exec(*pte));
91480+ set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
91481+ continue;
91482+ }
91483+#endif
91484+
91485+ {
91486+ pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
91487+ WARN_ON(!pte_none(ptent) && !pte_present(ptent));
91488+ }
91489 } while (pte++, addr += PAGE_SIZE, addr != end);
91490 }
91491
91492@@ -120,16 +131,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
91493 pte = pte_alloc_kernel(pmd, addr);
91494 if (!pte)
91495 return -ENOMEM;
91496+
91497+ pax_open_kernel();
91498 do {
91499 struct page *page = pages[*nr];
91500
91501- if (WARN_ON(!pte_none(*pte)))
91502+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
91503+ if (pgprot_val(prot) & _PAGE_NX)
91504+#endif
91505+
91506+ if (!pte_none(*pte)) {
91507+ pax_close_kernel();
91508+ WARN_ON(1);
91509 return -EBUSY;
91510- if (WARN_ON(!page))
91511+ }
91512+ if (!page) {
91513+ pax_close_kernel();
91514+ WARN_ON(1);
91515 return -ENOMEM;
91516+ }
91517 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
91518 (*nr)++;
91519 } while (pte++, addr += PAGE_SIZE, addr != end);
91520+ pax_close_kernel();
91521 return 0;
91522 }
91523
91524@@ -139,7 +163,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
91525 pmd_t *pmd;
91526 unsigned long next;
91527
91528- pmd = pmd_alloc(&init_mm, pud, addr);
91529+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
91530 if (!pmd)
91531 return -ENOMEM;
91532 do {
91533@@ -156,7 +180,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
91534 pud_t *pud;
91535 unsigned long next;
91536
91537- pud = pud_alloc(&init_mm, pgd, addr);
91538+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
91539 if (!pud)
91540 return -ENOMEM;
91541 do {
91542@@ -216,6 +240,12 @@ int is_vmalloc_or_module_addr(const void *x)
91543 if (addr >= MODULES_VADDR && addr < MODULES_END)
91544 return 1;
91545 #endif
91546+
91547+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
91548+ if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
91549+ return 1;
91550+#endif
91551+
91552 return is_vmalloc_addr(x);
91553 }
91554
91555@@ -236,8 +266,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
91556
91557 if (!pgd_none(*pgd)) {
91558 pud_t *pud = pud_offset(pgd, addr);
91559+#ifdef CONFIG_X86
91560+ if (!pud_large(*pud))
91561+#endif
91562 if (!pud_none(*pud)) {
91563 pmd_t *pmd = pmd_offset(pud, addr);
91564+#ifdef CONFIG_X86
91565+ if (!pmd_large(*pmd))
91566+#endif
91567 if (!pmd_none(*pmd)) {
91568 pte_t *ptep, pte;
91569
91570@@ -1303,6 +1339,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
91571 struct vm_struct *area;
91572
91573 BUG_ON(in_interrupt());
91574+
91575+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
91576+ if (flags & VM_KERNEXEC) {
91577+ if (start != VMALLOC_START || end != VMALLOC_END)
91578+ return NULL;
91579+ start = (unsigned long)MODULES_EXEC_VADDR;
91580+ end = (unsigned long)MODULES_EXEC_END;
91581+ }
91582+#endif
91583+
91584 if (flags & VM_IOREMAP)
91585 align = 1ul << clamp(fls(size), PAGE_SHIFT, IOREMAP_MAX_ORDER);
91586
91587@@ -1528,6 +1574,11 @@ void *vmap(struct page **pages, unsigned int count,
91588 if (count > totalram_pages)
91589 return NULL;
91590
91591+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
91592+ if (!(pgprot_val(prot) & _PAGE_NX))
91593+ flags |= VM_KERNEXEC;
91594+#endif
91595+
91596 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
91597 __builtin_return_address(0));
91598 if (!area)
91599@@ -1629,6 +1680,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
91600 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
91601 goto fail;
91602
91603+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
91604+ if (!(pgprot_val(prot) & _PAGE_NX))
91605+ area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED | VM_KERNEXEC,
91606+ VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
91607+ else
91608+#endif
91609+
91610 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED,
91611 start, end, node, gfp_mask, caller);
91612 if (!area)
91613@@ -1805,10 +1863,9 @@ EXPORT_SYMBOL(vzalloc_node);
91614 * For tight control over page level allocator and protection flags
91615 * use __vmalloc() instead.
91616 */
91617-
91618 void *vmalloc_exec(unsigned long size)
91619 {
91620- return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
91621+ return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
91622 NUMA_NO_NODE, __builtin_return_address(0));
91623 }
91624
91625@@ -2115,6 +2172,8 @@ int remap_vmalloc_range_partial(struct vm_area_struct *vma, unsigned long uaddr,
91626 {
91627 struct vm_struct *area;
91628
91629+ BUG_ON(vma->vm_mirror);
91630+
91631 size = PAGE_ALIGN(size);
91632
91633 if (!PAGE_ALIGNED(uaddr) || !PAGE_ALIGNED(kaddr))
91634@@ -2600,7 +2659,11 @@ static int s_show(struct seq_file *m, void *p)
91635 v->addr, v->addr + v->size, v->size);
91636
91637 if (v->caller)
91638+#ifdef CONFIG_GRKERNSEC_HIDESYM
91639+ seq_printf(m, " %pK", v->caller);
91640+#else
91641 seq_printf(m, " %pS", v->caller);
91642+#endif
91643
91644 if (v->nr_pages)
91645 seq_printf(m, " pages=%d", v->nr_pages);
91646diff --git a/mm/vmstat.c b/mm/vmstat.c
91647index 9bb3145..98e5f68 100644
91648--- a/mm/vmstat.c
91649+++ b/mm/vmstat.c
91650@@ -79,7 +79,7 @@ void vm_events_fold_cpu(int cpu)
91651 *
91652 * vm_stat contains the global counters
91653 */
91654-atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
91655+atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
91656 EXPORT_SYMBOL(vm_stat);
91657
91658 #ifdef CONFIG_SMP
91659@@ -423,7 +423,7 @@ static inline void fold_diff(int *diff)
91660
91661 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
91662 if (diff[i])
91663- atomic_long_add(diff[i], &vm_stat[i]);
91664+ atomic_long_add_unchecked(diff[i], &vm_stat[i]);
91665 }
91666
91667 /*
91668@@ -455,7 +455,7 @@ static void refresh_cpu_vm_stats(void)
91669 v = this_cpu_xchg(p->vm_stat_diff[i], 0);
91670 if (v) {
91671
91672- atomic_long_add(v, &zone->vm_stat[i]);
91673+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
91674 global_diff[i] += v;
91675 #ifdef CONFIG_NUMA
91676 /* 3 seconds idle till flush */
91677@@ -517,7 +517,7 @@ void cpu_vm_stats_fold(int cpu)
91678
91679 v = p->vm_stat_diff[i];
91680 p->vm_stat_diff[i] = 0;
91681- atomic_long_add(v, &zone->vm_stat[i]);
91682+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
91683 global_diff[i] += v;
91684 }
91685 }
91686@@ -537,8 +537,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
91687 if (pset->vm_stat_diff[i]) {
91688 int v = pset->vm_stat_diff[i];
91689 pset->vm_stat_diff[i] = 0;
91690- atomic_long_add(v, &zone->vm_stat[i]);
91691- atomic_long_add(v, &vm_stat[i]);
91692+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
91693+ atomic_long_add_unchecked(v, &vm_stat[i]);
91694 }
91695 }
91696 #endif
91697@@ -1280,10 +1280,20 @@ static int __init setup_vmstat(void)
91698 start_cpu_timer(cpu);
91699 #endif
91700 #ifdef CONFIG_PROC_FS
91701- proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
91702- proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
91703- proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
91704- proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
91705+ {
91706+ mode_t gr_mode = S_IRUGO;
91707+#ifdef CONFIG_GRKERNSEC_PROC_ADD
91708+ gr_mode = S_IRUSR;
91709+#endif
91710+ proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
91711+ proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
91712+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
91713+ proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
91714+#else
91715+ proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
91716+#endif
91717+ proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
91718+ }
91719 #endif
91720 return 0;
91721 }
91722diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
91723index 61fc573..b5e47d0 100644
91724--- a/net/8021q/vlan.c
91725+++ b/net/8021q/vlan.c
91726@@ -472,7 +472,7 @@ out:
91727 return NOTIFY_DONE;
91728 }
91729
91730-static struct notifier_block vlan_notifier_block __read_mostly = {
91731+static struct notifier_block vlan_notifier_block = {
91732 .notifier_call = vlan_device_event,
91733 };
91734
91735@@ -547,8 +547,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
91736 err = -EPERM;
91737 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
91738 break;
91739- if ((args.u.name_type >= 0) &&
91740- (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
91741+ if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
91742 struct vlan_net *vn;
91743
91744 vn = net_generic(net, vlan_net_id);
91745diff --git a/net/9p/mod.c b/net/9p/mod.c
91746index 6ab36ae..6f1841b 100644
91747--- a/net/9p/mod.c
91748+++ b/net/9p/mod.c
91749@@ -84,7 +84,7 @@ static LIST_HEAD(v9fs_trans_list);
91750 void v9fs_register_trans(struct p9_trans_module *m)
91751 {
91752 spin_lock(&v9fs_trans_lock);
91753- list_add_tail(&m->list, &v9fs_trans_list);
91754+ pax_list_add_tail((struct list_head *)&m->list, &v9fs_trans_list);
91755 spin_unlock(&v9fs_trans_lock);
91756 }
91757 EXPORT_SYMBOL(v9fs_register_trans);
91758@@ -97,7 +97,7 @@ EXPORT_SYMBOL(v9fs_register_trans);
91759 void v9fs_unregister_trans(struct p9_trans_module *m)
91760 {
91761 spin_lock(&v9fs_trans_lock);
91762- list_del_init(&m->list);
91763+ pax_list_del_init((struct list_head *)&m->list);
91764 spin_unlock(&v9fs_trans_lock);
91765 }
91766 EXPORT_SYMBOL(v9fs_unregister_trans);
91767diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
91768index 3ffda1b..fceac96 100644
91769--- a/net/9p/trans_fd.c
91770+++ b/net/9p/trans_fd.c
91771@@ -432,7 +432,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
91772 oldfs = get_fs();
91773 set_fs(get_ds());
91774 /* The cast to a user pointer is valid due to the set_fs() */
91775- ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
91776+ ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
91777 set_fs(oldfs);
91778
91779 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
91780diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
91781index 876fbe8..8bbea9f 100644
91782--- a/net/atm/atm_misc.c
91783+++ b/net/atm/atm_misc.c
91784@@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
91785 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
91786 return 1;
91787 atm_return(vcc, truesize);
91788- atomic_inc(&vcc->stats->rx_drop);
91789+ atomic_inc_unchecked(&vcc->stats->rx_drop);
91790 return 0;
91791 }
91792 EXPORT_SYMBOL(atm_charge);
91793@@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
91794 }
91795 }
91796 atm_return(vcc, guess);
91797- atomic_inc(&vcc->stats->rx_drop);
91798+ atomic_inc_unchecked(&vcc->stats->rx_drop);
91799 return NULL;
91800 }
91801 EXPORT_SYMBOL(atm_alloc_charge);
91802@@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
91803
91804 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
91805 {
91806-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
91807+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
91808 __SONET_ITEMS
91809 #undef __HANDLE_ITEM
91810 }
91811@@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
91812
91813 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
91814 {
91815-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
91816+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
91817 __SONET_ITEMS
91818 #undef __HANDLE_ITEM
91819 }
91820diff --git a/net/atm/lec.h b/net/atm/lec.h
91821index 4149db1..f2ab682 100644
91822--- a/net/atm/lec.h
91823+++ b/net/atm/lec.h
91824@@ -48,7 +48,7 @@ struct lane2_ops {
91825 const u8 *tlvs, u32 sizeoftlvs);
91826 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
91827 const u8 *tlvs, u32 sizeoftlvs);
91828-};
91829+} __no_const;
91830
91831 /*
91832 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
91833diff --git a/net/atm/proc.c b/net/atm/proc.c
91834index bbb6461..cf04016 100644
91835--- a/net/atm/proc.c
91836+++ b/net/atm/proc.c
91837@@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
91838 const struct k_atm_aal_stats *stats)
91839 {
91840 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
91841- atomic_read(&stats->tx), atomic_read(&stats->tx_err),
91842- atomic_read(&stats->rx), atomic_read(&stats->rx_err),
91843- atomic_read(&stats->rx_drop));
91844+ atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
91845+ atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
91846+ atomic_read_unchecked(&stats->rx_drop));
91847 }
91848
91849 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
91850diff --git a/net/atm/resources.c b/net/atm/resources.c
91851index 0447d5d..3cf4728 100644
91852--- a/net/atm/resources.c
91853+++ b/net/atm/resources.c
91854@@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
91855 static void copy_aal_stats(struct k_atm_aal_stats *from,
91856 struct atm_aal_stats *to)
91857 {
91858-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
91859+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
91860 __AAL_STAT_ITEMS
91861 #undef __HANDLE_ITEM
91862 }
91863@@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
91864 static void subtract_aal_stats(struct k_atm_aal_stats *from,
91865 struct atm_aal_stats *to)
91866 {
91867-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
91868+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
91869 __AAL_STAT_ITEMS
91870 #undef __HANDLE_ITEM
91871 }
91872diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c
91873index 919a5ce..cc6b444 100644
91874--- a/net/ax25/sysctl_net_ax25.c
91875+++ b/net/ax25/sysctl_net_ax25.c
91876@@ -152,7 +152,7 @@ int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
91877 {
91878 char path[sizeof("net/ax25/") + IFNAMSIZ];
91879 int k;
91880- struct ctl_table *table;
91881+ ctl_table_no_const *table;
91882
91883 table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
91884 if (!table)
91885diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
91886index 0a8a80c..f7e89aa 100644
91887--- a/net/batman-adv/bat_iv_ogm.c
91888+++ b/net/batman-adv/bat_iv_ogm.c
91889@@ -121,7 +121,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
91890
91891 /* randomize initial seqno to avoid collision */
91892 get_random_bytes(&random_seqno, sizeof(random_seqno));
91893- atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
91894+ atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
91895
91896 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
91897 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
91898@@ -703,9 +703,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
91899 batadv_ogm_packet = (struct batadv_ogm_packet *)(*ogm_buff);
91900
91901 /* change sequence number to network order */
91902- seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
91903+ seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
91904 batadv_ogm_packet->seqno = htonl(seqno);
91905- atomic_inc(&hard_iface->bat_iv.ogm_seqno);
91906+ atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
91907
91908 batadv_ogm_packet->ttvn = atomic_read(&bat_priv->tt.vn);
91909 batadv_ogm_packet->tt_crc = htons(bat_priv->tt.local_crc);
91910@@ -1111,7 +1111,7 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
91911 return;
91912
91913 /* could be changed by schedule_own_packet() */
91914- if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
91915+ if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
91916
91917 if (batadv_ogm_packet->flags & BATADV_DIRECTLINK)
91918 has_directlink_flag = 1;
91919diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
91920index c478e6b..469fd2f 100644
91921--- a/net/batman-adv/hard-interface.c
91922+++ b/net/batman-adv/hard-interface.c
91923@@ -453,7 +453,7 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
91924 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
91925 dev_add_pack(&hard_iface->batman_adv_ptype);
91926
91927- atomic_set(&hard_iface->frag_seqno, 1);
91928+ atomic_set_unchecked(&hard_iface->frag_seqno, 1);
91929 batadv_info(hard_iface->soft_iface, "Adding interface: %s\n",
91930 hard_iface->net_dev->name);
91931
91932diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
91933index 813db4e..847edac 100644
91934--- a/net/batman-adv/soft-interface.c
91935+++ b/net/batman-adv/soft-interface.c
91936@@ -263,7 +263,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
91937 primary_if->net_dev->dev_addr, ETH_ALEN);
91938
91939 /* set broadcast sequence number */
91940- seqno = atomic_inc_return(&bat_priv->bcast_seqno);
91941+ seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
91942 bcast_packet->seqno = htonl(seqno);
91943
91944 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
91945@@ -483,7 +483,7 @@ static int batadv_softif_init_late(struct net_device *dev)
91946 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
91947
91948 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
91949- atomic_set(&bat_priv->bcast_seqno, 1);
91950+ atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
91951 atomic_set(&bat_priv->tt.vn, 0);
91952 atomic_set(&bat_priv->tt.local_changes, 0);
91953 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
91954diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
91955index b2c94e1..3d47e07 100644
91956--- a/net/batman-adv/types.h
91957+++ b/net/batman-adv/types.h
91958@@ -51,7 +51,7 @@
91959 struct batadv_hard_iface_bat_iv {
91960 unsigned char *ogm_buff;
91961 int ogm_buff_len;
91962- atomic_t ogm_seqno;
91963+ atomic_unchecked_t ogm_seqno;
91964 };
91965
91966 /**
91967@@ -76,7 +76,7 @@ struct batadv_hard_iface {
91968 int16_t if_num;
91969 char if_status;
91970 struct net_device *net_dev;
91971- atomic_t frag_seqno;
91972+ atomic_unchecked_t frag_seqno;
91973 uint8_t num_bcasts;
91974 struct kobject *hardif_obj;
91975 atomic_t refcount;
91976@@ -560,7 +560,7 @@ struct batadv_priv {
91977 #ifdef CONFIG_BATMAN_ADV_DEBUG
91978 atomic_t log_level;
91979 #endif
91980- atomic_t bcast_seqno;
91981+ atomic_unchecked_t bcast_seqno;
91982 atomic_t bcast_queue_left;
91983 atomic_t batman_queue_left;
91984 char num_ifaces;
91985diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
91986index 48b31d3..62a0bcb 100644
91987--- a/net/batman-adv/unicast.c
91988+++ b/net/batman-adv/unicast.c
91989@@ -272,7 +272,7 @@ int batadv_frag_send_skb(struct sk_buff *skb, struct batadv_priv *bat_priv,
91990 frag1->flags = BATADV_UNI_FRAG_HEAD | large_tail;
91991 frag2->flags = large_tail;
91992
91993- seqno = atomic_add_return(2, &hard_iface->frag_seqno);
91994+ seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
91995 frag1->seqno = htons(seqno - 1);
91996 frag2->seqno = htons(seqno);
91997
91998diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
91999index 9bd7d95..6c4884f 100644
92000--- a/net/bluetooth/hci_sock.c
92001+++ b/net/bluetooth/hci_sock.c
92002@@ -934,7 +934,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
92003 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
92004 }
92005
92006- len = min_t(unsigned int, len, sizeof(uf));
92007+ len = min((size_t)len, sizeof(uf));
92008 if (copy_from_user(&uf, optval, len)) {
92009 err = -EFAULT;
92010 break;
92011diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
92012index 63fa111..b166ec6 100644
92013--- a/net/bluetooth/l2cap_core.c
92014+++ b/net/bluetooth/l2cap_core.c
92015@@ -3511,8 +3511,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
92016 break;
92017
92018 case L2CAP_CONF_RFC:
92019- if (olen == sizeof(rfc))
92020- memcpy(&rfc, (void *)val, olen);
92021+ if (olen != sizeof(rfc))
92022+ break;
92023+
92024+ memcpy(&rfc, (void *)val, olen);
92025
92026 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
92027 rfc.mode != chan->mode)
92028diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
92029index 0098af8..fb5a31f 100644
92030--- a/net/bluetooth/l2cap_sock.c
92031+++ b/net/bluetooth/l2cap_sock.c
92032@@ -485,7 +485,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
92033 struct sock *sk = sock->sk;
92034 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
92035 struct l2cap_options opts;
92036- int len, err = 0;
92037+ int err = 0;
92038+ size_t len = optlen;
92039 u32 opt;
92040
92041 BT_DBG("sk %p", sk);
92042@@ -507,7 +508,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
92043 opts.max_tx = chan->max_tx;
92044 opts.txwin_size = chan->tx_win;
92045
92046- len = min_t(unsigned int, sizeof(opts), optlen);
92047+ len = min(sizeof(opts), len);
92048 if (copy_from_user((char *) &opts, optval, len)) {
92049 err = -EFAULT;
92050 break;
92051@@ -587,7 +588,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
92052 struct bt_security sec;
92053 struct bt_power pwr;
92054 struct l2cap_conn *conn;
92055- int len, err = 0;
92056+ int err = 0;
92057+ size_t len = optlen;
92058 u32 opt;
92059
92060 BT_DBG("sk %p", sk);
92061@@ -610,7 +612,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
92062
92063 sec.level = BT_SECURITY_LOW;
92064
92065- len = min_t(unsigned int, sizeof(sec), optlen);
92066+ len = min(sizeof(sec), len);
92067 if (copy_from_user((char *) &sec, optval, len)) {
92068 err = -EFAULT;
92069 break;
92070@@ -707,7 +709,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
92071
92072 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
92073
92074- len = min_t(unsigned int, sizeof(pwr), optlen);
92075+ len = min(sizeof(pwr), len);
92076 if (copy_from_user((char *) &pwr, optval, len)) {
92077 err = -EFAULT;
92078 break;
92079diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
92080index 30b3721..c1bd0a0 100644
92081--- a/net/bluetooth/rfcomm/sock.c
92082+++ b/net/bluetooth/rfcomm/sock.c
92083@@ -666,7 +666,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
92084 struct sock *sk = sock->sk;
92085 struct bt_security sec;
92086 int err = 0;
92087- size_t len;
92088+ size_t len = optlen;
92089 u32 opt;
92090
92091 BT_DBG("sk %p", sk);
92092@@ -688,7 +688,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
92093
92094 sec.level = BT_SECURITY_LOW;
92095
92096- len = min_t(unsigned int, sizeof(sec), optlen);
92097+ len = min(sizeof(sec), len);
92098 if (copy_from_user((char *) &sec, optval, len)) {
92099 err = -EFAULT;
92100 break;
92101diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
92102index 84fcf9f..e389b27 100644
92103--- a/net/bluetooth/rfcomm/tty.c
92104+++ b/net/bluetooth/rfcomm/tty.c
92105@@ -684,7 +684,7 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
92106 BT_DBG("tty %p id %d", tty, tty->index);
92107
92108 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
92109- dev->channel, dev->port.count);
92110+ dev->channel, atomic_read(&dev->port.count));
92111
92112 err = tty_port_open(&dev->port, tty, filp);
92113 if (err)
92114@@ -707,7 +707,7 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
92115 struct rfcomm_dev *dev = (struct rfcomm_dev *) tty->driver_data;
92116
92117 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
92118- dev->port.count);
92119+ atomic_read(&dev->port.count));
92120
92121 tty_port_close(&dev->port, tty, filp);
92122 }
92123diff --git a/net/bridge/netfilter/ebt_ulog.c b/net/bridge/netfilter/ebt_ulog.c
92124index 5180938..7c470c3 100644
92125--- a/net/bridge/netfilter/ebt_ulog.c
92126+++ b/net/bridge/netfilter/ebt_ulog.c
92127@@ -181,6 +181,7 @@ static void ebt_ulog_packet(struct net *net, unsigned int hooknr,
92128 ub->qlen++;
92129
92130 pm = nlmsg_data(nlh);
92131+ memset(pm, 0, sizeof(*pm));
92132
92133 /* Fill in the ulog data */
92134 pm->version = EBT_ULOG_VERSION;
92135@@ -193,8 +194,6 @@ static void ebt_ulog_packet(struct net *net, unsigned int hooknr,
92136 pm->hook = hooknr;
92137 if (uloginfo->prefix != NULL)
92138 strcpy(pm->prefix, uloginfo->prefix);
92139- else
92140- *(pm->prefix) = '\0';
92141
92142 if (in) {
92143 strcpy(pm->physindev, in->name);
92144@@ -204,16 +203,14 @@ static void ebt_ulog_packet(struct net *net, unsigned int hooknr,
92145 strcpy(pm->indev, br_port_get_rcu(in)->br->dev->name);
92146 else
92147 strcpy(pm->indev, in->name);
92148- } else
92149- pm->indev[0] = pm->physindev[0] = '\0';
92150+ }
92151
92152 if (out) {
92153 /* If out exists, then out is a bridge port */
92154 strcpy(pm->physoutdev, out->name);
92155 /* rcu_read_lock()ed by nf_hook_slow */
92156 strcpy(pm->outdev, br_port_get_rcu(out)->br->dev->name);
92157- } else
92158- pm->outdev[0] = pm->physoutdev[0] = '\0';
92159+ }
92160
92161 if (skb_copy_bits(skb, -ETH_HLEN, pm->data, copy_len) < 0)
92162 BUG();
92163diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
92164index ac78024..161a80c 100644
92165--- a/net/bridge/netfilter/ebtables.c
92166+++ b/net/bridge/netfilter/ebtables.c
92167@@ -1525,7 +1525,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
92168 tmp.valid_hooks = t->table->valid_hooks;
92169 }
92170 mutex_unlock(&ebt_mutex);
92171- if (copy_to_user(user, &tmp, *len) != 0){
92172+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
92173 BUGPRINT("c2u Didn't work\n");
92174 ret = -EFAULT;
92175 break;
92176@@ -2331,7 +2331,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
92177 goto out;
92178 tmp.valid_hooks = t->valid_hooks;
92179
92180- if (copy_to_user(user, &tmp, *len) != 0) {
92181+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
92182 ret = -EFAULT;
92183 break;
92184 }
92185@@ -2342,7 +2342,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
92186 tmp.entries_size = t->table->entries_size;
92187 tmp.valid_hooks = t->table->valid_hooks;
92188
92189- if (copy_to_user(user, &tmp, *len) != 0) {
92190+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
92191 ret = -EFAULT;
92192 break;
92193 }
92194diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
92195index 0f45522..dab651f 100644
92196--- a/net/caif/cfctrl.c
92197+++ b/net/caif/cfctrl.c
92198@@ -10,6 +10,7 @@
92199 #include <linux/spinlock.h>
92200 #include <linux/slab.h>
92201 #include <linux/pkt_sched.h>
92202+#include <linux/sched.h>
92203 #include <net/caif/caif_layer.h>
92204 #include <net/caif/cfpkt.h>
92205 #include <net/caif/cfctrl.h>
92206@@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
92207 memset(&dev_info, 0, sizeof(dev_info));
92208 dev_info.id = 0xff;
92209 cfsrvl_init(&this->serv, 0, &dev_info, false);
92210- atomic_set(&this->req_seq_no, 1);
92211- atomic_set(&this->rsp_seq_no, 1);
92212+ atomic_set_unchecked(&this->req_seq_no, 1);
92213+ atomic_set_unchecked(&this->rsp_seq_no, 1);
92214 this->serv.layer.receive = cfctrl_recv;
92215 sprintf(this->serv.layer.name, "ctrl");
92216 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
92217@@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
92218 struct cfctrl_request_info *req)
92219 {
92220 spin_lock_bh(&ctrl->info_list_lock);
92221- atomic_inc(&ctrl->req_seq_no);
92222- req->sequence_no = atomic_read(&ctrl->req_seq_no);
92223+ atomic_inc_unchecked(&ctrl->req_seq_no);
92224+ req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
92225 list_add_tail(&req->list, &ctrl->list);
92226 spin_unlock_bh(&ctrl->info_list_lock);
92227 }
92228@@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
92229 if (p != first)
92230 pr_warn("Requests are not received in order\n");
92231
92232- atomic_set(&ctrl->rsp_seq_no,
92233+ atomic_set_unchecked(&ctrl->rsp_seq_no,
92234 p->sequence_no);
92235 list_del(&p->list);
92236 goto out;
92237diff --git a/net/can/af_can.c b/net/can/af_can.c
92238index 3ab8dd2..b9aef13 100644
92239--- a/net/can/af_can.c
92240+++ b/net/can/af_can.c
92241@@ -862,7 +862,7 @@ static const struct net_proto_family can_family_ops = {
92242 };
92243
92244 /* notifier block for netdevice event */
92245-static struct notifier_block can_netdev_notifier __read_mostly = {
92246+static struct notifier_block can_netdev_notifier = {
92247 .notifier_call = can_notifier,
92248 };
92249
92250diff --git a/net/can/gw.c b/net/can/gw.c
92251index 3f9b0f3..fc6d4fa 100644
92252--- a/net/can/gw.c
92253+++ b/net/can/gw.c
92254@@ -80,7 +80,6 @@ MODULE_PARM_DESC(max_hops,
92255 "default: " __stringify(CGW_DEFAULT_HOPS) ")");
92256
92257 static HLIST_HEAD(cgw_list);
92258-static struct notifier_block notifier;
92259
92260 static struct kmem_cache *cgw_cache __read_mostly;
92261
92262@@ -954,6 +953,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh)
92263 return err;
92264 }
92265
92266+static struct notifier_block notifier = {
92267+ .notifier_call = cgw_notifier
92268+};
92269+
92270 static __init int cgw_module_init(void)
92271 {
92272 /* sanitize given module parameter */
92273@@ -969,7 +972,6 @@ static __init int cgw_module_init(void)
92274 return -ENOMEM;
92275
92276 /* set notifier */
92277- notifier.notifier_call = cgw_notifier;
92278 register_netdevice_notifier(&notifier);
92279
92280 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
92281diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
92282index 4a5df7b..9ad1f1d 100644
92283--- a/net/ceph/messenger.c
92284+++ b/net/ceph/messenger.c
92285@@ -186,7 +186,7 @@ static void con_fault(struct ceph_connection *con);
92286 #define MAX_ADDR_STR_LEN 64 /* 54 is enough */
92287
92288 static char addr_str[ADDR_STR_COUNT][MAX_ADDR_STR_LEN];
92289-static atomic_t addr_str_seq = ATOMIC_INIT(0);
92290+static atomic_unchecked_t addr_str_seq = ATOMIC_INIT(0);
92291
92292 static struct page *zero_page; /* used in certain error cases */
92293
92294@@ -197,7 +197,7 @@ const char *ceph_pr_addr(const struct sockaddr_storage *ss)
92295 struct sockaddr_in *in4 = (struct sockaddr_in *) ss;
92296 struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) ss;
92297
92298- i = atomic_inc_return(&addr_str_seq) & ADDR_STR_COUNT_MASK;
92299+ i = atomic_inc_return_unchecked(&addr_str_seq) & ADDR_STR_COUNT_MASK;
92300 s = addr_str[i];
92301
92302 switch (ss->ss_family) {
92303diff --git a/net/compat.c b/net/compat.c
92304index 8903258..24e30e5 100644
92305--- a/net/compat.c
92306+++ b/net/compat.c
92307@@ -73,9 +73,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
92308 return -EFAULT;
92309 if (kmsg->msg_namelen > sizeof(struct sockaddr_storage))
92310 return -EINVAL;
92311- kmsg->msg_name = compat_ptr(tmp1);
92312- kmsg->msg_iov = compat_ptr(tmp2);
92313- kmsg->msg_control = compat_ptr(tmp3);
92314+ kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
92315+ kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
92316+ kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
92317 return 0;
92318 }
92319
92320@@ -87,7 +87,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
92321
92322 if (kern_msg->msg_namelen) {
92323 if (mode == VERIFY_READ) {
92324- int err = move_addr_to_kernel(kern_msg->msg_name,
92325+ int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
92326 kern_msg->msg_namelen,
92327 kern_address);
92328 if (err < 0)
92329@@ -98,7 +98,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
92330 kern_msg->msg_name = NULL;
92331
92332 tot_len = iov_from_user_compat_to_kern(kern_iov,
92333- (struct compat_iovec __user *)kern_msg->msg_iov,
92334+ (struct compat_iovec __force_user *)kern_msg->msg_iov,
92335 kern_msg->msg_iovlen);
92336 if (tot_len >= 0)
92337 kern_msg->msg_iov = kern_iov;
92338@@ -118,20 +118,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
92339
92340 #define CMSG_COMPAT_FIRSTHDR(msg) \
92341 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
92342- (struct compat_cmsghdr __user *)((msg)->msg_control) : \
92343+ (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
92344 (struct compat_cmsghdr __user *)NULL)
92345
92346 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
92347 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
92348 (ucmlen) <= (unsigned long) \
92349 ((mhdr)->msg_controllen - \
92350- ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
92351+ ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
92352
92353 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
92354 struct compat_cmsghdr __user *cmsg, int cmsg_len)
92355 {
92356 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
92357- if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
92358+ if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
92359 msg->msg_controllen)
92360 return NULL;
92361 return (struct compat_cmsghdr __user *)ptr;
92362@@ -221,7 +221,7 @@ Efault:
92363
92364 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
92365 {
92366- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
92367+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
92368 struct compat_cmsghdr cmhdr;
92369 struct compat_timeval ctv;
92370 struct compat_timespec cts[3];
92371@@ -277,7 +277,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
92372
92373 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
92374 {
92375- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
92376+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
92377 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
92378 int fdnum = scm->fp->count;
92379 struct file **fp = scm->fp->fp;
92380@@ -365,7 +365,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
92381 return -EFAULT;
92382 old_fs = get_fs();
92383 set_fs(KERNEL_DS);
92384- err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
92385+ err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
92386 set_fs(old_fs);
92387
92388 return err;
92389@@ -426,7 +426,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
92390 len = sizeof(ktime);
92391 old_fs = get_fs();
92392 set_fs(KERNEL_DS);
92393- err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
92394+ err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
92395 set_fs(old_fs);
92396
92397 if (!err) {
92398@@ -569,7 +569,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
92399 case MCAST_JOIN_GROUP:
92400 case MCAST_LEAVE_GROUP:
92401 {
92402- struct compat_group_req __user *gr32 = (void *)optval;
92403+ struct compat_group_req __user *gr32 = (void __user *)optval;
92404 struct group_req __user *kgr =
92405 compat_alloc_user_space(sizeof(struct group_req));
92406 u32 interface;
92407@@ -590,7 +590,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
92408 case MCAST_BLOCK_SOURCE:
92409 case MCAST_UNBLOCK_SOURCE:
92410 {
92411- struct compat_group_source_req __user *gsr32 = (void *)optval;
92412+ struct compat_group_source_req __user *gsr32 = (void __user *)optval;
92413 struct group_source_req __user *kgsr = compat_alloc_user_space(
92414 sizeof(struct group_source_req));
92415 u32 interface;
92416@@ -611,7 +611,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
92417 }
92418 case MCAST_MSFILTER:
92419 {
92420- struct compat_group_filter __user *gf32 = (void *)optval;
92421+ struct compat_group_filter __user *gf32 = (void __user *)optval;
92422 struct group_filter __user *kgf;
92423 u32 interface, fmode, numsrc;
92424
92425@@ -649,7 +649,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
92426 char __user *optval, int __user *optlen,
92427 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
92428 {
92429- struct compat_group_filter __user *gf32 = (void *)optval;
92430+ struct compat_group_filter __user *gf32 = (void __user *)optval;
92431 struct group_filter __user *kgf;
92432 int __user *koptlen;
92433 u32 interface, fmode, numsrc;
92434@@ -807,7 +807,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
92435
92436 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
92437 return -EINVAL;
92438- if (copy_from_user(a, args, nas[call]))
92439+ if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
92440 return -EFAULT;
92441 a0 = a[0];
92442 a1 = a[1];
92443diff --git a/net/core/datagram.c b/net/core/datagram.c
92444index af814e7..3d761de 100644
92445--- a/net/core/datagram.c
92446+++ b/net/core/datagram.c
92447@@ -301,7 +301,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
92448 }
92449
92450 kfree_skb(skb);
92451- atomic_inc(&sk->sk_drops);
92452+ atomic_inc_unchecked(&sk->sk_drops);
92453 sk_mem_reclaim_partial(sk);
92454
92455 return err;
92456diff --git a/net/core/dev.c b/net/core/dev.c
92457index 3430b1e..d6453ad 100644
92458--- a/net/core/dev.c
92459+++ b/net/core/dev.c
92460@@ -1680,14 +1680,14 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
92461 {
92462 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
92463 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
92464- atomic_long_inc(&dev->rx_dropped);
92465+ atomic_long_inc_unchecked(&dev->rx_dropped);
92466 kfree_skb(skb);
92467 return NET_RX_DROP;
92468 }
92469 }
92470
92471 if (unlikely(!is_skb_forwardable(dev, skb))) {
92472- atomic_long_inc(&dev->rx_dropped);
92473+ atomic_long_inc_unchecked(&dev->rx_dropped);
92474 kfree_skb(skb);
92475 return NET_RX_DROP;
92476 }
92477@@ -2432,7 +2432,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
92478
92479 struct dev_gso_cb {
92480 void (*destructor)(struct sk_buff *skb);
92481-};
92482+} __no_const;
92483
92484 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
92485
92486@@ -3207,7 +3207,7 @@ enqueue:
92487
92488 local_irq_restore(flags);
92489
92490- atomic_long_inc(&skb->dev->rx_dropped);
92491+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
92492 kfree_skb(skb);
92493 return NET_RX_DROP;
92494 }
92495@@ -3279,7 +3279,7 @@ int netif_rx_ni(struct sk_buff *skb)
92496 }
92497 EXPORT_SYMBOL(netif_rx_ni);
92498
92499-static void net_tx_action(struct softirq_action *h)
92500+static __latent_entropy void net_tx_action(void)
92501 {
92502 struct softnet_data *sd = &__get_cpu_var(softnet_data);
92503
92504@@ -3613,7 +3613,7 @@ ncls:
92505 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
92506 } else {
92507 drop:
92508- atomic_long_inc(&skb->dev->rx_dropped);
92509+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
92510 kfree_skb(skb);
92511 /* Jamal, now you will not able to escape explaining
92512 * me how you were going to use this. :-)
92513@@ -4273,7 +4273,7 @@ void netif_napi_del(struct napi_struct *napi)
92514 }
92515 EXPORT_SYMBOL(netif_napi_del);
92516
92517-static void net_rx_action(struct softirq_action *h)
92518+static __latent_entropy void net_rx_action(void)
92519 {
92520 struct softnet_data *sd = &__get_cpu_var(softnet_data);
92521 unsigned long time_limit = jiffies + 2;
92522@@ -5977,7 +5977,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
92523 } else {
92524 netdev_stats_to_stats64(storage, &dev->stats);
92525 }
92526- storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
92527+ storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
92528 return storage;
92529 }
92530 EXPORT_SYMBOL(dev_get_stats);
92531diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
92532index 5b7d0e1..cb960fc 100644
92533--- a/net/core/dev_ioctl.c
92534+++ b/net/core/dev_ioctl.c
92535@@ -365,9 +365,13 @@ void dev_load(struct net *net, const char *name)
92536 if (no_module && capable(CAP_NET_ADMIN))
92537 no_module = request_module("netdev-%s", name);
92538 if (no_module && capable(CAP_SYS_MODULE)) {
92539+#ifdef CONFIG_GRKERNSEC_MODHARDEN
92540+ ___request_module(true, "grsec_modharden_netdev", "%s", name);
92541+#else
92542 if (!request_module("%s", name))
92543 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
92544 name);
92545+#endif
92546 }
92547 }
92548 EXPORT_SYMBOL(dev_load);
92549diff --git a/net/core/flow.c b/net/core/flow.c
92550index dfa602c..3103d88 100644
92551--- a/net/core/flow.c
92552+++ b/net/core/flow.c
92553@@ -61,7 +61,7 @@ struct flow_cache {
92554 struct timer_list rnd_timer;
92555 };
92556
92557-atomic_t flow_cache_genid = ATOMIC_INIT(0);
92558+atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
92559 EXPORT_SYMBOL(flow_cache_genid);
92560 static struct flow_cache flow_cache_global;
92561 static struct kmem_cache *flow_cachep __read_mostly;
92562@@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
92563
92564 static int flow_entry_valid(struct flow_cache_entry *fle)
92565 {
92566- if (atomic_read(&flow_cache_genid) != fle->genid)
92567+ if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
92568 return 0;
92569 if (fle->object && !fle->object->ops->check(fle->object))
92570 return 0;
92571@@ -258,7 +258,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
92572 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
92573 fcp->hash_count++;
92574 }
92575- } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
92576+ } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
92577 flo = fle->object;
92578 if (!flo)
92579 goto ret_object;
92580@@ -279,7 +279,7 @@ nocache:
92581 }
92582 flo = resolver(net, key, family, dir, flo, ctx);
92583 if (fle) {
92584- fle->genid = atomic_read(&flow_cache_genid);
92585+ fle->genid = atomic_read_unchecked(&flow_cache_genid);
92586 if (!IS_ERR(flo))
92587 fle->object = flo;
92588 else
92589diff --git a/net/core/iovec.c b/net/core/iovec.c
92590index b77eeec..2890aca 100644
92591--- a/net/core/iovec.c
92592+++ b/net/core/iovec.c
92593@@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
92594 if (m->msg_namelen) {
92595 if (mode == VERIFY_READ) {
92596 void __user *namep;
92597- namep = (void __user __force *) m->msg_name;
92598+ namep = (void __force_user *) m->msg_name;
92599 err = move_addr_to_kernel(namep, m->msg_namelen,
92600 address);
92601 if (err < 0)
92602@@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
92603 }
92604
92605 size = m->msg_iovlen * sizeof(struct iovec);
92606- if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
92607+ if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
92608 return -EFAULT;
92609
92610 m->msg_iov = iov;
92611diff --git a/net/core/neighbour.c b/net/core/neighbour.c
92612index 6072610..7374c18 100644
92613--- a/net/core/neighbour.c
92614+++ b/net/core/neighbour.c
92615@@ -2774,7 +2774,7 @@ static int proc_unres_qlen(struct ctl_table *ctl, int write,
92616 void __user *buffer, size_t *lenp, loff_t *ppos)
92617 {
92618 int size, ret;
92619- struct ctl_table tmp = *ctl;
92620+ ctl_table_no_const tmp = *ctl;
92621
92622 tmp.extra1 = &zero;
92623 tmp.extra2 = &unres_qlen_max;
92624diff --git a/net/core/net-procfs.c b/net/core/net-procfs.c
92625index 2bf8329..7960607 100644
92626--- a/net/core/net-procfs.c
92627+++ b/net/core/net-procfs.c
92628@@ -283,8 +283,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
92629 else
92630 seq_printf(seq, "%04x", ntohs(pt->type));
92631
92632+#ifdef CONFIG_GRKERNSEC_HIDESYM
92633+ seq_printf(seq, " %-8s %pf\n",
92634+ pt->dev ? pt->dev->name : "", NULL);
92635+#else
92636 seq_printf(seq, " %-8s %pf\n",
92637 pt->dev ? pt->dev->name : "", pt->func);
92638+#endif
92639 }
92640
92641 return 0;
92642diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
92643index d954b56..b0a0f7a 100644
92644--- a/net/core/net-sysfs.c
92645+++ b/net/core/net-sysfs.c
92646@@ -1356,7 +1356,7 @@ void netdev_class_remove_file(struct class_attribute *class_attr)
92647 }
92648 EXPORT_SYMBOL(netdev_class_remove_file);
92649
92650-int netdev_kobject_init(void)
92651+int __init netdev_kobject_init(void)
92652 {
92653 kobj_ns_type_register(&net_ns_type_operations);
92654 return class_register(&net_class);
92655diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
92656index 81d3a9a..a0bd7a8 100644
92657--- a/net/core/net_namespace.c
92658+++ b/net/core/net_namespace.c
92659@@ -443,7 +443,7 @@ static int __register_pernet_operations(struct list_head *list,
92660 int error;
92661 LIST_HEAD(net_exit_list);
92662
92663- list_add_tail(&ops->list, list);
92664+ pax_list_add_tail((struct list_head *)&ops->list, list);
92665 if (ops->init || (ops->id && ops->size)) {
92666 for_each_net(net) {
92667 error = ops_init(ops, net);
92668@@ -456,7 +456,7 @@ static int __register_pernet_operations(struct list_head *list,
92669
92670 out_undo:
92671 /* If I have an error cleanup all namespaces I initialized */
92672- list_del(&ops->list);
92673+ pax_list_del((struct list_head *)&ops->list);
92674 ops_exit_list(ops, &net_exit_list);
92675 ops_free_list(ops, &net_exit_list);
92676 return error;
92677@@ -467,7 +467,7 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
92678 struct net *net;
92679 LIST_HEAD(net_exit_list);
92680
92681- list_del(&ops->list);
92682+ pax_list_del((struct list_head *)&ops->list);
92683 for_each_net(net)
92684 list_add_tail(&net->exit_list, &net_exit_list);
92685 ops_exit_list(ops, &net_exit_list);
92686@@ -601,7 +601,7 @@ int register_pernet_device(struct pernet_operations *ops)
92687 mutex_lock(&net_mutex);
92688 error = register_pernet_operations(&pernet_list, ops);
92689 if (!error && (first_device == &pernet_list))
92690- first_device = &ops->list;
92691+ first_device = (struct list_head *)&ops->list;
92692 mutex_unlock(&net_mutex);
92693 return error;
92694 }
92695diff --git a/net/core/netpoll.c b/net/core/netpoll.c
92696index fc75c9e..8c8e9be 100644
92697--- a/net/core/netpoll.c
92698+++ b/net/core/netpoll.c
92699@@ -428,7 +428,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
92700 struct udphdr *udph;
92701 struct iphdr *iph;
92702 struct ethhdr *eth;
92703- static atomic_t ip_ident;
92704+ static atomic_unchecked_t ip_ident;
92705 struct ipv6hdr *ip6h;
92706
92707 udp_len = len + sizeof(*udph);
92708@@ -499,7 +499,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
92709 put_unaligned(0x45, (unsigned char *)iph);
92710 iph->tos = 0;
92711 put_unaligned(htons(ip_len), &(iph->tot_len));
92712- iph->id = htons(atomic_inc_return(&ip_ident));
92713+ iph->id = htons(atomic_inc_return_unchecked(&ip_ident));
92714 iph->frag_off = 0;
92715 iph->ttl = 64;
92716 iph->protocol = IPPROTO_UDP;
92717diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
92718index 2a0e21d..6ad7642 100644
92719--- a/net/core/rtnetlink.c
92720+++ b/net/core/rtnetlink.c
92721@@ -58,7 +58,7 @@ struct rtnl_link {
92722 rtnl_doit_func doit;
92723 rtnl_dumpit_func dumpit;
92724 rtnl_calcit_func calcit;
92725-};
92726+} __no_const;
92727
92728 static DEFINE_MUTEX(rtnl_mutex);
92729
92730@@ -299,10 +299,13 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
92731 if (rtnl_link_ops_get(ops->kind))
92732 return -EEXIST;
92733
92734- if (!ops->dellink)
92735- ops->dellink = unregister_netdevice_queue;
92736+ if (!ops->dellink) {
92737+ pax_open_kernel();
92738+ *(void **)&ops->dellink = unregister_netdevice_queue;
92739+ pax_close_kernel();
92740+ }
92741
92742- list_add_tail(&ops->list, &link_ops);
92743+ pax_list_add_tail((struct list_head *)&ops->list, &link_ops);
92744 return 0;
92745 }
92746 EXPORT_SYMBOL_GPL(__rtnl_link_register);
92747@@ -349,7 +352,7 @@ void __rtnl_link_unregister(struct rtnl_link_ops *ops)
92748 for_each_net(net) {
92749 __rtnl_kill_links(net, ops);
92750 }
92751- list_del(&ops->list);
92752+ pax_list_del((struct list_head *)&ops->list);
92753 }
92754 EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
92755
92756diff --git a/net/core/scm.c b/net/core/scm.c
92757index b442e7e..6f5b5a2 100644
92758--- a/net/core/scm.c
92759+++ b/net/core/scm.c
92760@@ -210,7 +210,7 @@ EXPORT_SYMBOL(__scm_send);
92761 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
92762 {
92763 struct cmsghdr __user *cm
92764- = (__force struct cmsghdr __user *)msg->msg_control;
92765+ = (struct cmsghdr __force_user *)msg->msg_control;
92766 struct cmsghdr cmhdr;
92767 int cmlen = CMSG_LEN(len);
92768 int err;
92769@@ -233,7 +233,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
92770 err = -EFAULT;
92771 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
92772 goto out;
92773- if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
92774+ if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
92775 goto out;
92776 cmlen = CMSG_SPACE(len);
92777 if (msg->msg_controllen < cmlen)
92778@@ -249,7 +249,7 @@ EXPORT_SYMBOL(put_cmsg);
92779 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
92780 {
92781 struct cmsghdr __user *cm
92782- = (__force struct cmsghdr __user*)msg->msg_control;
92783+ = (struct cmsghdr __force_user *)msg->msg_control;
92784
92785 int fdmax = 0;
92786 int fdnum = scm->fp->count;
92787@@ -269,7 +269,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
92788 if (fdnum < fdmax)
92789 fdmax = fdnum;
92790
92791- for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
92792+ for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
92793 i++, cmfptr++)
92794 {
92795 struct socket *sock;
92796diff --git a/net/core/skbuff.c b/net/core/skbuff.c
92797index d81cff1..e31f952 100644
92798--- a/net/core/skbuff.c
92799+++ b/net/core/skbuff.c
92800@@ -3082,13 +3082,15 @@ void __init skb_init(void)
92801 skbuff_head_cache = kmem_cache_create("skbuff_head_cache",
92802 sizeof(struct sk_buff),
92803 0,
92804- SLAB_HWCACHE_ALIGN|SLAB_PANIC,
92805+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|
92806+ SLAB_NO_SANITIZE,
92807 NULL);
92808 skbuff_fclone_cache = kmem_cache_create("skbuff_fclone_cache",
92809 (2*sizeof(struct sk_buff)) +
92810 sizeof(atomic_t),
92811 0,
92812- SLAB_HWCACHE_ALIGN|SLAB_PANIC,
92813+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|
92814+ SLAB_NO_SANITIZE,
92815 NULL);
92816 }
92817
92818diff --git a/net/core/sock.c b/net/core/sock.c
92819index 0b39e7a..5e9f91e 100644
92820--- a/net/core/sock.c
92821+++ b/net/core/sock.c
92822@@ -393,7 +393,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
92823 struct sk_buff_head *list = &sk->sk_receive_queue;
92824
92825 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
92826- atomic_inc(&sk->sk_drops);
92827+ atomic_inc_unchecked(&sk->sk_drops);
92828 trace_sock_rcvqueue_full(sk, skb);
92829 return -ENOMEM;
92830 }
92831@@ -403,7 +403,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
92832 return err;
92833
92834 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
92835- atomic_inc(&sk->sk_drops);
92836+ atomic_inc_unchecked(&sk->sk_drops);
92837 return -ENOBUFS;
92838 }
92839
92840@@ -423,7 +423,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
92841 skb_dst_force(skb);
92842
92843 spin_lock_irqsave(&list->lock, flags);
92844- skb->dropcount = atomic_read(&sk->sk_drops);
92845+ skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
92846 __skb_queue_tail(list, skb);
92847 spin_unlock_irqrestore(&list->lock, flags);
92848
92849@@ -443,7 +443,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
92850 skb->dev = NULL;
92851
92852 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
92853- atomic_inc(&sk->sk_drops);
92854+ atomic_inc_unchecked(&sk->sk_drops);
92855 goto discard_and_relse;
92856 }
92857 if (nested)
92858@@ -461,7 +461,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
92859 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
92860 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
92861 bh_unlock_sock(sk);
92862- atomic_inc(&sk->sk_drops);
92863+ atomic_inc_unchecked(&sk->sk_drops);
92864 goto discard_and_relse;
92865 }
92866
92867@@ -949,12 +949,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
92868 struct timeval tm;
92869 } v;
92870
92871- int lv = sizeof(int);
92872- int len;
92873+ unsigned int lv = sizeof(int);
92874+ unsigned int len;
92875
92876 if (get_user(len, optlen))
92877 return -EFAULT;
92878- if (len < 0)
92879+ if (len > INT_MAX)
92880 return -EINVAL;
92881
92882 memset(&v, 0, sizeof(v));
92883@@ -1106,11 +1106,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
92884
92885 case SO_PEERNAME:
92886 {
92887- char address[128];
92888+ char address[_K_SS_MAXSIZE];
92889
92890 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
92891 return -ENOTCONN;
92892- if (lv < len)
92893+ if (lv < len || sizeof address < len)
92894 return -EINVAL;
92895 if (copy_to_user(optval, address, len))
92896 return -EFAULT;
92897@@ -1183,7 +1183,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
92898
92899 if (len > lv)
92900 len = lv;
92901- if (copy_to_user(optval, &v, len))
92902+ if (len > sizeof(v) || copy_to_user(optval, &v, len))
92903 return -EFAULT;
92904 lenout:
92905 if (put_user(len, optlen))
92906@@ -2326,7 +2326,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
92907 */
92908 smp_wmb();
92909 atomic_set(&sk->sk_refcnt, 1);
92910- atomic_set(&sk->sk_drops, 0);
92911+ atomic_set_unchecked(&sk->sk_drops, 0);
92912 }
92913 EXPORT_SYMBOL(sock_init_data);
92914
92915@@ -2451,6 +2451,7 @@ void sock_enable_timestamp(struct sock *sk, int flag)
92916 int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
92917 int level, int type)
92918 {
92919+ struct sock_extended_err ee;
92920 struct sock_exterr_skb *serr;
92921 struct sk_buff *skb, *skb2;
92922 int copied, err;
92923@@ -2472,7 +2473,8 @@ int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
92924 sock_recv_timestamp(msg, sk, skb);
92925
92926 serr = SKB_EXT_ERR(skb);
92927- put_cmsg(msg, level, type, sizeof(serr->ee), &serr->ee);
92928+ ee = serr->ee;
92929+ put_cmsg(msg, level, type, sizeof ee, &ee);
92930
92931 msg->msg_flags |= MSG_ERRQUEUE;
92932 err = copied;
92933diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
92934index a0e9cf6..ef7f9ed 100644
92935--- a/net/core/sock_diag.c
92936+++ b/net/core/sock_diag.c
92937@@ -9,26 +9,33 @@
92938 #include <linux/inet_diag.h>
92939 #include <linux/sock_diag.h>
92940
92941-static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
92942+static const struct sock_diag_handler *sock_diag_handlers[AF_MAX] __read_only;
92943 static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
92944 static DEFINE_MUTEX(sock_diag_table_mutex);
92945
92946 int sock_diag_check_cookie(void *sk, __u32 *cookie)
92947 {
92948+#ifndef CONFIG_GRKERNSEC_HIDESYM
92949 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
92950 cookie[1] != INET_DIAG_NOCOOKIE) &&
92951 ((u32)(unsigned long)sk != cookie[0] ||
92952 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
92953 return -ESTALE;
92954 else
92955+#endif
92956 return 0;
92957 }
92958 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
92959
92960 void sock_diag_save_cookie(void *sk, __u32 *cookie)
92961 {
92962+#ifdef CONFIG_GRKERNSEC_HIDESYM
92963+ cookie[0] = 0;
92964+ cookie[1] = 0;
92965+#else
92966 cookie[0] = (u32)(unsigned long)sk;
92967 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
92968+#endif
92969 }
92970 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
92971
92972@@ -113,8 +120,11 @@ int sock_diag_register(const struct sock_diag_handler *hndl)
92973 mutex_lock(&sock_diag_table_mutex);
92974 if (sock_diag_handlers[hndl->family])
92975 err = -EBUSY;
92976- else
92977+ else {
92978+ pax_open_kernel();
92979 sock_diag_handlers[hndl->family] = hndl;
92980+ pax_close_kernel();
92981+ }
92982 mutex_unlock(&sock_diag_table_mutex);
92983
92984 return err;
92985@@ -130,7 +140,9 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
92986
92987 mutex_lock(&sock_diag_table_mutex);
92988 BUG_ON(sock_diag_handlers[family] != hnld);
92989+ pax_open_kernel();
92990 sock_diag_handlers[family] = NULL;
92991+ pax_close_kernel();
92992 mutex_unlock(&sock_diag_table_mutex);
92993 }
92994 EXPORT_SYMBOL_GPL(sock_diag_unregister);
92995diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
92996index cca4441..5e616de 100644
92997--- a/net/core/sysctl_net_core.c
92998+++ b/net/core/sysctl_net_core.c
92999@@ -32,7 +32,7 @@ static int rps_sock_flow_sysctl(struct ctl_table *table, int write,
93000 {
93001 unsigned int orig_size, size;
93002 int ret, i;
93003- struct ctl_table tmp = {
93004+ ctl_table_no_const tmp = {
93005 .data = &size,
93006 .maxlen = sizeof(size),
93007 .mode = table->mode
93008@@ -199,7 +199,7 @@ static int set_default_qdisc(struct ctl_table *table, int write,
93009 void __user *buffer, size_t *lenp, loff_t *ppos)
93010 {
93011 char id[IFNAMSIZ];
93012- struct ctl_table tbl = {
93013+ ctl_table_no_const tbl = {
93014 .data = id,
93015 .maxlen = IFNAMSIZ,
93016 };
93017@@ -378,13 +378,12 @@ static struct ctl_table netns_core_table[] = {
93018
93019 static __net_init int sysctl_core_net_init(struct net *net)
93020 {
93021- struct ctl_table *tbl;
93022+ ctl_table_no_const *tbl = NULL;
93023
93024 net->core.sysctl_somaxconn = SOMAXCONN;
93025
93026- tbl = netns_core_table;
93027 if (!net_eq(net, &init_net)) {
93028- tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
93029+ tbl = kmemdup(netns_core_table, sizeof(netns_core_table), GFP_KERNEL);
93030 if (tbl == NULL)
93031 goto err_dup;
93032
93033@@ -394,17 +393,16 @@ static __net_init int sysctl_core_net_init(struct net *net)
93034 if (net->user_ns != &init_user_ns) {
93035 tbl[0].procname = NULL;
93036 }
93037- }
93038-
93039- net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
93040+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
93041+ } else
93042+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", netns_core_table);
93043 if (net->core.sysctl_hdr == NULL)
93044 goto err_reg;
93045
93046 return 0;
93047
93048 err_reg:
93049- if (tbl != netns_core_table)
93050- kfree(tbl);
93051+ kfree(tbl);
93052 err_dup:
93053 return -ENOMEM;
93054 }
93055@@ -419,7 +417,7 @@ static __net_exit void sysctl_core_net_exit(struct net *net)
93056 kfree(tbl);
93057 }
93058
93059-static __net_initdata struct pernet_operations sysctl_core_ops = {
93060+static __net_initconst struct pernet_operations sysctl_core_ops = {
93061 .init = sysctl_core_net_init,
93062 .exit = sysctl_core_net_exit,
93063 };
93064diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
93065index dd4d506..fb2fb87 100644
93066--- a/net/decnet/af_decnet.c
93067+++ b/net/decnet/af_decnet.c
93068@@ -465,6 +465,7 @@ static struct proto dn_proto = {
93069 .sysctl_rmem = sysctl_decnet_rmem,
93070 .max_header = DN_MAX_NSP_DATA_HEADER + 64,
93071 .obj_size = sizeof(struct dn_sock),
93072+ .slab_flags = SLAB_USERCOPY,
93073 };
93074
93075 static struct sock *dn_alloc_sock(struct net *net, struct socket *sock, gfp_t gfp)
93076diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
93077index 5325b54..a0d4d69 100644
93078--- a/net/decnet/sysctl_net_decnet.c
93079+++ b/net/decnet/sysctl_net_decnet.c
93080@@ -174,7 +174,7 @@ static int dn_node_address_handler(struct ctl_table *table, int write,
93081
93082 if (len > *lenp) len = *lenp;
93083
93084- if (copy_to_user(buffer, addr, len))
93085+ if (len > sizeof addr || copy_to_user(buffer, addr, len))
93086 return -EFAULT;
93087
93088 *lenp = len;
93089@@ -237,7 +237,7 @@ static int dn_def_dev_handler(struct ctl_table *table, int write,
93090
93091 if (len > *lenp) len = *lenp;
93092
93093- if (copy_to_user(buffer, devname, len))
93094+ if (len > sizeof devname || copy_to_user(buffer, devname, len))
93095 return -EFAULT;
93096
93097 *lenp = len;
93098diff --git a/net/ieee802154/6lowpan.c b/net/ieee802154/6lowpan.c
93099index ff41b4d6..6125050 100644
93100--- a/net/ieee802154/6lowpan.c
93101+++ b/net/ieee802154/6lowpan.c
93102@@ -548,7 +548,7 @@ static int lowpan_header_create(struct sk_buff *skb,
93103 hc06_ptr += 3;
93104 } else {
93105 /* compress nothing */
93106- memcpy(hc06_ptr, &hdr, 4);
93107+ memcpy(hc06_ptr, hdr, 4);
93108 /* replace the top byte with new ECN | DSCP format */
93109 *hc06_ptr = tmp;
93110 hc06_ptr += 4;
93111diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
93112index cfeb85c..385989a 100644
93113--- a/net/ipv4/af_inet.c
93114+++ b/net/ipv4/af_inet.c
93115@@ -1675,13 +1675,9 @@ static int __init inet_init(void)
93116
93117 BUILD_BUG_ON(sizeof(struct inet_skb_parm) > FIELD_SIZEOF(struct sk_buff, cb));
93118
93119- sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
93120- if (!sysctl_local_reserved_ports)
93121- goto out;
93122-
93123 rc = proto_register(&tcp_prot, 1);
93124 if (rc)
93125- goto out_free_reserved_ports;
93126+ goto out;
93127
93128 rc = proto_register(&udp_prot, 1);
93129 if (rc)
93130@@ -1790,8 +1786,6 @@ out_unregister_udp_proto:
93131 proto_unregister(&udp_prot);
93132 out_unregister_tcp_proto:
93133 proto_unregister(&tcp_prot);
93134-out_free_reserved_ports:
93135- kfree(sysctl_local_reserved_ports);
93136 goto out;
93137 }
93138
93139diff --git a/net/ipv4/datagram.c b/net/ipv4/datagram.c
93140index b28e863..19e3637 100644
93141--- a/net/ipv4/datagram.c
93142+++ b/net/ipv4/datagram.c
93143@@ -57,7 +57,7 @@ int ip4_datagram_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len)
93144 if (IS_ERR(rt)) {
93145 err = PTR_ERR(rt);
93146 if (err == -ENETUNREACH)
93147- IP_INC_STATS_BH(sock_net(sk), IPSTATS_MIB_OUTNOROUTES);
93148+ IP_INC_STATS(sock_net(sk), IPSTATS_MIB_OUTNOROUTES);
93149 goto out;
93150 }
93151
93152diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
93153index a1b5bcb..62ec5c6 100644
93154--- a/net/ipv4/devinet.c
93155+++ b/net/ipv4/devinet.c
93156@@ -1533,7 +1533,7 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
93157 idx = 0;
93158 head = &net->dev_index_head[h];
93159 rcu_read_lock();
93160- cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
93161+ cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
93162 net->dev_base_seq;
93163 hlist_for_each_entry_rcu(dev, head, index_hlist) {
93164 if (idx < s_idx)
93165@@ -1844,7 +1844,7 @@ static int inet_netconf_dump_devconf(struct sk_buff *skb,
93166 idx = 0;
93167 head = &net->dev_index_head[h];
93168 rcu_read_lock();
93169- cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
93170+ cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
93171 net->dev_base_seq;
93172 hlist_for_each_entry_rcu(dev, head, index_hlist) {
93173 if (idx < s_idx)
93174@@ -2069,7 +2069,7 @@ static int ipv4_doint_and_flush(struct ctl_table *ctl, int write,
93175 #define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
93176 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush)
93177
93178-static struct devinet_sysctl_table {
93179+static const struct devinet_sysctl_table {
93180 struct ctl_table_header *sysctl_header;
93181 struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
93182 } devinet_sysctl = {
93183@@ -2191,7 +2191,7 @@ static __net_init int devinet_init_net(struct net *net)
93184 int err;
93185 struct ipv4_devconf *all, *dflt;
93186 #ifdef CONFIG_SYSCTL
93187- struct ctl_table *tbl = ctl_forward_entry;
93188+ ctl_table_no_const *tbl = NULL;
93189 struct ctl_table_header *forw_hdr;
93190 #endif
93191
93192@@ -2209,7 +2209,7 @@ static __net_init int devinet_init_net(struct net *net)
93193 goto err_alloc_dflt;
93194
93195 #ifdef CONFIG_SYSCTL
93196- tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL);
93197+ tbl = kmemdup(ctl_forward_entry, sizeof(ctl_forward_entry), GFP_KERNEL);
93198 if (tbl == NULL)
93199 goto err_alloc_ctl;
93200
93201@@ -2229,7 +2229,10 @@ static __net_init int devinet_init_net(struct net *net)
93202 goto err_reg_dflt;
93203
93204 err = -ENOMEM;
93205- forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
93206+ if (!net_eq(net, &init_net))
93207+ forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
93208+ else
93209+ forw_hdr = register_net_sysctl(net, "net/ipv4", ctl_forward_entry);
93210 if (forw_hdr == NULL)
93211 goto err_reg_ctl;
93212 net->ipv4.forw_hdr = forw_hdr;
93213@@ -2245,8 +2248,7 @@ err_reg_ctl:
93214 err_reg_dflt:
93215 __devinet_sysctl_unregister(all);
93216 err_reg_all:
93217- if (tbl != ctl_forward_entry)
93218- kfree(tbl);
93219+ kfree(tbl);
93220 err_alloc_ctl:
93221 #endif
93222 if (dflt != &ipv4_devconf_dflt)
93223diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
93224index b3f627a..b0f3e99 100644
93225--- a/net/ipv4/fib_frontend.c
93226+++ b/net/ipv4/fib_frontend.c
93227@@ -1017,12 +1017,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
93228 #ifdef CONFIG_IP_ROUTE_MULTIPATH
93229 fib_sync_up(dev);
93230 #endif
93231- atomic_inc(&net->ipv4.dev_addr_genid);
93232+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
93233 rt_cache_flush(dev_net(dev));
93234 break;
93235 case NETDEV_DOWN:
93236 fib_del_ifaddr(ifa, NULL);
93237- atomic_inc(&net->ipv4.dev_addr_genid);
93238+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
93239 if (ifa->ifa_dev->ifa_list == NULL) {
93240 /* Last address was deleted from this interface.
93241 * Disable IP.
93242@@ -1058,7 +1058,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
93243 #ifdef CONFIG_IP_ROUTE_MULTIPATH
93244 fib_sync_up(dev);
93245 #endif
93246- atomic_inc(&net->ipv4.dev_addr_genid);
93247+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
93248 rt_cache_flush(net);
93249 break;
93250 case NETDEV_DOWN:
93251diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
93252index d5dbca5..6251d5f 100644
93253--- a/net/ipv4/fib_semantics.c
93254+++ b/net/ipv4/fib_semantics.c
93255@@ -766,7 +766,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
93256 nh->nh_saddr = inet_select_addr(nh->nh_dev,
93257 nh->nh_gw,
93258 nh->nh_parent->fib_scope);
93259- nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
93260+ nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
93261
93262 return nh->nh_saddr;
93263 }
93264diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
93265index 6acb541..9ea617d 100644
93266--- a/net/ipv4/inet_connection_sock.c
93267+++ b/net/ipv4/inet_connection_sock.c
93268@@ -37,7 +37,7 @@ struct local_ports sysctl_local_ports __read_mostly = {
93269 .range = { 32768, 61000 },
93270 };
93271
93272-unsigned long *sysctl_local_reserved_ports;
93273+unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
93274 EXPORT_SYMBOL(sysctl_local_reserved_ports);
93275
93276 void inet_get_local_port_range(int *low, int *high)
93277diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
93278index 96da9c7..b956690 100644
93279--- a/net/ipv4/inet_hashtables.c
93280+++ b/net/ipv4/inet_hashtables.c
93281@@ -18,12 +18,15 @@
93282 #include <linux/sched.h>
93283 #include <linux/slab.h>
93284 #include <linux/wait.h>
93285+#include <linux/security.h>
93286
93287 #include <net/inet_connection_sock.h>
93288 #include <net/inet_hashtables.h>
93289 #include <net/secure_seq.h>
93290 #include <net/ip.h>
93291
93292+extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
93293+
93294 /*
93295 * Allocate and initialize a new local port bind bucket.
93296 * The bindhash mutex for snum's hash chain must be held here.
93297@@ -554,6 +557,8 @@ ok:
93298 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
93299 spin_unlock(&head->lock);
93300
93301+ gr_update_task_in_ip_table(current, inet_sk(sk));
93302+
93303 if (tw) {
93304 inet_twsk_deschedule(tw, death_row);
93305 while (twrefcnt) {
93306diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
93307index 33d5537..da337a4 100644
93308--- a/net/ipv4/inetpeer.c
93309+++ b/net/ipv4/inetpeer.c
93310@@ -503,8 +503,8 @@ relookup:
93311 if (p) {
93312 p->daddr = *daddr;
93313 atomic_set(&p->refcnt, 1);
93314- atomic_set(&p->rid, 0);
93315- atomic_set(&p->ip_id_count,
93316+ atomic_set_unchecked(&p->rid, 0);
93317+ atomic_set_unchecked(&p->ip_id_count,
93318 (daddr->family == AF_INET) ?
93319 secure_ip_id(daddr->addr.a4) :
93320 secure_ipv6_id(daddr->addr.a6));
93321diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
93322index b66910a..cfe416e 100644
93323--- a/net/ipv4/ip_fragment.c
93324+++ b/net/ipv4/ip_fragment.c
93325@@ -282,7 +282,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
93326 return 0;
93327
93328 start = qp->rid;
93329- end = atomic_inc_return(&peer->rid);
93330+ end = atomic_inc_return_unchecked(&peer->rid);
93331 qp->rid = end;
93332
93333 rc = qp->q.fragments && (end - start) > max;
93334@@ -759,12 +759,11 @@ static struct ctl_table ip4_frags_ctl_table[] = {
93335
93336 static int __net_init ip4_frags_ns_ctl_register(struct net *net)
93337 {
93338- struct ctl_table *table;
93339+ ctl_table_no_const *table = NULL;
93340 struct ctl_table_header *hdr;
93341
93342- table = ip4_frags_ns_ctl_table;
93343 if (!net_eq(net, &init_net)) {
93344- table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
93345+ table = kmemdup(ip4_frags_ns_ctl_table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
93346 if (table == NULL)
93347 goto err_alloc;
93348
93349@@ -775,9 +774,10 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
93350 /* Don't export sysctls to unprivileged users */
93351 if (net->user_ns != &init_user_ns)
93352 table[0].procname = NULL;
93353- }
93354+ hdr = register_net_sysctl(net, "net/ipv4", table);
93355+ } else
93356+ hdr = register_net_sysctl(net, "net/ipv4", ip4_frags_ns_ctl_table);
93357
93358- hdr = register_net_sysctl(net, "net/ipv4", table);
93359 if (hdr == NULL)
93360 goto err_reg;
93361
93362@@ -785,8 +785,7 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
93363 return 0;
93364
93365 err_reg:
93366- if (!net_eq(net, &init_net))
93367- kfree(table);
93368+ kfree(table);
93369 err_alloc:
93370 return -ENOMEM;
93371 }
93372diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
93373index d7aea4c..a8ee872 100644
93374--- a/net/ipv4/ip_gre.c
93375+++ b/net/ipv4/ip_gre.c
93376@@ -115,7 +115,7 @@ static bool log_ecn_error = true;
93377 module_param(log_ecn_error, bool, 0644);
93378 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
93379
93380-static struct rtnl_link_ops ipgre_link_ops __read_mostly;
93381+static struct rtnl_link_ops ipgre_link_ops;
93382 static int ipgre_tunnel_init(struct net_device *dev);
93383
93384 static int ipgre_net_id __read_mostly;
93385@@ -731,7 +731,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = {
93386 [IFLA_GRE_PMTUDISC] = { .type = NLA_U8 },
93387 };
93388
93389-static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
93390+static struct rtnl_link_ops ipgre_link_ops = {
93391 .kind = "gre",
93392 .maxtype = IFLA_GRE_MAX,
93393 .policy = ipgre_policy,
93394@@ -745,7 +745,7 @@ static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
93395 .fill_info = ipgre_fill_info,
93396 };
93397
93398-static struct rtnl_link_ops ipgre_tap_ops __read_mostly = {
93399+static struct rtnl_link_ops ipgre_tap_ops = {
93400 .kind = "gretap",
93401 .maxtype = IFLA_GRE_MAX,
93402 .policy = ipgre_policy,
93403diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
93404index d9c4f11..02b82dbc 100644
93405--- a/net/ipv4/ip_sockglue.c
93406+++ b/net/ipv4/ip_sockglue.c
93407@@ -1152,7 +1152,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
93408 len = min_t(unsigned int, len, opt->optlen);
93409 if (put_user(len, optlen))
93410 return -EFAULT;
93411- if (copy_to_user(optval, opt->__data, len))
93412+ if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
93413+ copy_to_user(optval, opt->__data, len))
93414 return -EFAULT;
93415 return 0;
93416 }
93417@@ -1283,7 +1284,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
93418 if (sk->sk_type != SOCK_STREAM)
93419 return -ENOPROTOOPT;
93420
93421- msg.msg_control = optval;
93422+ msg.msg_control = (void __force_kernel *)optval;
93423 msg.msg_controllen = len;
93424 msg.msg_flags = flags;
93425
93426diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
93427index 6e87f85..2c28e240 100644
93428--- a/net/ipv4/ip_vti.c
93429+++ b/net/ipv4/ip_vti.c
93430@@ -44,7 +44,7 @@
93431 #include <net/net_namespace.h>
93432 #include <net/netns/generic.h>
93433
93434-static struct rtnl_link_ops vti_link_ops __read_mostly;
93435+static struct rtnl_link_ops vti_link_ops;
93436
93437 static int vti_net_id __read_mostly;
93438 static int vti_tunnel_init(struct net_device *dev);
93439@@ -424,7 +424,7 @@ static const struct nla_policy vti_policy[IFLA_VTI_MAX + 1] = {
93440 [IFLA_VTI_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
93441 };
93442
93443-static struct rtnl_link_ops vti_link_ops __read_mostly = {
93444+static struct rtnl_link_ops vti_link_ops = {
93445 .kind = "vti",
93446 .maxtype = IFLA_VTI_MAX,
93447 .policy = vti_policy,
93448diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
93449index efa1138..20dbba0 100644
93450--- a/net/ipv4/ipconfig.c
93451+++ b/net/ipv4/ipconfig.c
93452@@ -334,7 +334,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
93453
93454 mm_segment_t oldfs = get_fs();
93455 set_fs(get_ds());
93456- res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
93457+ res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
93458 set_fs(oldfs);
93459 return res;
93460 }
93461@@ -345,7 +345,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
93462
93463 mm_segment_t oldfs = get_fs();
93464 set_fs(get_ds());
93465- res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
93466+ res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
93467 set_fs(oldfs);
93468 return res;
93469 }
93470@@ -356,7 +356,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
93471
93472 mm_segment_t oldfs = get_fs();
93473 set_fs(get_ds());
93474- res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
93475+ res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
93476 set_fs(oldfs);
93477 return res;
93478 }
93479diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
93480index 7f80fb4..b0328f6 100644
93481--- a/net/ipv4/ipip.c
93482+++ b/net/ipv4/ipip.c
93483@@ -124,7 +124,7 @@ MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
93484 static int ipip_net_id __read_mostly;
93485
93486 static int ipip_tunnel_init(struct net_device *dev);
93487-static struct rtnl_link_ops ipip_link_ops __read_mostly;
93488+static struct rtnl_link_ops ipip_link_ops;
93489
93490 static int ipip_err(struct sk_buff *skb, u32 info)
93491 {
93492@@ -408,7 +408,7 @@ static const struct nla_policy ipip_policy[IFLA_IPTUN_MAX + 1] = {
93493 [IFLA_IPTUN_PMTUDISC] = { .type = NLA_U8 },
93494 };
93495
93496-static struct rtnl_link_ops ipip_link_ops __read_mostly = {
93497+static struct rtnl_link_ops ipip_link_ops = {
93498 .kind = "ipip",
93499 .maxtype = IFLA_IPTUN_MAX,
93500 .policy = ipip_policy,
93501diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
93502index 85a4f21..1beb1f5 100644
93503--- a/net/ipv4/netfilter/arp_tables.c
93504+++ b/net/ipv4/netfilter/arp_tables.c
93505@@ -880,14 +880,14 @@ static int compat_table_info(const struct xt_table_info *info,
93506 #endif
93507
93508 static int get_info(struct net *net, void __user *user,
93509- const int *len, int compat)
93510+ int len, int compat)
93511 {
93512 char name[XT_TABLE_MAXNAMELEN];
93513 struct xt_table *t;
93514 int ret;
93515
93516- if (*len != sizeof(struct arpt_getinfo)) {
93517- duprintf("length %u != %Zu\n", *len,
93518+ if (len != sizeof(struct arpt_getinfo)) {
93519+ duprintf("length %u != %Zu\n", len,
93520 sizeof(struct arpt_getinfo));
93521 return -EINVAL;
93522 }
93523@@ -924,7 +924,7 @@ static int get_info(struct net *net, void __user *user,
93524 info.size = private->size;
93525 strcpy(info.name, name);
93526
93527- if (copy_to_user(user, &info, *len) != 0)
93528+ if (copy_to_user(user, &info, len) != 0)
93529 ret = -EFAULT;
93530 else
93531 ret = 0;
93532@@ -1683,7 +1683,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
93533
93534 switch (cmd) {
93535 case ARPT_SO_GET_INFO:
93536- ret = get_info(sock_net(sk), user, len, 1);
93537+ ret = get_info(sock_net(sk), user, *len, 1);
93538 break;
93539 case ARPT_SO_GET_ENTRIES:
93540 ret = compat_get_entries(sock_net(sk), user, len);
93541@@ -1728,7 +1728,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
93542
93543 switch (cmd) {
93544 case ARPT_SO_GET_INFO:
93545- ret = get_info(sock_net(sk), user, len, 0);
93546+ ret = get_info(sock_net(sk), user, *len, 0);
93547 break;
93548
93549 case ARPT_SO_GET_ENTRIES:
93550diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
93551index d23118d..6ad7277 100644
93552--- a/net/ipv4/netfilter/ip_tables.c
93553+++ b/net/ipv4/netfilter/ip_tables.c
93554@@ -1068,14 +1068,14 @@ static int compat_table_info(const struct xt_table_info *info,
93555 #endif
93556
93557 static int get_info(struct net *net, void __user *user,
93558- const int *len, int compat)
93559+ int len, int compat)
93560 {
93561 char name[XT_TABLE_MAXNAMELEN];
93562 struct xt_table *t;
93563 int ret;
93564
93565- if (*len != sizeof(struct ipt_getinfo)) {
93566- duprintf("length %u != %zu\n", *len,
93567+ if (len != sizeof(struct ipt_getinfo)) {
93568+ duprintf("length %u != %zu\n", len,
93569 sizeof(struct ipt_getinfo));
93570 return -EINVAL;
93571 }
93572@@ -1112,7 +1112,7 @@ static int get_info(struct net *net, void __user *user,
93573 info.size = private->size;
93574 strcpy(info.name, name);
93575
93576- if (copy_to_user(user, &info, *len) != 0)
93577+ if (copy_to_user(user, &info, len) != 0)
93578 ret = -EFAULT;
93579 else
93580 ret = 0;
93581@@ -1966,7 +1966,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
93582
93583 switch (cmd) {
93584 case IPT_SO_GET_INFO:
93585- ret = get_info(sock_net(sk), user, len, 1);
93586+ ret = get_info(sock_net(sk), user, *len, 1);
93587 break;
93588 case IPT_SO_GET_ENTRIES:
93589 ret = compat_get_entries(sock_net(sk), user, len);
93590@@ -2013,7 +2013,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
93591
93592 switch (cmd) {
93593 case IPT_SO_GET_INFO:
93594- ret = get_info(sock_net(sk), user, len, 0);
93595+ ret = get_info(sock_net(sk), user, *len, 0);
93596 break;
93597
93598 case IPT_SO_GET_ENTRIES:
93599diff --git a/net/ipv4/netfilter/ipt_ULOG.c b/net/ipv4/netfilter/ipt_ULOG.c
93600index cbc2215..9cb993c 100644
93601--- a/net/ipv4/netfilter/ipt_ULOG.c
93602+++ b/net/ipv4/netfilter/ipt_ULOG.c
93603@@ -220,6 +220,7 @@ static void ipt_ulog_packet(struct net *net,
93604 ub->qlen++;
93605
93606 pm = nlmsg_data(nlh);
93607+ memset(pm, 0, sizeof(*pm));
93608
93609 /* We might not have a timestamp, get one */
93610 if (skb->tstamp.tv64 == 0)
93611@@ -238,8 +239,6 @@ static void ipt_ulog_packet(struct net *net,
93612 }
93613 else if (loginfo->prefix[0] != '\0')
93614 strncpy(pm->prefix, loginfo->prefix, sizeof(pm->prefix));
93615- else
93616- *(pm->prefix) = '\0';
93617
93618 if (in && in->hard_header_len > 0 &&
93619 skb->mac_header != skb->network_header &&
93620@@ -251,13 +250,9 @@ static void ipt_ulog_packet(struct net *net,
93621
93622 if (in)
93623 strncpy(pm->indev_name, in->name, sizeof(pm->indev_name));
93624- else
93625- pm->indev_name[0] = '\0';
93626
93627 if (out)
93628 strncpy(pm->outdev_name, out->name, sizeof(pm->outdev_name));
93629- else
93630- pm->outdev_name[0] = '\0';
93631
93632 /* copy_len <= skb->len, so can't fail. */
93633 if (skb_copy_bits(skb, 0, pm->payload, copy_len) < 0)
93634diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
93635index d7d9882..d700c68 100644
93636--- a/net/ipv4/ping.c
93637+++ b/net/ipv4/ping.c
93638@@ -55,7 +55,7 @@
93639
93640
93641 struct ping_table ping_table;
93642-struct pingv6_ops pingv6_ops;
93643+struct pingv6_ops *pingv6_ops;
93644 EXPORT_SYMBOL_GPL(pingv6_ops);
93645
93646 static u16 ping_port_rover;
93647@@ -335,7 +335,7 @@ static int ping_check_bind_addr(struct sock *sk, struct inet_sock *isk,
93648 return -ENODEV;
93649 }
93650 }
93651- has_addr = pingv6_ops.ipv6_chk_addr(net, &addr->sin6_addr, dev,
93652+ has_addr = pingv6_ops->ipv6_chk_addr(net, &addr->sin6_addr, dev,
93653 scoped);
93654 rcu_read_unlock();
93655
93656@@ -541,7 +541,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
93657 }
93658 #if IS_ENABLED(CONFIG_IPV6)
93659 } else if (skb->protocol == htons(ETH_P_IPV6)) {
93660- harderr = pingv6_ops.icmpv6_err_convert(type, code, &err);
93661+ harderr = pingv6_ops->icmpv6_err_convert(type, code, &err);
93662 #endif
93663 }
93664
93665@@ -559,7 +559,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
93666 info, (u8 *)icmph);
93667 #if IS_ENABLED(CONFIG_IPV6)
93668 } else if (family == AF_INET6) {
93669- pingv6_ops.ipv6_icmp_error(sk, skb, err, 0,
93670+ pingv6_ops->ipv6_icmp_error(sk, skb, err, 0,
93671 info, (u8 *)icmph);
93672 #endif
93673 }
93674@@ -850,7 +850,7 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
93675 return ip_recv_error(sk, msg, len);
93676 #if IS_ENABLED(CONFIG_IPV6)
93677 } else if (family == AF_INET6) {
93678- return pingv6_ops.ipv6_recv_error(sk, msg, len);
93679+ return pingv6_ops->ipv6_recv_error(sk, msg, len);
93680 #endif
93681 }
93682 }
93683@@ -874,11 +874,14 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
93684
93685 /* Copy the address and add cmsg data. */
93686 if (family == AF_INET) {
93687- sin = (struct sockaddr_in *) msg->msg_name;
93688- sin->sin_family = AF_INET;
93689- sin->sin_port = 0 /* skb->h.uh->source */;
93690- sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
93691- memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
93692+ struct sockaddr_in *sin = (struct sockaddr_in *)msg->msg_name;
93693+
93694+ if (sin) {
93695+ sin->sin_family = AF_INET;
93696+ sin->sin_port = 0 /* skb->h.uh->source */;
93697+ sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
93698+ memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
93699+ }
93700
93701 if (isk->cmsg_flags)
93702 ip_cmsg_recv(msg, skb);
93703@@ -887,20 +890,23 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
93704 } else if (family == AF_INET6) {
93705 struct ipv6_pinfo *np = inet6_sk(sk);
93706 struct ipv6hdr *ip6 = ipv6_hdr(skb);
93707- sin6 = (struct sockaddr_in6 *) msg->msg_name;
93708- sin6->sin6_family = AF_INET6;
93709- sin6->sin6_port = 0;
93710- sin6->sin6_addr = ip6->saddr;
93711+ struct sockaddr_in6 *sin6 =
93712+ (struct sockaddr_in6 *)msg->msg_name;
93713
93714- sin6->sin6_flowinfo = 0;
93715- if (np->sndflow)
93716- sin6->sin6_flowinfo = ip6_flowinfo(ip6);
93717-
93718- sin6->sin6_scope_id = ipv6_iface_scope_id(&sin6->sin6_addr,
93719- IP6CB(skb)->iif);
93720+ if (sin6) {
93721+ sin6->sin6_family = AF_INET6;
93722+ sin6->sin6_port = 0;
93723+ sin6->sin6_addr = ip6->saddr;
93724+ sin6->sin6_flowinfo = 0;
93725+ if (np->sndflow)
93726+ sin6->sin6_flowinfo = ip6_flowinfo(ip6);
93727+ sin6->sin6_scope_id =
93728+ ipv6_iface_scope_id(&sin6->sin6_addr,
93729+ IP6CB(skb)->iif);
93730+ }
93731
93732 if (inet6_sk(sk)->rxopt.all)
93733- pingv6_ops.ip6_datagram_recv_ctl(sk, msg, skb);
93734+ pingv6_ops->ip6_datagram_recv_ctl(sk, msg, skb);
93735 #endif
93736 } else {
93737 BUG();
93738@@ -1090,7 +1096,7 @@ static void ping_v4_format_sock(struct sock *sp, struct seq_file *f,
93739 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
93740 0, sock_i_ino(sp),
93741 atomic_read(&sp->sk_refcnt), sp,
93742- atomic_read(&sp->sk_drops), len);
93743+ atomic_read_unchecked(&sp->sk_drops), len);
93744 }
93745
93746 static int ping_v4_seq_show(struct seq_file *seq, void *v)
93747diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
93748index 193db03..05ba36c 100644
93749--- a/net/ipv4/raw.c
93750+++ b/net/ipv4/raw.c
93751@@ -311,7 +311,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
93752 int raw_rcv(struct sock *sk, struct sk_buff *skb)
93753 {
93754 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
93755- atomic_inc(&sk->sk_drops);
93756+ atomic_inc_unchecked(&sk->sk_drops);
93757 kfree_skb(skb);
93758 return NET_RX_DROP;
93759 }
93760@@ -748,16 +748,20 @@ static int raw_init(struct sock *sk)
93761
93762 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
93763 {
93764+ struct icmp_filter filter;
93765+
93766 if (optlen > sizeof(struct icmp_filter))
93767 optlen = sizeof(struct icmp_filter);
93768- if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
93769+ if (copy_from_user(&filter, optval, optlen))
93770 return -EFAULT;
93771+ raw_sk(sk)->filter = filter;
93772 return 0;
93773 }
93774
93775 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
93776 {
93777 int len, ret = -EFAULT;
93778+ struct icmp_filter filter;
93779
93780 if (get_user(len, optlen))
93781 goto out;
93782@@ -767,8 +771,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
93783 if (len > sizeof(struct icmp_filter))
93784 len = sizeof(struct icmp_filter);
93785 ret = -EFAULT;
93786- if (put_user(len, optlen) ||
93787- copy_to_user(optval, &raw_sk(sk)->filter, len))
93788+ filter = raw_sk(sk)->filter;
93789+ if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
93790 goto out;
93791 ret = 0;
93792 out: return ret;
93793@@ -997,7 +1001,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
93794 0, 0L, 0,
93795 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
93796 0, sock_i_ino(sp),
93797- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
93798+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
93799 }
93800
93801 static int raw_seq_show(struct seq_file *seq, void *v)
93802diff --git a/net/ipv4/route.c b/net/ipv4/route.c
93803index 6011615..f418576 100644
93804--- a/net/ipv4/route.c
93805+++ b/net/ipv4/route.c
93806@@ -2613,34 +2613,34 @@ static struct ctl_table ipv4_route_flush_table[] = {
93807 .maxlen = sizeof(int),
93808 .mode = 0200,
93809 .proc_handler = ipv4_sysctl_rtcache_flush,
93810+ .extra1 = &init_net,
93811 },
93812 { },
93813 };
93814
93815 static __net_init int sysctl_route_net_init(struct net *net)
93816 {
93817- struct ctl_table *tbl;
93818+ ctl_table_no_const *tbl = NULL;
93819
93820- tbl = ipv4_route_flush_table;
93821 if (!net_eq(net, &init_net)) {
93822- tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
93823+ tbl = kmemdup(ipv4_route_flush_table, sizeof(ipv4_route_flush_table), GFP_KERNEL);
93824 if (tbl == NULL)
93825 goto err_dup;
93826
93827 /* Don't export sysctls to unprivileged users */
93828 if (net->user_ns != &init_user_ns)
93829 tbl[0].procname = NULL;
93830- }
93831- tbl[0].extra1 = net;
93832+ tbl[0].extra1 = net;
93833+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
93834+ } else
93835+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", ipv4_route_flush_table);
93836
93837- net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
93838 if (net->ipv4.route_hdr == NULL)
93839 goto err_reg;
93840 return 0;
93841
93842 err_reg:
93843- if (tbl != ipv4_route_flush_table)
93844- kfree(tbl);
93845+ kfree(tbl);
93846 err_dup:
93847 return -ENOMEM;
93848 }
93849@@ -2663,8 +2663,8 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
93850
93851 static __net_init int rt_genid_init(struct net *net)
93852 {
93853- atomic_set(&net->ipv4.rt_genid, 0);
93854- atomic_set(&net->fnhe_genid, 0);
93855+ atomic_set_unchecked(&net->ipv4.rt_genid, 0);
93856+ atomic_set_unchecked(&net->fnhe_genid, 0);
93857 get_random_bytes(&net->ipv4.dev_addr_genid,
93858 sizeof(net->ipv4.dev_addr_genid));
93859 return 0;
93860diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
93861index 540279f..9855b16 100644
93862--- a/net/ipv4/sysctl_net_ipv4.c
93863+++ b/net/ipv4/sysctl_net_ipv4.c
93864@@ -58,7 +58,7 @@ static int ipv4_local_port_range(struct ctl_table *table, int write,
93865 {
93866 int ret;
93867 int range[2];
93868- struct ctl_table tmp = {
93869+ ctl_table_no_const tmp = {
93870 .data = &range,
93871 .maxlen = sizeof(range),
93872 .mode = table->mode,
93873@@ -111,7 +111,7 @@ static int ipv4_ping_group_range(struct ctl_table *table, int write,
93874 int ret;
93875 gid_t urange[2];
93876 kgid_t low, high;
93877- struct ctl_table tmp = {
93878+ ctl_table_no_const tmp = {
93879 .data = &urange,
93880 .maxlen = sizeof(urange),
93881 .mode = table->mode,
93882@@ -142,7 +142,7 @@ static int proc_tcp_congestion_control(struct ctl_table *ctl, int write,
93883 void __user *buffer, size_t *lenp, loff_t *ppos)
93884 {
93885 char val[TCP_CA_NAME_MAX];
93886- struct ctl_table tbl = {
93887+ ctl_table_no_const tbl = {
93888 .data = val,
93889 .maxlen = TCP_CA_NAME_MAX,
93890 };
93891@@ -161,7 +161,7 @@ static int proc_tcp_available_congestion_control(struct ctl_table *ctl,
93892 void __user *buffer, size_t *lenp,
93893 loff_t *ppos)
93894 {
93895- struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
93896+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX, };
93897 int ret;
93898
93899 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
93900@@ -178,7 +178,7 @@ static int proc_allowed_congestion_control(struct ctl_table *ctl,
93901 void __user *buffer, size_t *lenp,
93902 loff_t *ppos)
93903 {
93904- struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
93905+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX };
93906 int ret;
93907
93908 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
93909@@ -204,15 +204,17 @@ static int ipv4_tcp_mem(struct ctl_table *ctl, int write,
93910 struct mem_cgroup *memcg;
93911 #endif
93912
93913- struct ctl_table tmp = {
93914+ ctl_table_no_const tmp = {
93915 .data = &vec,
93916 .maxlen = sizeof(vec),
93917 .mode = ctl->mode,
93918 };
93919
93920 if (!write) {
93921- ctl->data = &net->ipv4.sysctl_tcp_mem;
93922- return proc_doulongvec_minmax(ctl, write, buffer, lenp, ppos);
93923+ ctl_table_no_const tcp_mem = *ctl;
93924+
93925+ tcp_mem.data = &net->ipv4.sysctl_tcp_mem;
93926+ return proc_doulongvec_minmax(&tcp_mem, write, buffer, lenp, ppos);
93927 }
93928
93929 ret = proc_doulongvec_minmax(&tmp, write, buffer, lenp, ppos);
93930@@ -240,7 +242,7 @@ static int proc_tcp_fastopen_key(struct ctl_table *ctl, int write,
93931 void __user *buffer, size_t *lenp,
93932 loff_t *ppos)
93933 {
93934- struct ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
93935+ ctl_table_no_const tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
93936 struct tcp_fastopen_context *ctxt;
93937 int ret;
93938 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
93939@@ -483,7 +485,7 @@ static struct ctl_table ipv4_table[] = {
93940 },
93941 {
93942 .procname = "ip_local_reserved_ports",
93943- .data = NULL, /* initialized in sysctl_ipv4_init */
93944+ .data = sysctl_local_reserved_ports,
93945 .maxlen = 65536,
93946 .mode = 0644,
93947 .proc_handler = proc_do_large_bitmap,
93948@@ -864,11 +866,10 @@ static struct ctl_table ipv4_net_table[] = {
93949
93950 static __net_init int ipv4_sysctl_init_net(struct net *net)
93951 {
93952- struct ctl_table *table;
93953+ ctl_table_no_const *table = NULL;
93954
93955- table = ipv4_net_table;
93956 if (!net_eq(net, &init_net)) {
93957- table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
93958+ table = kmemdup(ipv4_net_table, sizeof(ipv4_net_table), GFP_KERNEL);
93959 if (table == NULL)
93960 goto err_alloc;
93961
93962@@ -903,15 +904,17 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
93963
93964 tcp_init_mem(net);
93965
93966- net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
93967+ if (!net_eq(net, &init_net))
93968+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
93969+ else
93970+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", ipv4_net_table);
93971 if (net->ipv4.ipv4_hdr == NULL)
93972 goto err_reg;
93973
93974 return 0;
93975
93976 err_reg:
93977- if (!net_eq(net, &init_net))
93978- kfree(table);
93979+ kfree(table);
93980 err_alloc:
93981 return -ENOMEM;
93982 }
93983@@ -933,16 +936,6 @@ static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
93984 static __init int sysctl_ipv4_init(void)
93985 {
93986 struct ctl_table_header *hdr;
93987- struct ctl_table *i;
93988-
93989- for (i = ipv4_table; i->procname; i++) {
93990- if (strcmp(i->procname, "ip_local_reserved_ports") == 0) {
93991- i->data = sysctl_local_reserved_ports;
93992- break;
93993- }
93994- }
93995- if (!i->procname)
93996- return -EINVAL;
93997
93998 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
93999 if (hdr == NULL)
94000diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
94001index 068c8fb..a755c52 100644
94002--- a/net/ipv4/tcp_input.c
94003+++ b/net/ipv4/tcp_input.c
94004@@ -4435,7 +4435,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
94005 * simplifies code)
94006 */
94007 static void
94008-tcp_collapse(struct sock *sk, struct sk_buff_head *list,
94009+__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
94010 struct sk_buff *head, struct sk_buff *tail,
94011 u32 start, u32 end)
94012 {
94013@@ -5520,6 +5520,7 @@ discard:
94014 tcp_paws_reject(&tp->rx_opt, 0))
94015 goto discard_and_undo;
94016
94017+#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
94018 if (th->syn) {
94019 /* We see SYN without ACK. It is attempt of
94020 * simultaneous connect with crossed SYNs.
94021@@ -5570,6 +5571,7 @@ discard:
94022 goto discard;
94023 #endif
94024 }
94025+#endif
94026 /* "fifth, if neither of the SYN or RST bits is set then
94027 * drop the segment and return."
94028 */
94029@@ -5616,7 +5618,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
94030 goto discard;
94031
94032 if (th->syn) {
94033- if (th->fin)
94034+ if (th->fin || th->urg || th->psh)
94035 goto discard;
94036 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
94037 return 1;
94038diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
94039index b14266b..c5fe725 100644
94040--- a/net/ipv4/tcp_ipv4.c
94041+++ b/net/ipv4/tcp_ipv4.c
94042@@ -91,6 +91,10 @@ int sysctl_tcp_low_latency __read_mostly;
94043 EXPORT_SYMBOL(sysctl_tcp_low_latency);
94044
94045
94046+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
94047+extern int grsec_enable_blackhole;
94048+#endif
94049+
94050 #ifdef CONFIG_TCP_MD5SIG
94051 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
94052 __be32 daddr, __be32 saddr, const struct tcphdr *th);
94053@@ -1829,6 +1833,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
94054 return 0;
94055
94056 reset:
94057+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
94058+ if (!grsec_enable_blackhole)
94059+#endif
94060 tcp_v4_send_reset(rsk, skb);
94061 discard:
94062 kfree_skb(skb);
94063@@ -1974,12 +1981,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
94064 TCP_SKB_CB(skb)->sacked = 0;
94065
94066 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
94067- if (!sk)
94068+ if (!sk) {
94069+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
94070+ ret = 1;
94071+#endif
94072 goto no_tcp_socket;
94073-
94074+ }
94075 process:
94076- if (sk->sk_state == TCP_TIME_WAIT)
94077+ if (sk->sk_state == TCP_TIME_WAIT) {
94078+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
94079+ ret = 2;
94080+#endif
94081 goto do_time_wait;
94082+ }
94083
94084 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
94085 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
94086@@ -2033,6 +2047,10 @@ csum_error:
94087 bad_packet:
94088 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
94089 } else {
94090+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
94091+ if (!grsec_enable_blackhole || (ret == 1 &&
94092+ (skb->dev->flags & IFF_LOOPBACK)))
94093+#endif
94094 tcp_v4_send_reset(NULL, skb);
94095 }
94096
94097diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
94098index 58a3e69..7f0626e 100644
94099--- a/net/ipv4/tcp_minisocks.c
94100+++ b/net/ipv4/tcp_minisocks.c
94101@@ -27,6 +27,10 @@
94102 #include <net/inet_common.h>
94103 #include <net/xfrm.h>
94104
94105+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
94106+extern int grsec_enable_blackhole;
94107+#endif
94108+
94109 int sysctl_tcp_syncookies __read_mostly = 1;
94110 EXPORT_SYMBOL(sysctl_tcp_syncookies);
94111
94112@@ -711,7 +715,10 @@ embryonic_reset:
94113 * avoid becoming vulnerable to outside attack aiming at
94114 * resetting legit local connections.
94115 */
94116- req->rsk_ops->send_reset(sk, skb);
94117+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
94118+ if (!grsec_enable_blackhole)
94119+#endif
94120+ req->rsk_ops->send_reset(sk, skb);
94121 } else if (fastopen) { /* received a valid RST pkt */
94122 reqsk_fastopen_remove(sk, req, true);
94123 tcp_reset(sk);
94124diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
94125index 611beab..c4b6e1d 100644
94126--- a/net/ipv4/tcp_probe.c
94127+++ b/net/ipv4/tcp_probe.c
94128@@ -245,7 +245,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
94129 if (cnt + width >= len)
94130 break;
94131
94132- if (copy_to_user(buf + cnt, tbuf, width))
94133+ if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
94134 return -EFAULT;
94135 cnt += width;
94136 }
94137diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
94138index 4b85e6f..22f9ac9 100644
94139--- a/net/ipv4/tcp_timer.c
94140+++ b/net/ipv4/tcp_timer.c
94141@@ -22,6 +22,10 @@
94142 #include <linux/gfp.h>
94143 #include <net/tcp.h>
94144
94145+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
94146+extern int grsec_lastack_retries;
94147+#endif
94148+
94149 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
94150 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
94151 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
94152@@ -185,6 +189,13 @@ static int tcp_write_timeout(struct sock *sk)
94153 }
94154 }
94155
94156+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
94157+ if ((sk->sk_state == TCP_LAST_ACK) &&
94158+ (grsec_lastack_retries > 0) &&
94159+ (grsec_lastack_retries < retry_until))
94160+ retry_until = grsec_lastack_retries;
94161+#endif
94162+
94163 if (retransmits_timed_out(sk, retry_until,
94164 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
94165 /* Has it gone just too far? */
94166diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
94167index 0ca44df..b5e4b11 100644
94168--- a/net/ipv4/udp.c
94169+++ b/net/ipv4/udp.c
94170@@ -87,6 +87,7 @@
94171 #include <linux/types.h>
94172 #include <linux/fcntl.h>
94173 #include <linux/module.h>
94174+#include <linux/security.h>
94175 #include <linux/socket.h>
94176 #include <linux/sockios.h>
94177 #include <linux/igmp.h>
94178@@ -112,6 +113,10 @@
94179 #include <net/busy_poll.h>
94180 #include "udp_impl.h"
94181
94182+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
94183+extern int grsec_enable_blackhole;
94184+#endif
94185+
94186 struct udp_table udp_table __read_mostly;
94187 EXPORT_SYMBOL(udp_table);
94188
94189@@ -595,6 +600,9 @@ found:
94190 return s;
94191 }
94192
94193+extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
94194+extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
94195+
94196 /*
94197 * This routine is called by the ICMP module when it gets some
94198 * sort of error condition. If err < 0 then the socket should
94199@@ -892,9 +900,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
94200 dport = usin->sin_port;
94201 if (dport == 0)
94202 return -EINVAL;
94203+
94204+ err = gr_search_udp_sendmsg(sk, usin);
94205+ if (err)
94206+ return err;
94207 } else {
94208 if (sk->sk_state != TCP_ESTABLISHED)
94209 return -EDESTADDRREQ;
94210+
94211+ err = gr_search_udp_sendmsg(sk, NULL);
94212+ if (err)
94213+ return err;
94214+
94215 daddr = inet->inet_daddr;
94216 dport = inet->inet_dport;
94217 /* Open fast path for connected socket.
94218@@ -1138,7 +1155,7 @@ static unsigned int first_packet_length(struct sock *sk)
94219 IS_UDPLITE(sk));
94220 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
94221 IS_UDPLITE(sk));
94222- atomic_inc(&sk->sk_drops);
94223+ atomic_inc_unchecked(&sk->sk_drops);
94224 __skb_unlink(skb, rcvq);
94225 __skb_queue_tail(&list_kill, skb);
94226 }
94227@@ -1224,6 +1241,10 @@ try_again:
94228 if (!skb)
94229 goto out;
94230
94231+ err = gr_search_udp_recvmsg(sk, skb);
94232+ if (err)
94233+ goto out_free;
94234+
94235 ulen = skb->len - sizeof(struct udphdr);
94236 copied = len;
94237 if (copied > ulen)
94238@@ -1257,7 +1278,7 @@ try_again:
94239 if (unlikely(err)) {
94240 trace_kfree_skb(skb, udp_recvmsg);
94241 if (!peeked) {
94242- atomic_inc(&sk->sk_drops);
94243+ atomic_inc_unchecked(&sk->sk_drops);
94244 UDP_INC_STATS_USER(sock_net(sk),
94245 UDP_MIB_INERRORS, is_udplite);
94246 }
94247@@ -1544,7 +1565,7 @@ csum_error:
94248 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
94249 drop:
94250 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
94251- atomic_inc(&sk->sk_drops);
94252+ atomic_inc_unchecked(&sk->sk_drops);
94253 kfree_skb(skb);
94254 return -1;
94255 }
94256@@ -1563,7 +1584,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
94257 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
94258
94259 if (!skb1) {
94260- atomic_inc(&sk->sk_drops);
94261+ atomic_inc_unchecked(&sk->sk_drops);
94262 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
94263 IS_UDPLITE(sk));
94264 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
94265@@ -1735,6 +1756,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
94266 goto csum_error;
94267
94268 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
94269+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
94270+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
94271+#endif
94272 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
94273
94274 /*
94275@@ -2167,7 +2191,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
94276 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
94277 0, sock_i_ino(sp),
94278 atomic_read(&sp->sk_refcnt), sp,
94279- atomic_read(&sp->sk_drops), len);
94280+ atomic_read_unchecked(&sp->sk_drops), len);
94281 }
94282
94283 int udp4_seq_show(struct seq_file *seq, void *v)
94284diff --git a/net/ipv4/xfrm4_policy.c b/net/ipv4/xfrm4_policy.c
94285index ccde542..eeb5ff7 100644
94286--- a/net/ipv4/xfrm4_policy.c
94287+++ b/net/ipv4/xfrm4_policy.c
94288@@ -182,11 +182,11 @@ _decode_session4(struct sk_buff *skb, struct flowi *fl, int reverse)
94289 fl4->flowi4_tos = iph->tos;
94290 }
94291
94292-static inline int xfrm4_garbage_collect(struct dst_ops *ops)
94293+static int xfrm4_garbage_collect(struct dst_ops *ops)
94294 {
94295 struct net *net = container_of(ops, struct net, xfrm.xfrm4_dst_ops);
94296
94297- xfrm4_policy_afinfo.garbage_collect(net);
94298+ xfrm_garbage_collect_deferred(net);
94299 return (dst_entries_get_slow(ops) > ops->gc_thresh * 2);
94300 }
94301
94302@@ -265,19 +265,18 @@ static struct ctl_table xfrm4_policy_table[] = {
94303
94304 static int __net_init xfrm4_net_init(struct net *net)
94305 {
94306- struct ctl_table *table;
94307+ ctl_table_no_const *table = NULL;
94308 struct ctl_table_header *hdr;
94309
94310- table = xfrm4_policy_table;
94311 if (!net_eq(net, &init_net)) {
94312- table = kmemdup(table, sizeof(xfrm4_policy_table), GFP_KERNEL);
94313+ table = kmemdup(xfrm4_policy_table, sizeof(xfrm4_policy_table), GFP_KERNEL);
94314 if (!table)
94315 goto err_alloc;
94316
94317 table[0].data = &net->xfrm.xfrm4_dst_ops.gc_thresh;
94318- }
94319-
94320- hdr = register_net_sysctl(net, "net/ipv4", table);
94321+ hdr = register_net_sysctl(net, "net/ipv4", table);
94322+ } else
94323+ hdr = register_net_sysctl(net, "net/ipv4", xfrm4_policy_table);
94324 if (!hdr)
94325 goto err_reg;
94326
94327@@ -285,8 +284,7 @@ static int __net_init xfrm4_net_init(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/ipv6/addrconf.c b/net/ipv6/addrconf.c
94338index cd3fb30..b7dfef7 100644
94339--- a/net/ipv6/addrconf.c
94340+++ b/net/ipv6/addrconf.c
94341@@ -586,7 +586,7 @@ static int inet6_netconf_dump_devconf(struct sk_buff *skb,
94342 idx = 0;
94343 head = &net->dev_index_head[h];
94344 rcu_read_lock();
94345- cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^
94346+ cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^
94347 net->dev_base_seq;
94348 hlist_for_each_entry_rcu(dev, head, index_hlist) {
94349 if (idx < s_idx)
94350@@ -2364,7 +2364,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
94351 p.iph.ihl = 5;
94352 p.iph.protocol = IPPROTO_IPV6;
94353 p.iph.ttl = 64;
94354- ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
94355+ ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
94356
94357 if (ops->ndo_do_ioctl) {
94358 mm_segment_t oldfs = get_fs();
94359@@ -3977,7 +3977,7 @@ static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
94360 s_ip_idx = ip_idx = cb->args[2];
94361
94362 rcu_read_lock();
94363- cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
94364+ cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
94365 for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
94366 idx = 0;
94367 head = &net->dev_index_head[h];
94368@@ -4603,7 +4603,7 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
94369 dst_free(&ifp->rt->dst);
94370 break;
94371 }
94372- atomic_inc(&net->ipv6.dev_addr_genid);
94373+ atomic_inc_unchecked(&net->ipv6.dev_addr_genid);
94374 rt_genid_bump_ipv6(net);
94375 }
94376
94377@@ -4624,7 +4624,7 @@ int addrconf_sysctl_forward(struct ctl_table *ctl, int write,
94378 int *valp = ctl->data;
94379 int val = *valp;
94380 loff_t pos = *ppos;
94381- struct ctl_table lctl;
94382+ ctl_table_no_const lctl;
94383 int ret;
94384
94385 /*
94386@@ -4709,7 +4709,7 @@ int addrconf_sysctl_disable(struct ctl_table *ctl, int write,
94387 int *valp = ctl->data;
94388 int val = *valp;
94389 loff_t pos = *ppos;
94390- struct ctl_table lctl;
94391+ ctl_table_no_const lctl;
94392 int ret;
94393
94394 /*
94395diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c
94396index 7c96100..bfd994a 100644
94397--- a/net/ipv6/af_inet6.c
94398+++ b/net/ipv6/af_inet6.c
94399@@ -767,7 +767,7 @@ static int __net_init inet6_net_init(struct net *net)
94400
94401 net->ipv6.sysctl.bindv6only = 0;
94402 net->ipv6.sysctl.icmpv6_time = 1*HZ;
94403- atomic_set(&net->ipv6.rt_genid, 0);
94404+ atomic_set_unchecked(&net->ipv6.rt_genid, 0);
94405
94406 err = ipv6_init_mibs(net);
94407 if (err)
94408diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c
94409index 48b6bd2..76d3458 100644
94410--- a/net/ipv6/datagram.c
94411+++ b/net/ipv6/datagram.c
94412@@ -904,5 +904,5 @@ void ip6_dgram_sock_seq_show(struct seq_file *seq, struct sock *sp,
94413 0,
94414 sock_i_ino(sp),
94415 atomic_read(&sp->sk_refcnt), sp,
94416- atomic_read(&sp->sk_drops));
94417+ atomic_read_unchecked(&sp->sk_drops));
94418 }
94419diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
94420index eef8d94..cfa1852 100644
94421--- a/net/ipv6/icmp.c
94422+++ b/net/ipv6/icmp.c
94423@@ -997,7 +997,7 @@ struct ctl_table ipv6_icmp_table_template[] = {
94424
94425 struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
94426 {
94427- struct ctl_table *table;
94428+ ctl_table_no_const *table;
94429
94430 table = kmemdup(ipv6_icmp_table_template,
94431 sizeof(ipv6_icmp_table_template),
94432diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
94433index bf4a9a0..e5f6ac5 100644
94434--- a/net/ipv6/ip6_gre.c
94435+++ b/net/ipv6/ip6_gre.c
94436@@ -74,7 +74,7 @@ struct ip6gre_net {
94437 struct net_device *fb_tunnel_dev;
94438 };
94439
94440-static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
94441+static struct rtnl_link_ops ip6gre_link_ops;
94442 static int ip6gre_tunnel_init(struct net_device *dev);
94443 static void ip6gre_tunnel_setup(struct net_device *dev);
94444 static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
94445@@ -1286,7 +1286,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
94446 }
94447
94448
94449-static struct inet6_protocol ip6gre_protocol __read_mostly = {
94450+static struct inet6_protocol ip6gre_protocol = {
94451 .handler = ip6gre_rcv,
94452 .err_handler = ip6gre_err,
94453 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
94454@@ -1622,7 +1622,7 @@ static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
94455 [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
94456 };
94457
94458-static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
94459+static struct rtnl_link_ops ip6gre_link_ops = {
94460 .kind = "ip6gre",
94461 .maxtype = IFLA_GRE_MAX,
94462 .policy = ip6gre_policy,
94463@@ -1635,7 +1635,7 @@ static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
94464 .fill_info = ip6gre_fill_info,
94465 };
94466
94467-static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
94468+static struct rtnl_link_ops ip6gre_tap_ops = {
94469 .kind = "ip6gretap",
94470 .maxtype = IFLA_GRE_MAX,
94471 .policy = ip6gre_policy,
94472diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
94473index 583b77e..99522b8 100644
94474--- a/net/ipv6/ip6_tunnel.c
94475+++ b/net/ipv6/ip6_tunnel.c
94476@@ -89,7 +89,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
94477
94478 static int ip6_tnl_dev_init(struct net_device *dev);
94479 static void ip6_tnl_dev_setup(struct net_device *dev);
94480-static struct rtnl_link_ops ip6_link_ops __read_mostly;
94481+static struct rtnl_link_ops ip6_link_ops;
94482
94483 static int ip6_tnl_net_id __read_mostly;
94484 struct ip6_tnl_net {
94485@@ -1690,7 +1690,7 @@ static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
94486 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
94487 };
94488
94489-static struct rtnl_link_ops ip6_link_ops __read_mostly = {
94490+static struct rtnl_link_ops ip6_link_ops = {
94491 .kind = "ip6tnl",
94492 .maxtype = IFLA_IPTUN_MAX,
94493 .policy = ip6_tnl_policy,
94494diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
94495index d1e2e8e..51c19ae 100644
94496--- a/net/ipv6/ipv6_sockglue.c
94497+++ b/net/ipv6/ipv6_sockglue.c
94498@@ -991,7 +991,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
94499 if (sk->sk_type != SOCK_STREAM)
94500 return -ENOPROTOOPT;
94501
94502- msg.msg_control = optval;
94503+ msg.msg_control = (void __force_kernel *)optval;
94504 msg.msg_controllen = len;
94505 msg.msg_flags = flags;
94506
94507diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
94508index 44400c2..8e11f52 100644
94509--- a/net/ipv6/netfilter/ip6_tables.c
94510+++ b/net/ipv6/netfilter/ip6_tables.c
94511@@ -1078,14 +1078,14 @@ static int compat_table_info(const struct xt_table_info *info,
94512 #endif
94513
94514 static int get_info(struct net *net, void __user *user,
94515- const int *len, int compat)
94516+ int len, int compat)
94517 {
94518 char name[XT_TABLE_MAXNAMELEN];
94519 struct xt_table *t;
94520 int ret;
94521
94522- if (*len != sizeof(struct ip6t_getinfo)) {
94523- duprintf("length %u != %zu\n", *len,
94524+ if (len != sizeof(struct ip6t_getinfo)) {
94525+ duprintf("length %u != %zu\n", len,
94526 sizeof(struct ip6t_getinfo));
94527 return -EINVAL;
94528 }
94529@@ -1122,7 +1122,7 @@ static int get_info(struct net *net, void __user *user,
94530 info.size = private->size;
94531 strcpy(info.name, name);
94532
94533- if (copy_to_user(user, &info, *len) != 0)
94534+ if (copy_to_user(user, &info, len) != 0)
94535 ret = -EFAULT;
94536 else
94537 ret = 0;
94538@@ -1976,7 +1976,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
94539
94540 switch (cmd) {
94541 case IP6T_SO_GET_INFO:
94542- ret = get_info(sock_net(sk), user, len, 1);
94543+ ret = get_info(sock_net(sk), user, *len, 1);
94544 break;
94545 case IP6T_SO_GET_ENTRIES:
94546 ret = compat_get_entries(sock_net(sk), user, len);
94547@@ -2023,7 +2023,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
94548
94549 switch (cmd) {
94550 case IP6T_SO_GET_INFO:
94551- ret = get_info(sock_net(sk), user, len, 0);
94552+ ret = get_info(sock_net(sk), user, *len, 0);
94553 break;
94554
94555 case IP6T_SO_GET_ENTRIES:
94556diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
94557index dffdc1a..ccc6678 100644
94558--- a/net/ipv6/netfilter/nf_conntrack_reasm.c
94559+++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
94560@@ -90,12 +90,11 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = {
94561
94562 static int nf_ct_frag6_sysctl_register(struct net *net)
94563 {
94564- struct ctl_table *table;
94565+ ctl_table_no_const *table = NULL;
94566 struct ctl_table_header *hdr;
94567
94568- table = nf_ct_frag6_sysctl_table;
94569 if (!net_eq(net, &init_net)) {
94570- table = kmemdup(table, sizeof(nf_ct_frag6_sysctl_table),
94571+ table = kmemdup(nf_ct_frag6_sysctl_table, sizeof(nf_ct_frag6_sysctl_table),
94572 GFP_KERNEL);
94573 if (table == NULL)
94574 goto err_alloc;
94575@@ -103,9 +102,9 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
94576 table[0].data = &net->nf_frag.frags.timeout;
94577 table[1].data = &net->nf_frag.frags.low_thresh;
94578 table[2].data = &net->nf_frag.frags.high_thresh;
94579- }
94580-
94581- hdr = register_net_sysctl(net, "net/netfilter", table);
94582+ hdr = register_net_sysctl(net, "net/netfilter", table);
94583+ } else
94584+ hdr = register_net_sysctl(net, "net/netfilter", nf_ct_frag6_sysctl_table);
94585 if (hdr == NULL)
94586 goto err_reg;
94587
94588@@ -113,8 +112,7 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
94589 return 0;
94590
94591 err_reg:
94592- if (!net_eq(net, &init_net))
94593- kfree(table);
94594+ kfree(table);
94595 err_alloc:
94596 return -ENOMEM;
94597 }
94598diff --git a/net/ipv6/output_core.c b/net/ipv6/output_core.c
94599index 827f795..7e28e82 100644
94600--- a/net/ipv6/output_core.c
94601+++ b/net/ipv6/output_core.c
94602@@ -9,8 +9,8 @@
94603
94604 void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
94605 {
94606- static atomic_t ipv6_fragmentation_id;
94607- int old, new;
94608+ static atomic_unchecked_t ipv6_fragmentation_id;
94609+ int id;
94610
94611 #if IS_ENABLED(CONFIG_IPV6)
94612 if (rt && !(rt->dst.flags & DST_NOPEER)) {
94613@@ -26,13 +26,10 @@ void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
94614 }
94615 }
94616 #endif
94617- do {
94618- old = atomic_read(&ipv6_fragmentation_id);
94619- new = old + 1;
94620- if (!new)
94621- new = 1;
94622- } while (atomic_cmpxchg(&ipv6_fragmentation_id, old, new) != old);
94623- fhdr->identification = htonl(new);
94624+ id = atomic_inc_return_unchecked(&ipv6_fragmentation_id);
94625+ if (!id)
94626+ id = atomic_inc_return_unchecked(&ipv6_fragmentation_id);
94627+ fhdr->identification = htonl(id);
94628 }
94629 EXPORT_SYMBOL(ipv6_select_ident);
94630
94631diff --git a/net/ipv6/ping.c b/net/ipv6/ping.c
94632index 18f19df..b46ada1 100644
94633--- a/net/ipv6/ping.c
94634+++ b/net/ipv6/ping.c
94635@@ -245,6 +245,22 @@ static struct pernet_operations ping_v6_net_ops = {
94636 };
94637 #endif
94638
94639+static struct pingv6_ops real_pingv6_ops = {
94640+ .ipv6_recv_error = ipv6_recv_error,
94641+ .ip6_datagram_recv_ctl = ip6_datagram_recv_ctl,
94642+ .icmpv6_err_convert = icmpv6_err_convert,
94643+ .ipv6_icmp_error = ipv6_icmp_error,
94644+ .ipv6_chk_addr = ipv6_chk_addr,
94645+};
94646+
94647+static struct pingv6_ops dummy_pingv6_ops = {
94648+ .ipv6_recv_error = dummy_ipv6_recv_error,
94649+ .ip6_datagram_recv_ctl = dummy_ip6_datagram_recv_ctl,
94650+ .icmpv6_err_convert = dummy_icmpv6_err_convert,
94651+ .ipv6_icmp_error = dummy_ipv6_icmp_error,
94652+ .ipv6_chk_addr = dummy_ipv6_chk_addr,
94653+};
94654+
94655 int __init pingv6_init(void)
94656 {
94657 #ifdef CONFIG_PROC_FS
94658@@ -252,11 +268,7 @@ int __init pingv6_init(void)
94659 if (ret)
94660 return ret;
94661 #endif
94662- pingv6_ops.ipv6_recv_error = ipv6_recv_error;
94663- pingv6_ops.ip6_datagram_recv_ctl = ip6_datagram_recv_ctl;
94664- pingv6_ops.icmpv6_err_convert = icmpv6_err_convert;
94665- pingv6_ops.ipv6_icmp_error = ipv6_icmp_error;
94666- pingv6_ops.ipv6_chk_addr = ipv6_chk_addr;
94667+ pingv6_ops = &real_pingv6_ops;
94668 return inet6_register_protosw(&pingv6_protosw);
94669 }
94670
94671@@ -265,11 +277,7 @@ int __init pingv6_init(void)
94672 */
94673 void pingv6_exit(void)
94674 {
94675- pingv6_ops.ipv6_recv_error = dummy_ipv6_recv_error;
94676- pingv6_ops.ip6_datagram_recv_ctl = dummy_ip6_datagram_recv_ctl;
94677- pingv6_ops.icmpv6_err_convert = dummy_icmpv6_err_convert;
94678- pingv6_ops.ipv6_icmp_error = dummy_ipv6_icmp_error;
94679- pingv6_ops.ipv6_chk_addr = dummy_ipv6_chk_addr;
94680+ pingv6_ops = &dummy_pingv6_ops;
94681 #ifdef CONFIG_PROC_FS
94682 unregister_pernet_subsys(&ping_v6_net_ops);
94683 #endif
94684diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
94685index a4ed241..8bf6277 100644
94686--- a/net/ipv6/raw.c
94687+++ b/net/ipv6/raw.c
94688@@ -385,7 +385,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
94689 {
94690 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
94691 skb_checksum_complete(skb)) {
94692- atomic_inc(&sk->sk_drops);
94693+ atomic_inc_unchecked(&sk->sk_drops);
94694 kfree_skb(skb);
94695 return NET_RX_DROP;
94696 }
94697@@ -413,7 +413,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
94698 struct raw6_sock *rp = raw6_sk(sk);
94699
94700 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
94701- atomic_inc(&sk->sk_drops);
94702+ atomic_inc_unchecked(&sk->sk_drops);
94703 kfree_skb(skb);
94704 return NET_RX_DROP;
94705 }
94706@@ -437,7 +437,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
94707
94708 if (inet->hdrincl) {
94709 if (skb_checksum_complete(skb)) {
94710- atomic_inc(&sk->sk_drops);
94711+ atomic_inc_unchecked(&sk->sk_drops);
94712 kfree_skb(skb);
94713 return NET_RX_DROP;
94714 }
94715@@ -609,7 +609,7 @@ out:
94716 return err;
94717 }
94718
94719-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
94720+static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
94721 struct flowi6 *fl6, struct dst_entry **dstp,
94722 unsigned int flags)
94723 {
94724@@ -922,12 +922,15 @@ do_confirm:
94725 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
94726 char __user *optval, int optlen)
94727 {
94728+ struct icmp6_filter filter;
94729+
94730 switch (optname) {
94731 case ICMPV6_FILTER:
94732 if (optlen > sizeof(struct icmp6_filter))
94733 optlen = sizeof(struct icmp6_filter);
94734- if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
94735+ if (copy_from_user(&filter, optval, optlen))
94736 return -EFAULT;
94737+ raw6_sk(sk)->filter = filter;
94738 return 0;
94739 default:
94740 return -ENOPROTOOPT;
94741@@ -940,6 +943,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
94742 char __user *optval, int __user *optlen)
94743 {
94744 int len;
94745+ struct icmp6_filter filter;
94746
94747 switch (optname) {
94748 case ICMPV6_FILTER:
94749@@ -951,7 +955,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
94750 len = sizeof(struct icmp6_filter);
94751 if (put_user(len, optlen))
94752 return -EFAULT;
94753- if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
94754+ filter = raw6_sk(sk)->filter;
94755+ if (len > sizeof filter || copy_to_user(optval, &filter, len))
94756 return -EFAULT;
94757 return 0;
94758 default:
94759diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
94760index 1aeb473..bea761c 100644
94761--- a/net/ipv6/reassembly.c
94762+++ b/net/ipv6/reassembly.c
94763@@ -626,12 +626,11 @@ static struct ctl_table ip6_frags_ctl_table[] = {
94764
94765 static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
94766 {
94767- struct ctl_table *table;
94768+ ctl_table_no_const *table = NULL;
94769 struct ctl_table_header *hdr;
94770
94771- table = ip6_frags_ns_ctl_table;
94772 if (!net_eq(net, &init_net)) {
94773- table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
94774+ table = kmemdup(ip6_frags_ns_ctl_table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
94775 if (table == NULL)
94776 goto err_alloc;
94777
94778@@ -642,9 +641,10 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
94779 /* Don't export sysctls to unprivileged users */
94780 if (net->user_ns != &init_user_ns)
94781 table[0].procname = NULL;
94782- }
94783+ hdr = register_net_sysctl(net, "net/ipv6", table);
94784+ } else
94785+ hdr = register_net_sysctl(net, "net/ipv6", ip6_frags_ns_ctl_table);
94786
94787- hdr = register_net_sysctl(net, "net/ipv6", table);
94788 if (hdr == NULL)
94789 goto err_reg;
94790
94791@@ -652,8 +652,7 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
94792 return 0;
94793
94794 err_reg:
94795- if (!net_eq(net, &init_net))
94796- kfree(table);
94797+ kfree(table);
94798 err_alloc:
94799 return -ENOMEM;
94800 }
94801diff --git a/net/ipv6/route.c b/net/ipv6/route.c
94802index 04e17b3..83502e9 100644
94803--- a/net/ipv6/route.c
94804+++ b/net/ipv6/route.c
94805@@ -3006,7 +3006,7 @@ struct ctl_table ipv6_route_table_template[] = {
94806
94807 struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
94808 {
94809- struct ctl_table *table;
94810+ ctl_table_no_const *table;
94811
94812 table = kmemdup(ipv6_route_table_template,
94813 sizeof(ipv6_route_table_template),
94814diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
94815index 1926945..30a1a57 100644
94816--- a/net/ipv6/sit.c
94817+++ b/net/ipv6/sit.c
94818@@ -74,7 +74,7 @@ static void ipip6_tunnel_setup(struct net_device *dev);
94819 static void ipip6_dev_free(struct net_device *dev);
94820 static bool check_6rd(struct ip_tunnel *tunnel, const struct in6_addr *v6dst,
94821 __be32 *v4dst);
94822-static struct rtnl_link_ops sit_link_ops __read_mostly;
94823+static struct rtnl_link_ops sit_link_ops;
94824
94825 static int sit_net_id __read_mostly;
94826 struct sit_net {
94827@@ -1594,7 +1594,7 @@ static const struct nla_policy ipip6_policy[IFLA_IPTUN_MAX + 1] = {
94828 #endif
94829 };
94830
94831-static struct rtnl_link_ops sit_link_ops __read_mostly = {
94832+static struct rtnl_link_ops sit_link_ops = {
94833 .kind = "sit",
94834 .maxtype = IFLA_IPTUN_MAX,
94835 .policy = ipip6_policy,
94836diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
94837index 107b2f1..72741a9 100644
94838--- a/net/ipv6/sysctl_net_ipv6.c
94839+++ b/net/ipv6/sysctl_net_ipv6.c
94840@@ -40,7 +40,7 @@ static struct ctl_table ipv6_rotable[] = {
94841
94842 static int __net_init ipv6_sysctl_net_init(struct net *net)
94843 {
94844- struct ctl_table *ipv6_table;
94845+ ctl_table_no_const *ipv6_table;
94846 struct ctl_table *ipv6_route_table;
94847 struct ctl_table *ipv6_icmp_table;
94848 int err;
94849diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
94850index 5c71501..7e8d5d3 100644
94851--- a/net/ipv6/tcp_ipv6.c
94852+++ b/net/ipv6/tcp_ipv6.c
94853@@ -104,6 +104,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
94854 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
94855 }
94856
94857+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
94858+extern int grsec_enable_blackhole;
94859+#endif
94860+
94861 static void tcp_v6_hash(struct sock *sk)
94862 {
94863 if (sk->sk_state != TCP_CLOSE) {
94864@@ -1397,6 +1401,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
94865 return 0;
94866
94867 reset:
94868+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
94869+ if (!grsec_enable_blackhole)
94870+#endif
94871 tcp_v6_send_reset(sk, skb);
94872 discard:
94873 if (opt_skb)
94874@@ -1479,12 +1486,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
94875 TCP_SKB_CB(skb)->sacked = 0;
94876
94877 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
94878- if (!sk)
94879+ if (!sk) {
94880+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
94881+ ret = 1;
94882+#endif
94883 goto no_tcp_socket;
94884+ }
94885
94886 process:
94887- if (sk->sk_state == TCP_TIME_WAIT)
94888+ if (sk->sk_state == TCP_TIME_WAIT) {
94889+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
94890+ ret = 2;
94891+#endif
94892 goto do_time_wait;
94893+ }
94894
94895 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
94896 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
94897@@ -1536,6 +1551,10 @@ csum_error:
94898 bad_packet:
94899 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
94900 } else {
94901+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
94902+ if (!grsec_enable_blackhole || (ret == 1 &&
94903+ (skb->dev->flags & IFF_LOOPBACK)))
94904+#endif
94905 tcp_v6_send_reset(NULL, skb);
94906 }
94907
94908diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
94909index 1878609..b48e1d4 100644
94910--- a/net/ipv6/udp.c
94911+++ b/net/ipv6/udp.c
94912@@ -53,6 +53,10 @@
94913 #include <trace/events/skb.h>
94914 #include "udp_impl.h"
94915
94916+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
94917+extern int grsec_enable_blackhole;
94918+#endif
94919+
94920 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
94921 {
94922 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
94923@@ -420,7 +424,7 @@ try_again:
94924 if (unlikely(err)) {
94925 trace_kfree_skb(skb, udpv6_recvmsg);
94926 if (!peeked) {
94927- atomic_inc(&sk->sk_drops);
94928+ atomic_inc_unchecked(&sk->sk_drops);
94929 if (is_udp4)
94930 UDP_INC_STATS_USER(sock_net(sk),
94931 UDP_MIB_INERRORS,
94932@@ -668,7 +672,7 @@ csum_error:
94933 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
94934 drop:
94935 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
94936- atomic_inc(&sk->sk_drops);
94937+ atomic_inc_unchecked(&sk->sk_drops);
94938 kfree_skb(skb);
94939 return -1;
94940 }
94941@@ -726,7 +730,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
94942 if (likely(skb1 == NULL))
94943 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
94944 if (!skb1) {
94945- atomic_inc(&sk->sk_drops);
94946+ atomic_inc_unchecked(&sk->sk_drops);
94947 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
94948 IS_UDPLITE(sk));
94949 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
94950@@ -866,6 +870,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
94951 goto csum_error;
94952
94953 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
94954+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
94955+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
94956+#endif
94957 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
94958
94959 kfree_skb(skb);
94960diff --git a/net/ipv6/xfrm6_policy.c b/net/ipv6/xfrm6_policy.c
94961index 08ed277..80e4bc8 100644
94962--- a/net/ipv6/xfrm6_policy.c
94963+++ b/net/ipv6/xfrm6_policy.c
94964@@ -208,11 +208,11 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
94965 }
94966 }
94967
94968-static inline int xfrm6_garbage_collect(struct dst_ops *ops)
94969+static int xfrm6_garbage_collect(struct dst_ops *ops)
94970 {
94971 struct net *net = container_of(ops, struct net, xfrm.xfrm6_dst_ops);
94972
94973- xfrm6_policy_afinfo.garbage_collect(net);
94974+ xfrm_garbage_collect_deferred(net);
94975 return dst_entries_get_fast(ops) > ops->gc_thresh * 2;
94976 }
94977
94978@@ -325,19 +325,19 @@ static struct ctl_table xfrm6_policy_table[] = {
94979
94980 static int __net_init xfrm6_net_init(struct net *net)
94981 {
94982- struct ctl_table *table;
94983+ ctl_table_no_const *table = NULL;
94984 struct ctl_table_header *hdr;
94985
94986- table = xfrm6_policy_table;
94987 if (!net_eq(net, &init_net)) {
94988- table = kmemdup(table, sizeof(xfrm6_policy_table), GFP_KERNEL);
94989+ table = kmemdup(xfrm6_policy_table, sizeof(xfrm6_policy_table), GFP_KERNEL);
94990 if (!table)
94991 goto err_alloc;
94992
94993 table[0].data = &net->xfrm.xfrm6_dst_ops.gc_thresh;
94994- }
94995+ hdr = register_net_sysctl(net, "net/ipv6", table);
94996+ } else
94997+ hdr = register_net_sysctl(net, "net/ipv6", xfrm6_policy_table);
94998
94999- hdr = register_net_sysctl(net, "net/ipv6", table);
95000 if (!hdr)
95001 goto err_reg;
95002
95003@@ -345,8 +345,7 @@ static int __net_init xfrm6_net_init(struct net *net)
95004 return 0;
95005
95006 err_reg:
95007- if (!net_eq(net, &init_net))
95008- kfree(table);
95009+ kfree(table);
95010 err_alloc:
95011 return -ENOMEM;
95012 }
95013diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
95014index 41ac7938..75e3bb1 100644
95015--- a/net/irda/ircomm/ircomm_tty.c
95016+++ b/net/irda/ircomm/ircomm_tty.c
95017@@ -319,11 +319,11 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
95018 add_wait_queue(&port->open_wait, &wait);
95019
95020 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
95021- __FILE__, __LINE__, tty->driver->name, port->count);
95022+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
95023
95024 spin_lock_irqsave(&port->lock, flags);
95025 if (!tty_hung_up_p(filp))
95026- port->count--;
95027+ atomic_dec(&port->count);
95028 port->blocked_open++;
95029 spin_unlock_irqrestore(&port->lock, flags);
95030
95031@@ -358,7 +358,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
95032 }
95033
95034 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
95035- __FILE__, __LINE__, tty->driver->name, port->count);
95036+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
95037
95038 schedule();
95039 }
95040@@ -368,12 +368,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
95041
95042 spin_lock_irqsave(&port->lock, flags);
95043 if (!tty_hung_up_p(filp))
95044- port->count++;
95045+ atomic_inc(&port->count);
95046 port->blocked_open--;
95047 spin_unlock_irqrestore(&port->lock, flags);
95048
95049 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
95050- __FILE__, __LINE__, tty->driver->name, port->count);
95051+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
95052
95053 if (!retval)
95054 port->flags |= ASYNC_NORMAL_ACTIVE;
95055@@ -447,12 +447,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
95056
95057 /* ++ is not atomic, so this should be protected - Jean II */
95058 spin_lock_irqsave(&self->port.lock, flags);
95059- self->port.count++;
95060+ atomic_inc(&self->port.count);
95061 spin_unlock_irqrestore(&self->port.lock, flags);
95062 tty_port_tty_set(&self->port, tty);
95063
95064 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
95065- self->line, self->port.count);
95066+ self->line, atomic_read(&self->port.count));
95067
95068 /* Not really used by us, but lets do it anyway */
95069 self->port.low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
95070@@ -989,7 +989,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
95071 tty_kref_put(port->tty);
95072 }
95073 port->tty = NULL;
95074- port->count = 0;
95075+ atomic_set(&port->count, 0);
95076 spin_unlock_irqrestore(&port->lock, flags);
95077
95078 wake_up_interruptible(&port->open_wait);
95079@@ -1346,7 +1346,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
95080 seq_putc(m, '\n');
95081
95082 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
95083- seq_printf(m, "Open count: %d\n", self->port.count);
95084+ seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
95085 seq_printf(m, "Max data size: %d\n", self->max_data_size);
95086 seq_printf(m, "Max header size: %d\n", self->max_header_size);
95087
95088diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
95089index 168aff5..9d43132 100644
95090--- a/net/iucv/af_iucv.c
95091+++ b/net/iucv/af_iucv.c
95092@@ -773,10 +773,10 @@ static int iucv_sock_autobind(struct sock *sk)
95093
95094 write_lock_bh(&iucv_sk_list.lock);
95095
95096- sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
95097+ sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
95098 while (__iucv_get_sock_by_name(name)) {
95099 sprintf(name, "%08x",
95100- atomic_inc_return(&iucv_sk_list.autobind_name));
95101+ atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
95102 }
95103
95104 write_unlock_bh(&iucv_sk_list.lock);
95105diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
95106index cd5b8ec..f205e6b 100644
95107--- a/net/iucv/iucv.c
95108+++ b/net/iucv/iucv.c
95109@@ -690,7 +690,7 @@ static int iucv_cpu_notify(struct notifier_block *self,
95110 return NOTIFY_OK;
95111 }
95112
95113-static struct notifier_block __refdata iucv_cpu_notifier = {
95114+static struct notifier_block iucv_cpu_notifier = {
95115 .notifier_call = iucv_cpu_notify,
95116 };
95117
95118diff --git a/net/key/af_key.c b/net/key/af_key.c
95119index 911ef03..58f9c96 100644
95120--- a/net/key/af_key.c
95121+++ b/net/key/af_key.c
95122@@ -3041,10 +3041,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
95123 static u32 get_acqseq(void)
95124 {
95125 u32 res;
95126- static atomic_t acqseq;
95127+ static atomic_unchecked_t acqseq;
95128
95129 do {
95130- res = atomic_inc_return(&acqseq);
95131+ res = atomic_inc_return_unchecked(&acqseq);
95132 } while (!res);
95133 return res;
95134 }
95135diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
95136index 629dee7..4bdd2c8 100644
95137--- a/net/mac80211/cfg.c
95138+++ b/net/mac80211/cfg.c
95139@@ -826,7 +826,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
95140 ret = ieee80211_vif_use_channel(sdata, chandef,
95141 IEEE80211_CHANCTX_EXCLUSIVE);
95142 }
95143- } else if (local->open_count == local->monitors) {
95144+ } else if (local_read(&local->open_count) == local->monitors) {
95145 local->_oper_chandef = *chandef;
95146 ieee80211_hw_config(local, 0);
95147 }
95148@@ -3125,7 +3125,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
95149 else
95150 local->probe_req_reg--;
95151
95152- if (!local->open_count)
95153+ if (!local_read(&local->open_count))
95154 break;
95155
95156 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
95157@@ -3588,8 +3588,8 @@ static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
95158 if (chanctx_conf) {
95159 *chandef = chanctx_conf->def;
95160 ret = 0;
95161- } else if (local->open_count > 0 &&
95162- local->open_count == local->monitors &&
95163+ } else if (local_read(&local->open_count) > 0 &&
95164+ local_read(&local->open_count) == local->monitors &&
95165 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
95166 if (local->use_chanctx)
95167 *chandef = local->monitor_chandef;
95168diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
95169index 611abfc..8c2c7e4 100644
95170--- a/net/mac80211/ieee80211_i.h
95171+++ b/net/mac80211/ieee80211_i.h
95172@@ -28,6 +28,7 @@
95173 #include <net/ieee80211_radiotap.h>
95174 #include <net/cfg80211.h>
95175 #include <net/mac80211.h>
95176+#include <asm/local.h>
95177 #include "key.h"
95178 #include "sta_info.h"
95179 #include "debug.h"
95180@@ -945,7 +946,7 @@ struct ieee80211_local {
95181 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
95182 spinlock_t queue_stop_reason_lock;
95183
95184- int open_count;
95185+ local_t open_count;
95186 int monitors, cooked_mntrs;
95187 /* number of interfaces with corresponding FIF_ flags */
95188 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
95189diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
95190index fcecd63..a404454 100644
95191--- a/net/mac80211/iface.c
95192+++ b/net/mac80211/iface.c
95193@@ -519,7 +519,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
95194 break;
95195 }
95196
95197- if (local->open_count == 0) {
95198+ if (local_read(&local->open_count) == 0) {
95199 res = drv_start(local);
95200 if (res)
95201 goto err_del_bss;
95202@@ -566,7 +566,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
95203 res = drv_add_interface(local, sdata);
95204 if (res)
95205 goto err_stop;
95206- } else if (local->monitors == 0 && local->open_count == 0) {
95207+ } else if (local->monitors == 0 && local_read(&local->open_count) == 0) {
95208 res = ieee80211_add_virtual_monitor(local);
95209 if (res)
95210 goto err_stop;
95211@@ -675,7 +675,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
95212 atomic_inc(&local->iff_promiscs);
95213
95214 if (coming_up)
95215- local->open_count++;
95216+ local_inc(&local->open_count);
95217
95218 if (hw_reconf_flags)
95219 ieee80211_hw_config(local, hw_reconf_flags);
95220@@ -713,7 +713,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
95221 err_del_interface:
95222 drv_remove_interface(local, sdata);
95223 err_stop:
95224- if (!local->open_count)
95225+ if (!local_read(&local->open_count))
95226 drv_stop(local);
95227 err_del_bss:
95228 sdata->bss = NULL;
95229@@ -852,7 +852,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
95230 }
95231
95232 if (going_down)
95233- local->open_count--;
95234+ local_dec(&local->open_count);
95235
95236 switch (sdata->vif.type) {
95237 case NL80211_IFTYPE_AP_VLAN:
95238@@ -919,7 +919,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
95239 }
95240 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
95241
95242- if (local->open_count == 0)
95243+ if (local_read(&local->open_count) == 0)
95244 ieee80211_clear_tx_pending(local);
95245
95246 /*
95247@@ -959,7 +959,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
95248
95249 ieee80211_recalc_ps(local, -1);
95250
95251- if (local->open_count == 0) {
95252+ if (local_read(&local->open_count) == 0) {
95253 ieee80211_stop_device(local);
95254
95255 /* no reconfiguring after stop! */
95256@@ -970,7 +970,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
95257 ieee80211_configure_filter(local);
95258 ieee80211_hw_config(local, hw_reconf_flags);
95259
95260- if (local->monitors == local->open_count)
95261+ if (local->monitors == local_read(&local->open_count))
95262 ieee80211_add_virtual_monitor(local);
95263 }
95264
95265diff --git a/net/mac80211/main.c b/net/mac80211/main.c
95266index 21d5d44..4fee18a 100644
95267--- a/net/mac80211/main.c
95268+++ b/net/mac80211/main.c
95269@@ -172,7 +172,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
95270 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
95271 IEEE80211_CONF_CHANGE_POWER);
95272
95273- if (changed && local->open_count) {
95274+ if (changed && local_read(&local->open_count)) {
95275 ret = drv_config(local, changed);
95276 /*
95277 * Goal:
95278diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
95279index 3401262..d5cd68d 100644
95280--- a/net/mac80211/pm.c
95281+++ b/net/mac80211/pm.c
95282@@ -12,7 +12,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
95283 struct ieee80211_sub_if_data *sdata;
95284 struct sta_info *sta;
95285
95286- if (!local->open_count)
95287+ if (!local_read(&local->open_count))
95288 goto suspend;
95289
95290 ieee80211_scan_cancel(local);
95291@@ -59,7 +59,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
95292 cancel_work_sync(&local->dynamic_ps_enable_work);
95293 del_timer_sync(&local->dynamic_ps_timer);
95294
95295- local->wowlan = wowlan && local->open_count;
95296+ local->wowlan = wowlan && local_read(&local->open_count);
95297 if (local->wowlan) {
95298 int err = drv_suspend(local, wowlan);
95299 if (err < 0) {
95300@@ -116,7 +116,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
95301 WARN_ON(!list_empty(&local->chanctx_list));
95302
95303 /* stop hardware - this must stop RX */
95304- if (local->open_count)
95305+ if (local_read(&local->open_count))
95306 ieee80211_stop_device(local);
95307
95308 suspend:
95309diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
95310index e126605..73d2c39 100644
95311--- a/net/mac80211/rate.c
95312+++ b/net/mac80211/rate.c
95313@@ -725,7 +725,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
95314
95315 ASSERT_RTNL();
95316
95317- if (local->open_count)
95318+ if (local_read(&local->open_count))
95319 return -EBUSY;
95320
95321 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
95322diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
95323index c97a065..ff61928 100644
95324--- a/net/mac80211/rc80211_pid_debugfs.c
95325+++ b/net/mac80211/rc80211_pid_debugfs.c
95326@@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
95327
95328 spin_unlock_irqrestore(&events->lock, status);
95329
95330- if (copy_to_user(buf, pb, p))
95331+ if (p > sizeof(pb) || copy_to_user(buf, pb, p))
95332 return -EFAULT;
95333
95334 return p;
95335diff --git a/net/mac80211/util.c b/net/mac80211/util.c
95336index 69e4ef5..e8e4b92 100644
95337--- a/net/mac80211/util.c
95338+++ b/net/mac80211/util.c
95339@@ -1470,7 +1470,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
95340 }
95341 #endif
95342 /* everything else happens only if HW was up & running */
95343- if (!local->open_count)
95344+ if (!local_read(&local->open_count))
95345 goto wake_up;
95346
95347 /*
95348@@ -1695,7 +1695,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
95349 local->in_reconfig = false;
95350 barrier();
95351
95352- if (local->monitors == local->open_count && local->monitors > 0)
95353+ if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
95354 ieee80211_add_virtual_monitor(local);
95355
95356 /*
95357diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
95358index 6e839b6..002a233 100644
95359--- a/net/netfilter/Kconfig
95360+++ b/net/netfilter/Kconfig
95361@@ -950,6 +950,16 @@ config NETFILTER_XT_MATCH_ESP
95362
95363 To compile it as a module, choose M here. If unsure, say N.
95364
95365+config NETFILTER_XT_MATCH_GRADM
95366+ tristate '"gradm" match support'
95367+ depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
95368+ depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
95369+ ---help---
95370+ The gradm match allows to match on grsecurity RBAC being enabled.
95371+ It is useful when iptables rules are applied early on bootup to
95372+ prevent connections to the machine (except from a trusted host)
95373+ while the RBAC system is disabled.
95374+
95375 config NETFILTER_XT_MATCH_HASHLIMIT
95376 tristate '"hashlimit" match support'
95377 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
95378diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
95379index c3a0a12..90b587f 100644
95380--- a/net/netfilter/Makefile
95381+++ b/net/netfilter/Makefile
95382@@ -112,6 +112,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
95383 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
95384 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
95385 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
95386+obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
95387 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
95388 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
95389 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
95390diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
95391index f2e30fb..f131862 100644
95392--- a/net/netfilter/ipset/ip_set_core.c
95393+++ b/net/netfilter/ipset/ip_set_core.c
95394@@ -1819,7 +1819,7 @@ done:
95395 return ret;
95396 }
95397
95398-static struct nf_sockopt_ops so_set __read_mostly = {
95399+static struct nf_sockopt_ops so_set = {
95400 .pf = PF_INET,
95401 .get_optmin = SO_IP_SET,
95402 .get_optmax = SO_IP_SET + 1,
95403diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
95404index 4c8e5c0..5a79b4d 100644
95405--- a/net/netfilter/ipvs/ip_vs_conn.c
95406+++ b/net/netfilter/ipvs/ip_vs_conn.c
95407@@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
95408 /* Increase the refcnt counter of the dest */
95409 ip_vs_dest_hold(dest);
95410
95411- conn_flags = atomic_read(&dest->conn_flags);
95412+ conn_flags = atomic_read_unchecked(&dest->conn_flags);
95413 if (cp->protocol != IPPROTO_UDP)
95414 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
95415 flags = cp->flags;
95416@@ -900,7 +900,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
95417
95418 cp->control = NULL;
95419 atomic_set(&cp->n_control, 0);
95420- atomic_set(&cp->in_pkts, 0);
95421+ atomic_set_unchecked(&cp->in_pkts, 0);
95422
95423 cp->packet_xmit = NULL;
95424 cp->app = NULL;
95425@@ -1188,7 +1188,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
95426
95427 /* Don't drop the entry if its number of incoming packets is not
95428 located in [0, 8] */
95429- i = atomic_read(&cp->in_pkts);
95430+ i = atomic_read_unchecked(&cp->in_pkts);
95431 if (i > 8 || i < 0) return 0;
95432
95433 if (!todrop_rate[i]) return 0;
95434diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
95435index 74fd00c..06e7ac7 100644
95436--- a/net/netfilter/ipvs/ip_vs_core.c
95437+++ b/net/netfilter/ipvs/ip_vs_core.c
95438@@ -567,7 +567,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
95439 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
95440 /* do not touch skb anymore */
95441
95442- atomic_inc(&cp->in_pkts);
95443+ atomic_inc_unchecked(&cp->in_pkts);
95444 ip_vs_conn_put(cp);
95445 return ret;
95446 }
95447@@ -1719,7 +1719,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
95448 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
95449 pkts = sysctl_sync_threshold(ipvs);
95450 else
95451- pkts = atomic_add_return(1, &cp->in_pkts);
95452+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
95453
95454 if (ipvs->sync_state & IP_VS_STATE_MASTER)
95455 ip_vs_sync_conn(net, cp, pkts);
95456diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
95457index a3df9bd..895ae09 100644
95458--- a/net/netfilter/ipvs/ip_vs_ctl.c
95459+++ b/net/netfilter/ipvs/ip_vs_ctl.c
95460@@ -794,7 +794,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
95461 */
95462 ip_vs_rs_hash(ipvs, dest);
95463 }
95464- atomic_set(&dest->conn_flags, conn_flags);
95465+ atomic_set_unchecked(&dest->conn_flags, conn_flags);
95466
95467 /* bind the service */
95468 old_svc = rcu_dereference_protected(dest->svc, 1);
95469@@ -1641,7 +1641,7 @@ proc_do_sync_ports(struct ctl_table *table, int write,
95470 * align with netns init in ip_vs_control_net_init()
95471 */
95472
95473-static struct ctl_table vs_vars[] = {
95474+static ctl_table_no_const vs_vars[] __read_only = {
95475 {
95476 .procname = "amemthresh",
95477 .maxlen = sizeof(int),
95478@@ -2062,7 +2062,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
95479 " %-7s %-6d %-10d %-10d\n",
95480 &dest->addr.in6,
95481 ntohs(dest->port),
95482- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
95483+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
95484 atomic_read(&dest->weight),
95485 atomic_read(&dest->activeconns),
95486 atomic_read(&dest->inactconns));
95487@@ -2073,7 +2073,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
95488 "%-7s %-6d %-10d %-10d\n",
95489 ntohl(dest->addr.ip),
95490 ntohs(dest->port),
95491- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
95492+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
95493 atomic_read(&dest->weight),
95494 atomic_read(&dest->activeconns),
95495 atomic_read(&dest->inactconns));
95496@@ -2551,7 +2551,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
95497
95498 entry.addr = dest->addr.ip;
95499 entry.port = dest->port;
95500- entry.conn_flags = atomic_read(&dest->conn_flags);
95501+ entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
95502 entry.weight = atomic_read(&dest->weight);
95503 entry.u_threshold = dest->u_threshold;
95504 entry.l_threshold = dest->l_threshold;
95505@@ -3094,7 +3094,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
95506 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
95507 nla_put_be16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
95508 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
95509- (atomic_read(&dest->conn_flags) &
95510+ (atomic_read_unchecked(&dest->conn_flags) &
95511 IP_VS_CONN_F_FWD_MASK)) ||
95512 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
95513 atomic_read(&dest->weight)) ||
95514@@ -3684,7 +3684,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net)
95515 {
95516 int idx;
95517 struct netns_ipvs *ipvs = net_ipvs(net);
95518- struct ctl_table *tbl;
95519+ ctl_table_no_const *tbl;
95520
95521 atomic_set(&ipvs->dropentry, 0);
95522 spin_lock_init(&ipvs->dropentry_lock);
95523diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
95524index eff13c9..c1aab3e 100644
95525--- a/net/netfilter/ipvs/ip_vs_lblc.c
95526+++ b/net/netfilter/ipvs/ip_vs_lblc.c
95527@@ -118,7 +118,7 @@ struct ip_vs_lblc_table {
95528 * IPVS LBLC sysctl table
95529 */
95530 #ifdef CONFIG_SYSCTL
95531-static struct ctl_table vs_vars_table[] = {
95532+static ctl_table_no_const vs_vars_table[] __read_only = {
95533 {
95534 .procname = "lblc_expiration",
95535 .data = NULL,
95536diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
95537index 0b85500..8513fa5 100644
95538--- a/net/netfilter/ipvs/ip_vs_lblcr.c
95539+++ b/net/netfilter/ipvs/ip_vs_lblcr.c
95540@@ -289,7 +289,7 @@ struct ip_vs_lblcr_table {
95541 * IPVS LBLCR sysctl table
95542 */
95543
95544-static struct ctl_table vs_vars_table[] = {
95545+static ctl_table_no_const vs_vars_table[] __read_only = {
95546 {
95547 .procname = "lblcr_expiration",
95548 .data = NULL,
95549diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
95550index f448471..995f131 100644
95551--- a/net/netfilter/ipvs/ip_vs_sync.c
95552+++ b/net/netfilter/ipvs/ip_vs_sync.c
95553@@ -609,7 +609,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
95554 cp = cp->control;
95555 if (cp) {
95556 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
95557- pkts = atomic_add_return(1, &cp->in_pkts);
95558+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
95559 else
95560 pkts = sysctl_sync_threshold(ipvs);
95561 ip_vs_sync_conn(net, cp->control, pkts);
95562@@ -771,7 +771,7 @@ control:
95563 if (!cp)
95564 return;
95565 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
95566- pkts = atomic_add_return(1, &cp->in_pkts);
95567+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
95568 else
95569 pkts = sysctl_sync_threshold(ipvs);
95570 goto sloop;
95571@@ -895,7 +895,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
95572
95573 if (opt)
95574 memcpy(&cp->in_seq, opt, sizeof(*opt));
95575- atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
95576+ atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
95577 cp->state = state;
95578 cp->old_state = cp->state;
95579 /*
95580diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
95581index c47444e..b0961c6 100644
95582--- a/net/netfilter/ipvs/ip_vs_xmit.c
95583+++ b/net/netfilter/ipvs/ip_vs_xmit.c
95584@@ -1102,7 +1102,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
95585 else
95586 rc = NF_ACCEPT;
95587 /* do not touch skb anymore */
95588- atomic_inc(&cp->in_pkts);
95589+ atomic_inc_unchecked(&cp->in_pkts);
95590 goto out;
95591 }
95592
95593@@ -1194,7 +1194,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
95594 else
95595 rc = NF_ACCEPT;
95596 /* do not touch skb anymore */
95597- atomic_inc(&cp->in_pkts);
95598+ atomic_inc_unchecked(&cp->in_pkts);
95599 goto out;
95600 }
95601
95602diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
95603index 2d3030a..7ba1c0a 100644
95604--- a/net/netfilter/nf_conntrack_acct.c
95605+++ b/net/netfilter/nf_conntrack_acct.c
95606@@ -60,7 +60,7 @@ static struct nf_ct_ext_type acct_extend __read_mostly = {
95607 #ifdef CONFIG_SYSCTL
95608 static int nf_conntrack_acct_init_sysctl(struct net *net)
95609 {
95610- struct ctl_table *table;
95611+ ctl_table_no_const *table;
95612
95613 table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
95614 GFP_KERNEL);
95615diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
95616index 5d892fe..d2fc9d8 100644
95617--- a/net/netfilter/nf_conntrack_core.c
95618+++ b/net/netfilter/nf_conntrack_core.c
95619@@ -1600,6 +1600,10 @@ void nf_conntrack_init_end(void)
95620 #define DYING_NULLS_VAL ((1<<30)+1)
95621 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
95622
95623+#ifdef CONFIG_GRKERNSEC_HIDESYM
95624+static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
95625+#endif
95626+
95627 int nf_conntrack_init_net(struct net *net)
95628 {
95629 int ret;
95630@@ -1614,7 +1618,11 @@ int nf_conntrack_init_net(struct net *net)
95631 goto err_stat;
95632 }
95633
95634+#ifdef CONFIG_GRKERNSEC_HIDESYM
95635+ net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
95636+#else
95637 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
95638+#endif
95639 if (!net->ct.slabname) {
95640 ret = -ENOMEM;
95641 goto err_slabname;
95642diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
95643index 1df1761..ce8b88a 100644
95644--- a/net/netfilter/nf_conntrack_ecache.c
95645+++ b/net/netfilter/nf_conntrack_ecache.c
95646@@ -188,7 +188,7 @@ static struct nf_ct_ext_type event_extend __read_mostly = {
95647 #ifdef CONFIG_SYSCTL
95648 static int nf_conntrack_event_init_sysctl(struct net *net)
95649 {
95650- struct ctl_table *table;
95651+ ctl_table_no_const *table;
95652
95653 table = kmemdup(event_sysctl_table, sizeof(event_sysctl_table),
95654 GFP_KERNEL);
95655diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
95656index 974a2a4..52cc6ff 100644
95657--- a/net/netfilter/nf_conntrack_helper.c
95658+++ b/net/netfilter/nf_conntrack_helper.c
95659@@ -57,7 +57,7 @@ static struct ctl_table helper_sysctl_table[] = {
95660
95661 static int nf_conntrack_helper_init_sysctl(struct net *net)
95662 {
95663- struct ctl_table *table;
95664+ ctl_table_no_const *table;
95665
95666 table = kmemdup(helper_sysctl_table, sizeof(helper_sysctl_table),
95667 GFP_KERNEL);
95668diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
95669index ce30041..3861b5d 100644
95670--- a/net/netfilter/nf_conntrack_proto.c
95671+++ b/net/netfilter/nf_conntrack_proto.c
95672@@ -52,7 +52,7 @@ nf_ct_register_sysctl(struct net *net,
95673
95674 static void
95675 nf_ct_unregister_sysctl(struct ctl_table_header **header,
95676- struct ctl_table **table,
95677+ ctl_table_no_const **table,
95678 unsigned int users)
95679 {
95680 if (users > 0)
95681diff --git a/net/netfilter/nf_conntrack_proto_dccp.c b/net/netfilter/nf_conntrack_proto_dccp.c
95682index a99b6c3..cb372f9 100644
95683--- a/net/netfilter/nf_conntrack_proto_dccp.c
95684+++ b/net/netfilter/nf_conntrack_proto_dccp.c
95685@@ -428,7 +428,7 @@ static bool dccp_new(struct nf_conn *ct, const struct sk_buff *skb,
95686 const char *msg;
95687 u_int8_t state;
95688
95689- dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &dh);
95690+ dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &_dh);
95691 BUG_ON(dh == NULL);
95692
95693 state = dccp_state_table[CT_DCCP_ROLE_CLIENT][dh->dccph_type][CT_DCCP_NONE];
95694@@ -457,7 +457,7 @@ static bool dccp_new(struct nf_conn *ct, const struct sk_buff *skb,
95695 out_invalid:
95696 if (LOG_INVALID(net, IPPROTO_DCCP))
95697 nf_log_packet(net, nf_ct_l3num(ct), 0, skb, NULL, NULL,
95698- NULL, msg);
95699+ NULL, "%s", msg);
95700 return false;
95701 }
95702
95703@@ -486,7 +486,7 @@ static int dccp_packet(struct nf_conn *ct, const struct sk_buff *skb,
95704 u_int8_t type, old_state, new_state;
95705 enum ct_dccp_roles role;
95706
95707- dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &dh);
95708+ dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &_dh);
95709 BUG_ON(dh == NULL);
95710 type = dh->dccph_type;
95711
95712@@ -577,7 +577,7 @@ static int dccp_error(struct net *net, struct nf_conn *tmpl,
95713 unsigned int cscov;
95714 const char *msg;
95715
95716- dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &dh);
95717+ dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &_dh);
95718 if (dh == NULL) {
95719 msg = "nf_ct_dccp: short packet ";
95720 goto out_invalid;
95721@@ -614,7 +614,7 @@ static int dccp_error(struct net *net, struct nf_conn *tmpl,
95722
95723 out_invalid:
95724 if (LOG_INVALID(net, IPPROTO_DCCP))
95725- nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL, msg);
95726+ nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL, "%s", msg);
95727 return -NF_ACCEPT;
95728 }
95729
95730diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
95731index f641751..d3c5b51 100644
95732--- a/net/netfilter/nf_conntrack_standalone.c
95733+++ b/net/netfilter/nf_conntrack_standalone.c
95734@@ -471,7 +471,7 @@ static struct ctl_table nf_ct_netfilter_table[] = {
95735
95736 static int nf_conntrack_standalone_init_sysctl(struct net *net)
95737 {
95738- struct ctl_table *table;
95739+ ctl_table_no_const *table;
95740
95741 table = kmemdup(nf_ct_sysctl_table, sizeof(nf_ct_sysctl_table),
95742 GFP_KERNEL);
95743diff --git a/net/netfilter/nf_conntrack_timestamp.c b/net/netfilter/nf_conntrack_timestamp.c
95744index 902fb0a..87f7fdb 100644
95745--- a/net/netfilter/nf_conntrack_timestamp.c
95746+++ b/net/netfilter/nf_conntrack_timestamp.c
95747@@ -42,7 +42,7 @@ static struct nf_ct_ext_type tstamp_extend __read_mostly = {
95748 #ifdef CONFIG_SYSCTL
95749 static int nf_conntrack_tstamp_init_sysctl(struct net *net)
95750 {
95751- struct ctl_table *table;
95752+ ctl_table_no_const *table;
95753
95754 table = kmemdup(tstamp_sysctl_table, sizeof(tstamp_sysctl_table),
95755 GFP_KERNEL);
95756diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
95757index 85296d4..8becdec 100644
95758--- a/net/netfilter/nf_log.c
95759+++ b/net/netfilter/nf_log.c
95760@@ -243,7 +243,7 @@ static const struct file_operations nflog_file_ops = {
95761
95762 #ifdef CONFIG_SYSCTL
95763 static char nf_log_sysctl_fnames[NFPROTO_NUMPROTO-NFPROTO_UNSPEC][3];
95764-static struct ctl_table nf_log_sysctl_table[NFPROTO_NUMPROTO+1];
95765+static ctl_table_no_const nf_log_sysctl_table[NFPROTO_NUMPROTO+1] __read_only;
95766
95767 static int nf_log_proc_dostring(struct ctl_table *table, int write,
95768 void __user *buffer, size_t *lenp, loff_t *ppos)
95769@@ -274,14 +274,16 @@ static int nf_log_proc_dostring(struct ctl_table *table, int write,
95770 rcu_assign_pointer(net->nf.nf_loggers[tindex], logger);
95771 mutex_unlock(&nf_log_mutex);
95772 } else {
95773+ ctl_table_no_const nf_log_table = *table;
95774+
95775 mutex_lock(&nf_log_mutex);
95776 logger = rcu_dereference_protected(net->nf.nf_loggers[tindex],
95777 lockdep_is_held(&nf_log_mutex));
95778 if (!logger)
95779- table->data = "NONE";
95780+ nf_log_table.data = "NONE";
95781 else
95782- table->data = logger->name;
95783- r = proc_dostring(table, write, buffer, lenp, ppos);
95784+ nf_log_table.data = logger->name;
95785+ r = proc_dostring(&nf_log_table, write, buffer, lenp, ppos);
95786 mutex_unlock(&nf_log_mutex);
95787 }
95788
95789diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
95790index f042ae5..30ea486 100644
95791--- a/net/netfilter/nf_sockopt.c
95792+++ b/net/netfilter/nf_sockopt.c
95793@@ -45,7 +45,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
95794 }
95795 }
95796
95797- list_add(&reg->list, &nf_sockopts);
95798+ pax_list_add((struct list_head *)&reg->list, &nf_sockopts);
95799 out:
95800 mutex_unlock(&nf_sockopt_mutex);
95801 return ret;
95802@@ -55,7 +55,7 @@ EXPORT_SYMBOL(nf_register_sockopt);
95803 void nf_unregister_sockopt(struct nf_sockopt_ops *reg)
95804 {
95805 mutex_lock(&nf_sockopt_mutex);
95806- list_del(&reg->list);
95807+ pax_list_del((struct list_head *)&reg->list);
95808 mutex_unlock(&nf_sockopt_mutex);
95809 }
95810 EXPORT_SYMBOL(nf_unregister_sockopt);
95811diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
95812index d92cc31..e46f350 100644
95813--- a/net/netfilter/nfnetlink_log.c
95814+++ b/net/netfilter/nfnetlink_log.c
95815@@ -82,7 +82,7 @@ static int nfnl_log_net_id __read_mostly;
95816 struct nfnl_log_net {
95817 spinlock_t instances_lock;
95818 struct hlist_head instance_table[INSTANCE_BUCKETS];
95819- atomic_t global_seq;
95820+ atomic_unchecked_t global_seq;
95821 };
95822
95823 static struct nfnl_log_net *nfnl_log_pernet(struct net *net)
95824@@ -563,7 +563,7 @@ __build_packet_message(struct nfnl_log_net *log,
95825 /* global sequence number */
95826 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
95827 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
95828- htonl(atomic_inc_return(&log->global_seq))))
95829+ htonl(atomic_inc_return_unchecked(&log->global_seq))))
95830 goto nla_put_failure;
95831
95832 if (data_len) {
95833diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
95834new file mode 100644
95835index 0000000..c566332
95836--- /dev/null
95837+++ b/net/netfilter/xt_gradm.c
95838@@ -0,0 +1,51 @@
95839+/*
95840+ * gradm match for netfilter
95841